Skip to content

Commit

Permalink
test(question-usage): add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabauke committed Dec 18, 2023
1 parent ff88729 commit 707e48d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
...attributes
href="#"
{{on "click" (fn (mut this.modalVisible) true)}}
data-test-show-question-usage-modal-btn
data-test-show-question-usage-modal-link
>
{{this.title}}
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { render, click } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import { setupMirage } from "ember-cli-mirage/test-support";
import { setupIntl } from "ember-intl/test-support";
import { module, test } from "qunit";

import { setupRenderingTest } from "dummy/tests/helpers";

module(
"Integration | Component | cfb-form-editor/question-usage",
function (hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);
setupIntl(hooks);

test("it renders", async function (assert) {
this.set(
"question",
this.server.create("question", {
label: "Test Label",
slug: "test-slug",
type: "TEXT",
}),
);

this.server.createList("form", 3, { questions: [this.question] });

await render(
hbs`<CfbFormEditor::QuestionUsage @model={{this.question}} />`,
);

await click("[data-test-show-question-usage-modal-link]");

assert.dom("[data-test-question-usage-modal]").isVisible();
assert.dom("[data-test-question-form-item]").exists({ count: 3 });
});

test("it is hidden when no other reference to this question exists", async function (assert) {
this.set(
"question",
this.server.create("question", {
label: "Test Label",
slug: "test-slug",
type: "TEXT",
}),
);

this.server.create("form", { questions: [this.question] });

await render(
hbs`<CfbFormEditor::QuestionUsage @model={{this.question}} />`,
);

assert.dom("[data-test-show-question-usage-modal-link]").isNotVisible();
});
},
);

0 comments on commit 707e48d

Please sign in to comment.