2021-11-13 22:31:42 +08:00
import { click , visit } from "@ember/test-helpers" ;
2023-10-11 02:38:59 +08:00
import { test } from "qunit" ;
2024-11-10 08:30:33 +08:00
import { acceptance } from "discourse/tests/helpers/qunit-helpers" ;
2021-01-26 23:29:49 +08:00
acceptance ( "Poll in a post reply history" , function ( needs ) {
needs . user ( ) ;
needs . settings ( { poll _enabled : true } ) ;
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 ,
2021-07-08 15:46:21 +08:00
flair _url : null ,
flair _bg _color : null ,
flair _color : null ,
2021-01-26 23:29:49 +08:00
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 ,
2021-09-21 06:45:47 +08:00
bookmarks : [ ] ,
2021-01-26 23:29:49 +08:00
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…" ,
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 ,
2021-07-05 14:17:31 +08:00
unread _posts : 0 ,
2021-01-26 23:29:49 +08:00
pinned : false ,
unpinned : null ,
visible : true ,
closed : false ,
archived : false ,
notification _level : 2 ,
bookmarked : false ,
2021-09-21 06:45:47 +08:00
bookmarks : [ ] ,
2021-01-26 23:29:49 +08:00
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 ,
2021-07-05 14:17:31 +08:00
unread _posts : 0 ,
2021-01-26 23:29:49 +08:00
pinned : false ,
unpinned : null ,
visible : true ,
closed : false ,
archived : false ,
notification _level : 2 ,
bookmarked : false ,
2021-09-21 06:45:47 +08:00
bookmarks : [ ] ,
2021-01-26 23:29:49 +08:00
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 ,
2021-09-21 06:45:47 +08:00
bookmarks : [ ] ,
2021-01-26 23:29:49 +08:00
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 ,
2021-07-08 15:46:21 +08:00
flair _url : null ,
flair _color : null ,
flair _bg _color : null ,
2021-01-26 23:29:49 +08:00
} ,
] ,
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 ,
2021-07-08 15:46:21 +08:00
flair _url : null ,
flair _bg _color : null ,
flair _color : null ,
2021-01-26 23:29:49 +08:00
version : 1 ,
can _edit : false ,
can _delete : false ,
can _recover : false ,
can _wiki : false ,
user _title : null ,
bookmarked : false ,
2021-09-21 06:45:47 +08:00
bookmarks : [ ] ,
2021-01-26 23:29:49 +08:00
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" ) ;
2024-11-10 08:30:33 +08:00
assert . dom ( ".poll" ) . exists ( "poll is rendered" ) ;
assert . dom ( ".poll-buttons" ) . exists ( "poll is extended" ) ;
2021-01-26 23:29:49 +08:00
} ) ;
} ) ;