0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-07 13:19:19 +08:00
discourse/plugins/poll/test/javascripts/component/poll-results-ranked-choice-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

80 lines
2.2 KiB
Text
Vendored

import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { i18n } from "discourse-i18n";
import PollResultsRankedChoice from "discourse/plugins/poll/discourse/components/poll-results-ranked-choice";
const RANKED_CHOICE_OUTCOME = {
tied: false,
tied_candidates: null,
winner: true,
winning_candidate: {
digest: "c8678f4ce846ad5415278ff7ecadf3a6",
html: "Team Blue",
},
round_activity: [
{
round: 1,
eliminated: [
{ digest: "8bbb100d504298ad65a2604e99d5ba82", html: "Team Yellow" },
],
majority: null,
},
{
round: 2,
majority: [
{ digest: "c8678f4ce846ad5415278ff7ecadf3a6", html: "Team Blue" },
],
eliminated: null,
},
],
};
module("Component | PollResultsRankedChoice", function (hooks) {
setupRenderingTest(hooks);
test("Renders the ranked choice results component correctly", async function (assert) {
this.setProperties({
rankedChoiceOutcome: RANKED_CHOICE_OUTCOME,
});
await render(
<template>
<PollResultsRankedChoice
@rankedChoiceOutcome={{this.rankedChoiceOutcome}}
/>
</template>
);
assert
.dom("table.poll-results-ranked-choice tr")
.exists({ count: 3 }, "there are two rounds of ranked choice");
assert.dom("span.poll-results-ranked-choice-info").hasText(
i18n("poll.ranked_choice.winner", {
count: this.rankedChoiceOutcome.round_activity.length,
winner: this.rankedChoiceOutcome.winning_candidate.html,
}),
"displays the winner information"
);
});
test("Renders the ranked choice results component without error when outcome data is empty", async function (assert) {
this.rankedChoiceOutcome = null;
await render(
<template>
<PollResultsRankedChoice
@rankedChoiceOutcome={{this.rankedChoiceOutcome}}
/>
</template>
);
assert
.dom("table.poll-results-ranked-choice tr")
.exists(
{ count: 1 },
"there are no rounds of ranked choice displayed, only the header"
);
});
});