Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Disable cast votes button for multiple polls with no min. #15484

Merged
merged 1 commit into from Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/poll/assets/javascripts/widgets/discourse-poll.js
Expand Up @@ -813,8 +813,9 @@ export default createWidget("discourse-poll", {
min() {
let min = parseInt(this.attrs.poll.min, 10);
if (isNaN(min) || min < 0) {
min = 0;
min = 1;
}

return min;
},

Expand Down
73 changes: 42 additions & 31 deletions plugins/poll/test/javascripts/widgets/discourse-poll-test.js
Expand Up @@ -51,37 +51,6 @@ discourseModule(
];
});

pretender.put("/polls/vote", () => {
++requests;
return [
200,
{ "Content-Type": "application/json" },
{
poll: {
name: "poll",
type: "regular",
status: "open",
results: "always",
options: [
{
id: "1f972d1df351de3ce35a787c89faad29",
html: "yes",
votes: 1,
},
{
id: "d7ebc3a9beea2e680815a1e4f57d6db6",
html: "no",
votes: 0,
},
],
voters: 1,
chart_type: "bar",
},
vote: ["1f972d1df351de3ce35a787c89faad29"],
},
];
});

Comment on lines -54 to -84
Copy link
Contributor Author

@tgxworld tgxworld Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate of the pretender request above.

const template = hbs`{{mount-widget
widget="discourse-poll"
args=(hash id=id
Expand Down Expand Up @@ -180,5 +149,47 @@ discourseModule(
assert.ok(!exists(".chosen"));
},
});

componentTest("voting on a multiple poll with no min attribute", {
template,

beforeEach() {
this.setProperties({
post: EmberObject.create({
id: 42,
topic: {
archived: false,
},
}),
poll: EmberObject.create({
name: "poll",
type: "multiple",
status: "open",
results: "always",
max: 2,
options: [
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
],
voters: 0,
chart_type: "bar",
}),
vote: [],
groupableUserFields: [],
});
},

async test(assert) {
assert.ok(exists(".poll-buttons .cast-votes[disabled=true]"));

await click(
"li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']"
);

await click(".poll-buttons .cast-votes");

assert.ok(exists(".chosen"));
},
});
}
);