Skip to content

A platform for community discussion. Free, open, simple.

FIX: polls extending in post reply histories (#11837)

Andrew Prigorshnev3bbe87f22930
diff --git a/app/assets/javascripts/discourse/app/widgets/post.js b/app/assets/javascripts/discourse/app/widgets/post.js
index e90befbc421..5c7dad44c25 100644
--- a/app/assets/javascripts/discourse/app/widgets/post.js
+++ b/app/assets/javascripts/discourse/app/widgets/post.js
@@ -660,8 +660,10 @@ createWidget("post-article", {
.find("post-reply-history", { postId: this.attrs.id })
.then((posts) => {
this.state.repliesAbove = posts.map((p) => {
- p.shareUrl = `${topicUrl}/${p.post_number}`;
- return transformWithCallbacks(p);
+ let result = transformWithCallbacks(p);
+ result.shareUrl = `${topicUrl}/${p.post_number}`;
+ result.asPost = this.store.createRecord("post", p);
+ return result;
});
});
}
diff --git a/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6
new file mode 100644
index 00000000000..1959caab884
--- /dev/null
+++ b/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6
@@ -0,0 +1,444 @@
+import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
+
+acceptance("Poll in a post reply history", function (needs) {
+ needs.user();
+ needs.settings({ poll_enabled: true });
+ needs.hooks.beforeEach(() => {
+ clearPopupMenuOptionsCallback();
+ });
+
+ needs.pretender((server, helper) => {
+ server.get("/t/topic_with_poll_in_post_reply_history.json", () => {
+ return helper.response({
+ post_stream: {
+ posts: [
+ {
+ id: 82,
+ name: null,
+ username: "admin1",
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/a/bbce88/{size}.png",
+ created_at: "2021-01-25T13:08:27.385Z",
+ cooked: "<p>A reply to the poll.</p>",
+ post_number: 4,
+ post_type: 1,
+ updated_at: "2021-01-25T13:08:27.385Z",
+ reply_count: 0,
+ reply_to_post_number: 2,
+ quote_count: 0,
+ incoming_link_count: 0,
+ reads: 1,
+ readers_count: 0,
+ score: 0.2,
+ yours: true,
+ topic_id: 25,
+ topic_slug: "topic-with-a-poll-in-a-post-reply-history",
+ display_username: null,
+ primary_group_name: null,
+ primary_group_flair_url: null,
+ primary_group_flair_bg_color: null,
+ primary_group_flair_color: null,
+ version: 1,
+ can_edit: true,
+ can_delete: true,
+ can_recover: false,
+ can_wiki: true,
+ read: true,
+ user_title: null,
+ reply_to_user: {
+ username: "admin1",
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/a/bbce88/{size}.png",
+ },
+ bookmarked: false,
+ actions_summary: [
+ {
+ id: 3,
+ can_act: true,
+ },
+ {
+ id: 4,
+ can_act: true,
+ },
+ {
+ id: 8,
+ can_act: true,
+ },
+ {
+ id: 7,
+ can_act: true,
+ },
+ ],
+ moderator: false,
+ admin: true,
+ staff: true,
+ user_id: 3,
+ hidden: false,
+ trust_level: 1,
+ deleted_at: null,
+ user_deleted: false,
+ edit_reason: null,
+ can_view_edit_history: true,
+ wiki: false,
+ reviewable_id: 0,
+ reviewable_score_count: 0,
+ reviewable_score_pending_count: 0,
+ },
+ ],
+ stream: [82],
+ },
+ timeline_lookup: [[1, 0]],
+ suggested_topics: [
+ {
+ id: 7,
+ title: "Welcome to Discourse",
+ fancy_title: "Welcome to Discourse",
+ slug: "welcome-to-discourse",
+ posts_count: 1,
+ reply_count: 0,
+ highest_post_number: 1,
+ image_url: null,
+ created_at: "2021-01-07T15:36:44.707Z",
+ last_posted_at: "2021-01-07T15:36:44.750Z",
+ bumped: true,
+ bumped_at: "2021-01-07T15:36:44.750Z",
+ archetype: "regular",
+ unseen: false,
+ pinned: true,
+ unpinned: null,
+ excerpt:
+ "The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It’s important! Edit this into a brief description of your community: Who is it for? What can they fi&hellip;",
+ visible: true,
+ closed: false,
+ archived: false,
+ bookmarked: null,
+ liked: null,
+ like_count: 0,
+ views: 1,
+ category_id: 1,
+ featured_link: null,
+ posters: [
+ {
+ extras: "latest single",
+ description: "Original Poster, Most Recent Poster",
+ user: {
+ id: -1,
+ username: "system",
+ name: "system",
+ avatar_template:
+ "http://localhost:3000/images/discourse-logo-sketch-small.png",
+ },
+ },
+ ],
+ },
+ {
+ id: 20,
+ title: "Polls testing. Just one poll in the comment",
+ fancy_title: "Polls testing. Just one poll in the comment",
+ slug: "polls-testing-just-one-poll-in-the-comment",
+ posts_count: 3,
+ reply_count: 1,
+ highest_post_number: 3,
+ image_url: null,
+ created_at: "2021-01-21T09:21:35.102Z",
+ last_posted_at: "2021-01-22T09:35:33.543Z",
+ bumped: true,
+ bumped_at: "2021-01-22T09:35:33.543Z",
+ archetype: "regular",
+ unseen: false,
+ last_read_post_number: 3,
+ unread: 0,
+ new_posts: 0,
+ pinned: false,
+ unpinned: null,
+ visible: true,
+ closed: false,
+ archived: false,
+ notification_level: 2,
+ bookmarked: false,
+ liked: false,
+ like_count: 0,
+ views: 3,
+ category_id: 1,
+ featured_link: null,
+ posters: [
+ {
+ extras: null,
+ description: "Original Poster",
+ user: {
+ id: 2,
+ username: "andrey1",
+ name: "andrey1",
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/a/c0e974/{size}.png",
+ },
+ },
+ {
+ extras: "latest",
+ description: "Most Recent Poster",
+ user: {
+ id: 3,
+ username: "admin1",
+ name: null,
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/a/bbce88/{size}.png",
+ },
+ },
+ ],
+ },
+ {
+ id: 22,
+ title: "Polls testing. The whole test",
+ fancy_title: "Polls testing. The whole test",
+ slug: "polls-testing-the-whole-test",
+ posts_count: 12,
+ reply_count: 8,
+ highest_post_number: 12,
+ image_url: null,
+ created_at: "2021-01-21T09:55:20.135Z",
+ last_posted_at: "2021-01-22T11:59:31.561Z",
+ bumped: true,
+ bumped_at: "2021-01-22T11:59:31.561Z",
+ archetype: "regular",
+ unseen: false,
+ last_read_post_number: 12,
+ unread: 0,
+ new_posts: 0,
+ pinned: false,
+ unpinned: null,
+ visible: true,
+ closed: false,
+ archived: false,
+ notification_level: 2,
+ bookmarked: false,
+ liked: false,
+ like_count: 0,
+ views: 4,
+ category_id: 1,
+ featured_link: null,
+ posters: [
+ {
+ extras: null,
+ description: "Original Poster",
+ user: {
+ id: 2,
+ username: "andrey1",
+ name: "andrey1",
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/a/c0e974/{size}.png",
+ },
+ },
+ {
+ extras: "latest",
+ description: "Most Recent Poster",
+ user: {
+ id: 3,
+ username: "admin1",
+ name: null,
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/a/bbce88/{size}.png",
+ },
+ },
+ ],
+ },
+ ],
+ id: 25,
+ title: "Topic with a poll in a post reply history",
+ fancy_title: "Topic with a poll in a post reply history",
+ posts_count: 4,
+ created_at: "2021-01-25T13:07:31.670Z",
+ views: 2,
+ reply_count: 2,
+ like_count: 0,
+ last_posted_at: "2021-01-25T13:08:27.385Z",
+ visible: true,
+ closed: false,
+ archived: false,
+ has_summary: false,
+ archetype: "regular",
+ slug: "topic-with-a-poll-in-a-post-reply-history",
+ category_id: 1,
+ word_count: 25,
+ deleted_at: null,
+ user_id: 3,
+ featured_link: null,
+ pinned_globally: false,
+ pinned_at: null,
+ pinned_until: null,
+ image_url: null,
+ slow_mode_seconds: 0,
+ draft: null,
+ draft_key: "topic_25",
+ draft_sequence: 4,
+ posted: true,
+ unpinned: null,
+ pinned: false,
+ current_post_number: 4,
+ highest_post_number: 4,
+ last_read_post_number: 4,
+ last_read_post_id: 82,
+ deleted_by: null,
+ has_deleted: false,
+ actions_summary: [
+ {
+ id: 4,
+ count: 0,
+ hidden: false,
+ can_act: true,
+ },
+ {
+ id: 8,
+ count: 0,
+ hidden: false,
+ can_act: true,
+ },
+ {
+ id: 7,
+ count: 0,
+ hidden: false,
+ can_act: true,
+ },
+ ],
+ chunk_size: 20,
+ bookmarked: false,
+ topic_timer: null,
+ message_bus_last_id: 4,
+ participant_count: 1,
+ show_read_indicator: false,
+ thumbnails: null,
+ details: {
+ can_edit: true,
+ notification_level: 3,
+ notifications_reason_id: 1,
+ can_move_posts: true,
+ can_delete: true,
+ can_remove_allowed_users: true,
+ can_invite_to: true,
+ can_invite_via_email: true,
+ can_create_post: true,
+ can_reply_as_new_topic: true,
+ can_flag_topic: true,
+ can_convert_topic: true,
+ can_review_topic: true,
+ can_close_topic: true,
+ can_archive_topic: true,
+ can_split_merge_topic: true,
+ can_edit_staff_notes: true,
+ can_toggle_topic_visibility: true,
+ can_moderate_category: true,
+ can_remove_self_id: 3,
+ participants: [
+ {
+ id: 3,
+ username: "admin1",
+ name: null,
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/a/bbce88/{size}.png",
+ post_count: 4,
+ primary_group_name: null,
+ primary_group_flair_url: null,
+ primary_group_flair_color: null,
+ primary_group_flair_bg_color: null,
+ },
+ ],
+ created_by: {
+ id: 3,
+ username: "admin1",
+ name: null,
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/a/bbce88/{size}.png",
+ },
+ last_poster: {
+ id: 3,
+ username: "admin1",
+ name: null,
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/a/bbce88/{size}.png",
+ },
+ },
+ });
+ });
+
+ server.get("/posts/82/reply-history", () => {
+ return helper.response([
+ {
+ id: 80,
+ name: null,
+ username: "admin1",
+ avatar_template: "/letter_avatar_proxy/v4/letter/a/bbce88/{size}.png",
+ created_at: "2021-01-25T13:07:58.995Z",
+ cooked:
+ '<p>The poll:</p>\n<div class="poll" data-poll-status="open" data-poll-name="poll">\n<div>\n<div class="poll-container">\n<ul>\n<li data-poll-option-id="5b8ee5ba2a43e258f93dbef9264bf1ad">Option A</li>\n<li data-poll-option-id="6872645f5d8ef2311883617a3a7d381b">Option B</li>\n</ul>\n</div>\n<div class="poll-info">\n<p>\n<span class="info-number">0</span>\n<span class="info-label">voters</span>\n</p>\n</div>\n</div>\n</div>',
+ post_number: 2,
+ post_type: 1,
+ updated_at: "2021-01-25T13:07:58.995Z",
+ reply_count: 2,
+ reply_to_post_number: null,
+ quote_count: 0,
+ incoming_link_count: 0,
+ reads: 1,
+ readers_count: 0,
+ score: 10.2,
+ yours: false,
+ topic_id: 25,
+ topic_slug: "topic-with-a-poll-in-a-post-reply-history",
+ display_username: null,
+ primary_group_name: null,
+ primary_group_flair_url: null,
+ primary_group_flair_bg_color: null,
+ primary_group_flair_color: null,
+ version: 1,
+ can_edit: false,
+ can_delete: false,
+ can_recover: false,
+ can_wiki: false,
+ user_title: null,
+ bookmarked: false,
+ actions_summary: [],
+ moderator: false,
+ admin: true,
+ staff: true,
+ user_id: 3,
+ hidden: false,
+ trust_level: 1,
+ deleted_at: null,
+ user_deleted: false,
+ edit_reason: null,
+ can_view_edit_history: true,
+ wiki: false,
+ polls: [
+ {
+ name: "poll",
+ type: "regular",
+ status: "open",
+ results: "always",
+ options: [
+ {
+ id: "5b8ee5ba2a43e258f93dbef9264bf1ad",
+ html: "Option A",
+ votes: 0,
+ },
+ {
+ id: "6872645f5d8ef2311883617a3a7d381b",
+ html: "Option B",
+ votes: 0,
+ },
+ ],
+ voters: 0,
+ chart_type: "bar",
+ title: null,
+ },
+ ],
+ },
+ ]);
+ });
+ });
+
+ test("renders and extends", async function (assert) {
+ await visit("/t/-/topic_with_poll_in_post_reply_history");
+ await click(".reply-to-tab");
+ assert.ok(exists(".poll"), "poll is rendered");
+ assert.ok(exists(".poll-buttons"), "poll is extended");
+ });
+});
diff --git a/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6
index 45b93f47c56..846f97c4a14 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6
@@ -9,257 +9,6 @@ acceptance("Poll quote", function (needs) {
});
needs.pretender((server, helper) => {
- server.get("/t/topic_with_two_polls.json", () => {
- return helper.response({
- post_stream: {
- posts: [
- {
- id: 133,
- name: null,
- username: "bianca",
- avatar_template:
- "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
- created_at: "2020-08-17T12:05:24.577Z",
- cooked:
- '<div class="poll" data-poll-status="open" data-poll-name="poll1" data-poll-results="always" data-poll-charttype="bar" data-poll-type="regular">\n<div>\n<div class="poll-container">\n<ul>\n<li data-poll-option-id="bf48cd4958a17180e2a298e246988f94">Alpha</li>\n<li data-poll-option-id="c19aa835729ab0413a84a2c9850c4005">Beta</li>\n</ul>\n</div>\n<div class="poll-info">\n<p>\n<span class="info-number">0</span>\n<span class="info-label">voters</span>\n</p>\n</div>\n</div>\n</div>\n<div class="poll" data-poll-status="open" data-poll-name="poll2" data-poll-results="always" data-poll-charttype="bar" data-poll-type="regular">\n<div>\n<div class="poll-container">\n<ul>\n<li data-poll-option-id="def034c6770c6fd3754c054ef9ec4721">First</li>\n<li data-poll-option-id="e0f55d1a981683789bec2a0b05eb70ef">Second</li>\n</ul>\n</div>\n<div class="poll-info">\n<p>\n<span class="info-number">0</span>\n<span class="info-label">voters</span>\n</p>\n</div>\n</div>\n</div>',
- post_number: 1,
- post_type: 1,
- updated_at: "2020-08-17T12:05:24.577Z",
- reply_count: 0,
- reply_to_post_number: null,
- quote_count: 0,
- incoming_link_count: 0,
- reads: 1,
- readers_count: 0,
- score: 0,
- yours: true,
- topic_id: 130,
- topic_slug: "topic-with-two-polls",
- display_username: null,
- primary_group_name: null,
- primary_group_flair_url: null,
- primary_group_flair_bg_color: null,
- primary_group_flair_color: null,
- version: 1,
- can_edit: true,
- can_delete: false,
- can_recover: false,
- can_wiki: true,
- link_counts: [
- {
- url:
- "http://forum.example.com/t/topic-with-two-quoted-polls/129",
- internal: true,
- reflection: true,
- title: "Topic with two quoted polls",
- clicks: 0,
- },
- ],
- read: true,
- user_title: "Tester",
- title_is_group: false,
- bookmarked: false,
- actions_summary: [
- {
- id: 3,
- can_act: true,
- },
- {
- id: 4,
- can_act: true,
- },
- {
- id: 8,
- can_act: true,
- },
- {
- id: 7,
- can_act: true,
- },
- ],
- moderator: false,
- admin: true,
- staff: true,
- user_id: 1,
- hidden: false,
- trust_level: 0,
- deleted_at: null,
- user_deleted: false,
- edit_reason: null,
- can_view_edit_history: true,
- wiki: false,
- reviewable_id: 0,
- reviewable_score_count: 0,
- reviewable_score_pending_count: 0,
- calendar_details: [],
- polls: [
- {
- name: "poll1",
- type: "regular",
- status: "open",
- results: "always",
- options: [
- {
- id: "bf48cd4958a17180e2a298e246988f94",
- html: "Alpha",
- votes: 0,
- },
- {
- id: "c19aa835729ab0413a84a2c9850c4005",
- html: "Beta",
- votes: 0,
- },
- ],
- voters: 0,
- chart_type: "bar",
- },
- {
- name: "poll2",
- type: "regular",
- status: "open",
- results: "always",
- options: [
- {
- id: "def034c6770c6fd3754c054ef9ec4721",
- html: "First",
- votes: 0,
- },
- {
- id: "e0f55d1a981683789bec2a0b05eb70ef",
- html: "Second",
- votes: 0,
- },
- ],
- voters: 0,
- chart_type: "bar",
- },
- ],
- },
- ],
- stream: [133],
- },
- timeline_lookup: [[1, 0]],
- suggested_topics: [],
- tags: [],
- id: 130,
- title: "Topic with two polls",
- fancy_title: "Topic with two polls",
- posts_count: 1,
- created_at: "2020-08-17T12:05:24.500Z",
- views: 1,
- reply_count: 0,
- like_count: 0,
- last_posted_at: "2020-08-17T12:05:24.577Z",
- visible: true,
- closed: false,
- archived: false,
- has_summary: false,
- archetype: "regular",
- slug: "topic-with-two-polls",
- category_id: 1,
- word_count: 24,
- deleted_at: null,
- user_id: 1,
- featured_link: null,
- pinned_globally: false,
- pinned_at: null,
- pinned_until: null,
- image_url: null,
- draft: null,
- draft_key: "topic_130",
- draft_sequence: 0,
- posted: true,
- unpinned: null,
- pinned: false,
- current_post_number: 1,
- highest_post_number: 1,
- last_read_post_number: 1,
- last_read_post_id: 133,
- deleted_by: null,
- has_deleted: false,
- actions_summary: [
- {
- id: 4,
- count: 0,
- hidden: false,
- can_act: true,
- },
- {
- id: 8,
- count: 0,
- hidden: false,
- can_act: true,
- },
- {
- id: 7,
- count: 0,
- hidden: false,
- can_act: true,
- },
- ],
- chunk_size: 20,
- bookmarked: false,
- topic_timer: null,
- message_bus_last_id: 1,
- participant_count: 1,
- queued_posts_count: 0,
- show_read_indicator: false,
- thumbnails: null,
- can_vote: false,
- vote_count: null,
- user_voted: false,
- details: {
- notification_level: 3,
- notifications_reason_id: 1,
- can_move_posts: true,
- can_edit: true,
- can_delete: true,
- can_remove_allowed_users: true,
- can_invite_to: true,
- can_invite_via_email: true,
- can_create_post: true,
- can_reply_as_new_topic: true,
- can_flag_topic: true,
- can_convert_topic: true,
- can_review_topic: true,
- can_close_topic: true,
- can_archive_topic: true,
- can_split_merge_topic: true,
- can_edit_staff_notes: true,
- can_remove_self_id: 1,
- participants: [
- {
- id: 1,
- username: "bianca",
- name: null,
- avatar_template:
- "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
- post_count: 1,
- primary_group_name: null,
- primary_group_flair_url: null,
- primary_group_flair_color: null,
- primary_group_flair_bg_color: null,
- },
- ],
- created_by: {
- id: 1,
- username: "bianca",
- name: null,
- avatar_template:
- "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
- },
- last_poster: {
- id: 1,
- username: "bianca",
- name: null,
- avatar_template:
- "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
- },
- },
- pending_posts: [],
- });
- });
-
server.get("/posts/by_number/130/1", () => {
return helper.response({
id: 133,
@@ -675,9 +424,10 @@ acceptance("Poll quote", function (needs) {
});
});
- test("Quoted polls", async function (assert) {
+ test("renders and extends", async function (assert) {
await visit("/t/-/topic_with_two_quoted_polls");
await click(".quote-controls");
- assert.equal(queryAll(".poll").length, 2);
+ assert.equal(queryAll(".poll").length, 2, "polls are rendered");
+ assert.equal(queryAll(".poll-buttons").length, 2, "polls are extended");
});
});