discourse/plugins/discourse-ai/test/javascripts/integration/components/ai-helper-custom-prompt-test.gjs
Martin Brennan 79d1c792eb
DEV: Update test module name conventions (#40389)
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.
2026-05-29 15:19:55 +10:00

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");
});
});