0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-14 13:58:53 +08:00
discourse/plugins/poll/test/javascripts/component/poll-buttons-dropdown-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

159 lines
4.7 KiB
Text
Vendored

import { click, render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { i18n } from "discourse-i18n";
import PollButtonsDropdown from "discourse/plugins/poll/discourse/components/poll-buttons-dropdown";
module("Component | PollButtonsDropdown", function (hooks) {
setupRenderingTest(hooks);
test("Renders a clickable dropdown menu with a close option", async function (assert) {
this.siteSettings.data_explorer_enabled = true;
this.siteSettings.poll_export_data_explorer_query_id = 18;
this.currentUser.setProperties({ admin: true });
this.setProperties({
closed: true,
voters: 3,
isStaff: true,
isMe: false,
topicArchived: false,
groupableUserFields: [],
isAutomaticallyClosed: false,
dropDownClick: () => {},
});
await render(
<template>
<PollButtonsDropdown
@closed={{this.closed}}
@voters={{this.voters}}
@isStaff={{this.isStaff}}
@isMe={{this.isMe}}
@topicArchived={{this.topicArchived}}
@groupableUserFields={{this.groupableUserFields}}
@isAutomaticallyClosed={{this.isAutomaticallyClosed}}
@dropDownClick={{this.dropDownClick}}
/>
</template>
);
await click(".widget-dropdown-header");
assert.dom("li.dropdown-menu__item").exists({ count: 2 });
assert
.dom("li.dropdown-menu__item span")
.hasText(
i18n("poll.export-results.label"),
"displays the poll Export action"
);
});
test("Renders a show-tally button when poll is a bar chart", async function (assert) {
this.setProperties({
closed: false,
voters: 2,
isStaff: false,
isMe: false,
topicArchived: false,
groupableUserFields: ["stuff"],
isAutomaticallyClosed: false,
dropDownClick: () => {},
availableDisplayMode: "showTally",
});
await render(
<template>
<PollButtonsDropdown
@closed={{this.closed}}
@voters={{this.voters}}
@isStaff={{this.isStaff}}
@isMe={{this.isMe}}
@topicArchived={{this.topicArchived}}
@groupableUserFields={{this.groupableUserFields}}
@isAutomaticallyClosed={{this.isAutomaticallyClosed}}
@dropDownClick={{this.dropDownClick}}
@availableDisplayMode={{this.availableDisplayMode}}
/>
</template>
);
await click(".widget-dropdown-header");
assert.dom("li.dropdown-menu__item").exists({ count: 2 });
assert
.dom("li.dropdown-menu__item span")
.hasText(
i18n("poll.show-tally.label"),
"displays the show absolute button"
);
});
test("Renders a single button when there is only one authorised action", async function (assert) {
this.setProperties({
closed: false,
voters: 2,
isStaff: false,
isMe: false,
topicArchived: false,
groupableUserFields: ["stuff"],
isAutomaticallyClosed: false,
dropDownClick: () => {},
});
await render(
<template>
<PollButtonsDropdown
@closed={{this.closed}}
@voters={{this.voters}}
@isStaff={{this.isStaff}}
@isMe={{this.isMe}}
@topicArchived={{this.topicArchived}}
@groupableUserFields={{this.groupableUserFields}}
@isAutomaticallyClosed={{this.isAutomaticallyClosed}}
@dropDownClick={{this.dropDownClick}}
/>
</template>
);
assert.dom(".widget-dropdown-header").doesNotExist();
assert.dom("button.widget-button").exists({ count: 1 });
assert
.dom("button.widget-button span.d-button-label")
.hasText(
i18n("poll.breakdown.breakdown"),
"displays the poll Close action"
);
});
test("Doesn't render a button when user has no authorised actions", async function (assert) {
this.setProperties({
closed: false,
voters: 0,
isStaff: false,
isMe: false,
topicArchived: false,
groupableUserFields: [],
isAutomaticallyClosed: false,
dropDownClick: () => {},
});
await render(
<template>
<PollButtonsDropdown
@closed={{this.closed}}
@voters={{this.voters}}
@isStaff={{this.isStaff}}
@isMe={{this.isMe}}
@topicArchived={{this.topicArchived}}
@groupableUserFields={{this.groupableUserFields}}
@isAutomaticallyClosed={{this.isAutomaticallyClosed}}
@dropDownClick={{this.dropDownClick}}
/>
</template>
);
assert.dom(".widget-dropdown-header").doesNotExist();
assert.dom("button.widget-button").doesNotExist();
});
});