FIX: Ensure poll type toggle buttons function correctly (#18540)

Followup to 03b7b7d1bc
This commit is contained in:
David Taylor 2022-10-11 11:20:18 +01:00 committed by GitHub
parent b75dc04a25
commit a10a81244c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -402,6 +402,6 @@ export default Controller.extend(ModalFunctionality, {
@action @action
updatePollType(pollType, event) { updatePollType(pollType, event) {
event?.preventDefault(); event?.preventDefault();
this.pollType = pollType; this.set("pollType", pollType);
}, },
}); });

View File

@ -1,15 +1,15 @@
<DModalBody @title="poll.ui_builder.title" @class="poll-ui-builder"> <DModalBody @title="poll.ui_builder.title" @class="poll-ui-builder">
<div class="input-group poll-type"> <div class="input-group poll-type">
<a href {{on "click" (fn this.updatePollType "regular")}} class="poll-type-value {{if this.isRegular "active"}}"> <a href {{on "click" (fn this.updatePollType "regular")}} class="poll-type-value poll-type-value-regular {{if this.isRegular "active"}}">
{{i18n "poll.ui_builder.poll_type.regular"}} {{i18n "poll.ui_builder.poll_type.regular"}}
</a> </a>
<a href {{on "click" (fn this.updatePollType "multiple")}} class="poll-type-value {{if this.isMultiple "active"}}"> <a href {{on "click" (fn this.updatePollType "multiple")}} class="poll-type-value poll-type-value-multiple {{if this.isMultiple "active"}}">
{{i18n "poll.ui_builder.poll_type.multiple"}} {{i18n "poll.ui_builder.poll_type.multiple"}}
</a> </a>
{{#if this.showNumber}} {{#if this.showNumber}}
<a href {{on "click" (fn this.updatePollType "number")}} class="poll-type-value {{if this.isNumber "active"}}"> <a href {{on "click" (fn this.updatePollType "number")}} class="poll-type-value poll-type-value-number {{if this.isNumber "active"}}">
{{i18n "poll.ui_builder.poll_type.number"}} {{i18n "poll.ui_builder.poll_type.number"}}
</a> </a>
{{/if}} {{/if}}

View File

@ -3,6 +3,7 @@ import {
exists, exists,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { click } from "@ember/test-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer"; import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button"; import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
import { test } from "qunit"; import { test } from "qunit";
@ -24,6 +25,22 @@ acceptance("Poll Builder - polls are enabled", function (needs) {
exists(".select-kit-row[data-value='showPollBuilder']"), exists(".select-kit-row[data-value='showPollBuilder']"),
"it shows the builder button" "it shows the builder button"
); );
await click(".select-kit-row[data-value='showPollBuilder']");
assert.true(
exists(".poll-type-value-regular.active"),
"regular type is active"
);
await click(".poll-type-value-multiple");
assert.true(
exists(".poll-type-value-multiple.active"),
"multiple type is active"
);
await click(".poll-type-value-regular");
assert.true(
exists(".poll-type-value-regular.active"),
"regular type is active"
);
}); });
test("regular user - insufficient trust level", async function (assert) { test("regular user - insufficient trust level", async function (assert) {