mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:03:34 +08:00
FIX: update voter information upon remote change (#28168)
Fixes issue with polls not being fully updated by remote vote contributions in (semi-) real-time. This was down to too great a focus on tracking local state and not accommodating a more data down approach with responsive getters. This is now implemented. I've tried hard to minimise the changes whilst making sure the paradigm is properly followed through.
This commit is contained in:
@ -46,6 +46,46 @@ module("Poll | Component | poll", function (hooks) {
|
||||
});
|
||||
});
|
||||
|
||||
test("shows vote", async function (assert) {
|
||||
this.setProperties({
|
||||
attributes: EmberObject.create({
|
||||
post: EmberObject.create({
|
||||
id: 42,
|
||||
topic: {
|
||||
archived: false,
|
||||
},
|
||||
user_id: 29,
|
||||
}),
|
||||
poll: EmberObject.create({
|
||||
name: "poll",
|
||||
type: "regular",
|
||||
status: "closed",
|
||||
results: "always",
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 1 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
],
|
||||
voters: 1,
|
||||
chart_type: "bar",
|
||||
}),
|
||||
vote: [],
|
||||
groupableUserFields: [],
|
||||
}),
|
||||
preloadedVoters: [],
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<Poll @attrs={{this.attributes}} @preloadedVoters={{this.preloadedVoters}} />`
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
Array.from(queryAll(".results li .option p")).map(
|
||||
(span) => span.innerText
|
||||
),
|
||||
["100% yes", "0% no"]
|
||||
);
|
||||
});
|
||||
|
||||
test("can vote", async function (assert) {
|
||||
this.setProperties({
|
||||
attributes: EmberObject.create({
|
||||
@ -72,14 +112,10 @@ module("Poll | Component | poll", function (hooks) {
|
||||
groupableUserFields: [],
|
||||
}),
|
||||
preloadedVoters: [],
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
],
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<Poll @attrs={{this.attributes}} @preloadedVoters={{this.preloadedVoters}} @options={{this.options}} />`
|
||||
hbs`<Poll @attrs={{this.attributes}} @preloadedVoters={{this.preloadedVoters}} />`
|
||||
);
|
||||
|
||||
requests = 0;
|
||||
@ -89,10 +125,6 @@ module("Poll | Component | poll", function (hooks) {
|
||||
);
|
||||
assert.strictEqual(requests, 1);
|
||||
assert.strictEqual(count(".chosen"), 1);
|
||||
assert.deepEqual(
|
||||
Array.from(queryAll(".chosen span")).map((span) => span.innerText),
|
||||
["100%", "yes"]
|
||||
);
|
||||
|
||||
await click(".toggle-results");
|
||||
assert.strictEqual(
|
||||
@ -128,14 +160,10 @@ module("Poll | Component | poll", function (hooks) {
|
||||
groupableUserFields: [],
|
||||
}),
|
||||
preloadedVoters: [],
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
],
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<Poll @attrs={{this.attributes}} @preloadedVoters={{this.preloadedVoters}} @options={{this.options}} />`
|
||||
hbs`<Poll @attrs={{this.attributes}} @preloadedVoters={{this.preloadedVoters}} />`
|
||||
);
|
||||
|
||||
requests = 0;
|
||||
@ -178,13 +206,9 @@ module("Poll | Component | poll", function (hooks) {
|
||||
groupableUserFields: [],
|
||||
}),
|
||||
preloadedVoters: [],
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
],
|
||||
});
|
||||
await render(
|
||||
hbs`<Poll @attrs={{this.attributes}} @preloadedVoters={{this.preloadedVoters}} @options={{this.options}} />`
|
||||
hbs`<Poll @attrs={{this.attributes}} @preloadedVoters={{this.preloadedVoters}} />`
|
||||
);
|
||||
|
||||
assert.ok(exists(".poll-buttons .cast-votes:disabled"));
|
||||
|
Reference in New Issue
Block a user