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:
Robert
2024-08-02 07:50:33 +01:00
committed by GitHub
parent 11369018b6
commit 26c4d1398a
6 changed files with 264 additions and 194 deletions

View File

@ -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"));