mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 07:43:46 +08:00
Currently, most of the JS test modules follow this
convention:
```
module("Integration | Component | topic-dismiss-buttons"
```
Which is a legacy from when ember components etc were
rendered in templates like this:
```
{{d-button title="foo"}}
```
Instead, this commit updates all of them to follow this
PascalCase convention:
```
module("Integration | Component | TopicDismissButtons", function (hooks) {
```
No linting is added to enforce this, we suspect that it's
mostly a result of cargo culting, and people will add new
tests following PascalCase convention.
Also adds an initial AI skill for writing JS tests.
41 lines
1.3 KiB
Text
Vendored
41 lines
1.3 KiB
Text
Vendored
import { tracked } from "@glimmer/tracking";
|
|
import { render, triggerEvent } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import AiHelperCustomPrompt from "discourse/plugins/discourse-ai/discourse/components/ai-helper-custom-prompt";
|
|
|
|
class TestState {
|
|
@tracked value = "test";
|
|
}
|
|
|
|
module("Integration | Component | AiHelperCustomPrompt", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
async function renderPrompt(submit, initialValue = "test") {
|
|
const state = new TestState();
|
|
state.value = initialValue;
|
|
await render(
|
|
<template>
|
|
<AiHelperCustomPrompt @value={{state.value}} @submit={{submit}} />
|
|
</template>
|
|
);
|
|
}
|
|
|
|
test("submitting the form calls @submit", async function (assert) {
|
|
let submitted = 0;
|
|
await renderPrompt(() => (submitted += 1));
|
|
|
|
await triggerEvent(".ai-custom-prompt", "submit");
|
|
|
|
assert.strictEqual(submitted, 1, "called @submit once");
|
|
});
|
|
|
|
test("submit is skipped when the input is empty", async function (assert) {
|
|
let submitted = 0;
|
|
await renderPrompt(() => (submitted += 1), "");
|
|
|
|
await triggerEvent(".ai-custom-prompt", "submit");
|
|
|
|
assert.strictEqual(submitted, 0, "did not call @submit");
|
|
});
|
|
});
|