2020-05-14 10:04:08 -04:00
import I18n from "I18n" ;
2019-06-06 04:47:10 -04:00
import selectKit from "helpers/select-kit-helper" ;
2019-06-14 08:54:20 -04:00
import { acceptance , updateCurrentUser } from "helpers/qunit-helpers" ;
2018-06-15 11:03:24 -04:00
import { _clearSnapshots } from "select-kit/components/composer-actions" ;
2018-12-19 04:25:33 -05:00
import { toggleCheckDraftPopup } from "discourse/controllers/composer" ;
2020-02-04 10:59:56 -05:00
import Draft from "discourse/models/draft" ;
import { Promise } from "rsvp" ;
2018-02-01 10:42:56 -05:00
2018-06-15 11:03:24 -04:00
acceptance ( "Composer Actions" , {
2018-02-01 10:42:56 -05:00
loggedIn : true ,
settings : {
enable _whispers : true
2018-05-23 13:57:12 -04:00
} ,
2019-01-22 11:26:52 -05:00
site : {
can _tag _topics : true
} ,
2018-05-23 13:57:12 -04:00
beforeEach ( ) {
_clearSnapshots ( ) ;
2018-06-15 11:03:24 -04:00
}
2018-02-01 10:42:56 -05:00
} ) ;
2020-05-25 01:46:02 -04:00
QUnit . test (
"creating new topic and then reply_as_private_message keeps attributes" ,
async assert => {
await visit ( "/" ) ;
await click ( "button#create-topic" ) ;
await fillIn ( "#reply-title" , "this is the title" ) ;
await fillIn ( ".d-editor-input" , "this is the reply" ) ;
const composerActions = selectKit ( ".composer-actions" ) ;
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "reply_as_private_message" ) ;
assert . ok ( find ( "#reply-title" ) . val ( ) , "this is the title" ) ;
assert . ok ( find ( ".d-editor-input" ) . val ( ) , "this is the reply" ) ;
}
) ;
2018-06-15 11:03:24 -04:00
QUnit . test ( "replying to post" , async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
2018-02-01 10:42:56 -05:00
2018-06-15 11:03:24 -04:00
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_3 button.reply" ) ;
2018-07-29 16:51:32 -04:00
await composerActions . expand ( ) ;
2018-04-23 02:42:25 -04:00
2018-06-15 11:03:24 -04:00
assert . equal ( composerActions . rowByIndex ( 0 ) . value ( ) , "reply_as_new_topic" ) ;
assert . equal (
composerActions . rowByIndex ( 1 ) . value ( ) ,
"reply_as_private_message"
) ;
assert . equal ( composerActions . rowByIndex ( 2 ) . value ( ) , "reply_to_topic" ) ;
assert . equal ( composerActions . rowByIndex ( 3 ) . value ( ) , "toggle_whisper" ) ;
2018-08-09 20:48:30 -04:00
assert . equal ( composerActions . rowByIndex ( 4 ) . value ( ) , "toggle_topic_bump" ) ;
assert . equal ( composerActions . rowByIndex ( 5 ) . value ( ) , undefined ) ;
2018-02-01 10:42:56 -05:00
} ) ;
2018-06-15 11:03:24 -04:00
QUnit . test ( "replying to post - reply_as_private_message" , async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
2018-02-01 10:42:56 -05:00
2018-06-15 11:03:24 -04:00
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_3 button.reply" ) ;
2018-02-01 10:42:56 -05:00
2018-07-29 16:51:32 -04:00
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "reply_as_private_message" ) ;
2018-02-01 10:42:56 -05:00
2018-06-15 11:03:24 -04:00
assert . equal ( find ( ".users-input .item:eq(0)" ) . text ( ) , "codinghorror" ) ;
assert . ok (
find ( ".d-editor-input" )
. val ( )
. indexOf ( "Continuing the discussion" ) >= 0
) ;
2018-02-01 10:42:56 -05:00
} ) ;
2018-06-15 11:03:24 -04:00
QUnit . test ( "replying to post - reply_to_topic" , async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
2018-02-01 10:42:56 -05:00
2018-06-15 11:03:24 -04:00
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_3 button.reply" ) ;
await fillIn (
".d-editor-input" ,
"test replying to topic when initially replied to post"
) ;
2018-02-01 10:42:56 -05:00
2018-07-29 16:51:32 -04:00
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "reply_to_topic" ) ;
2018-05-21 23:56:11 -04:00
2018-06-15 11:03:24 -04:00
assert . equal (
find ( ".action-title .topic-link" )
. text ( )
. trim ( ) ,
"Internationalization / localization"
) ;
assert . equal (
find ( ".action-title .topic-link" ) . attr ( "href" ) ,
"/t/internationalization-localization/280"
) ;
assert . equal (
find ( ".d-editor-input" ) . val ( ) ,
"test replying to topic when initially replied to post"
) ;
2018-02-01 10:42:56 -05:00
} ) ;
2018-06-15 11:03:24 -04:00
QUnit . test ( "replying to post - toggle_whisper" , async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
2018-02-01 10:42:56 -05:00
2018-06-15 11:03:24 -04:00
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_3 button.reply" ) ;
await fillIn (
".d-editor-input" ,
"test replying as whisper to topic when initially not a whisper"
) ;
2018-05-23 09:52:15 -04:00
2018-07-29 16:51:32 -04:00
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "toggle_whisper" ) ;
2018-02-01 10:42:56 -05:00
2019-01-22 06:02:02 -05:00
assert . ok (
find ( ".composer-fields .whisper .d-icon-far-eye-slash" ) . length === 1
) ;
2018-02-01 10:42:56 -05:00
} ) ;
2018-06-15 11:03:24 -04:00
QUnit . test ( "replying to post - reply_as_new_topic" , async assert => {
2020-02-04 10:59:56 -05:00
sandbox
. stub ( Draft , "get" )
. returns ( Promise . resolve ( { draft : "" , draft _sequence : 0 } ) ) ;
2018-06-15 11:03:24 -04:00
const composerActions = selectKit ( ".composer-actions" ) ;
const categoryChooser = selectKit ( ".title-wrapper .category-chooser" ) ;
const categoryChooserReplyArea = selectKit ( ".reply-area .category-chooser" ) ;
const quote = "test replying as new topic when initially replied to post" ;
2018-02-01 10:42:56 -05:00
2018-06-15 11:03:24 -04:00
await visit ( "/t/internationalization-localization/280" ) ;
2018-05-23 09:52:15 -04:00
2019-01-22 06:02:02 -05:00
await click ( "#topic-title .d-icon-pencil-alt" ) ;
2018-07-29 16:51:32 -04:00
await categoryChooser . expand ( ) ;
await categoryChooser . selectRowByValue ( 4 ) ;
2018-06-15 11:03:24 -04:00
await click ( "#topic-title .submit-edit" ) ;
2018-02-01 10:42:56 -05:00
2018-06-15 11:03:24 -04:00
await click ( "article#post_3 button.reply" ) ;
await fillIn ( ".d-editor-input" , quote ) ;
2018-02-01 10:42:56 -05:00
2018-07-29 16:51:32 -04:00
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "reply_as_new_topic" ) ;
2018-02-01 10:42:56 -05:00
2018-06-15 11:03:24 -04:00
assert . equal ( categoryChooserReplyArea . header ( ) . name ( ) , "faq" ) ;
assert . equal (
find ( ".action-title" )
. text ( )
. trim ( ) ,
I18n . t ( "topic.create_long" )
) ;
assert . ok (
find ( ".d-editor-input" )
. val ( )
. includes ( quote )
) ;
2020-02-04 10:59:56 -05:00
sandbox . restore ( ) ;
2018-02-08 05:46:55 -05:00
} ) ;
2020-02-04 10:59:56 -05:00
QUnit . test ( "reply_as_new_topic without a new_topic draft" , async assert => {
await visit ( "/t/internationalization-localization/280" ) ;
await click ( ".create.reply" ) ;
const composerActions = selectKit ( ".composer-actions" ) ;
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "reply_as_new_topic" ) ;
assert . equal ( exists ( find ( ".bootbox" ) ) , false ) ;
2018-03-13 15:59:12 -04:00
} ) ;
2018-02-08 05:46:55 -05:00
2018-06-15 11:03:24 -04:00
QUnit . test ( "hide component if no content" , async assert => {
2020-05-15 13:54:44 -04:00
await visit ( "/" ) ;
await click ( "button#create-topic" ) ;
2018-05-23 12:25:58 -04:00
2020-05-15 13:54:44 -04:00
const composerActions = selectKit ( ".composer-actions" ) ;
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "reply_as_private_message" ) ;
2018-05-23 12:25:58 -04:00
assert . ok ( composerActions . el ( ) . hasClass ( "is-hidden" ) ) ;
2020-05-15 13:54:44 -04:00
await click ( "button#create-topic" ) ;
await composerActions . expand ( ) ;
assert . equal ( composerActions . rows ( ) . length , 2 ) ;
2018-05-23 12:25:58 -04:00
} ) ;
2018-06-15 11:03:24 -04:00
QUnit . test ( "interactions" , async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
const quote = "Life is like riding a bicycle." ;
2018-02-08 05:46:55 -05:00
2018-06-15 11:03:24 -04:00
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_3 button.reply" ) ;
await fillIn ( ".d-editor-input" , quote ) ;
2018-07-29 16:51:32 -04:00
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "reply_to_topic" ) ;
2018-02-08 05:46:55 -05:00
2018-06-15 11:03:24 -04:00
assert . equal (
find ( ".action-title" )
. text ( )
. trim ( ) ,
"Internationalization / localization"
) ;
assert . equal ( find ( ".d-editor-input" ) . val ( ) , quote ) ;
2018-02-08 05:46:55 -05:00
2018-07-29 16:51:32 -04:00
await composerActions . expand ( ) ;
2018-02-08 05:46:55 -05:00
2018-06-15 11:03:24 -04:00
assert . equal ( composerActions . rowByIndex ( 0 ) . value ( ) , "reply_as_new_topic" ) ;
assert . equal ( composerActions . rowByIndex ( 1 ) . value ( ) , "reply_to_post" ) ;
assert . equal (
composerActions . rowByIndex ( 2 ) . value ( ) ,
"reply_as_private_message"
) ;
assert . equal ( composerActions . rowByIndex ( 3 ) . value ( ) , "toggle_whisper" ) ;
2018-08-09 20:48:30 -04:00
assert . equal ( composerActions . rowByIndex ( 4 ) . value ( ) , "toggle_topic_bump" ) ;
assert . equal ( composerActions . rows ( ) . length , 5 ) ;
2018-02-08 05:46:55 -05:00
2018-07-29 16:51:32 -04:00
await composerActions . selectRowByValue ( "reply_to_post" ) ;
await composerActions . expand ( ) ;
2018-02-08 05:46:55 -05:00
2018-06-15 11:03:24 -04:00
assert . ok ( exists ( find ( ".action-title img.avatar" ) ) ) ;
assert . equal (
find ( ".action-title .user-link" )
. text ( )
. trim ( ) ,
"codinghorror"
) ;
assert . equal ( find ( ".d-editor-input" ) . val ( ) , quote ) ;
assert . equal ( composerActions . rowByIndex ( 0 ) . value ( ) , "reply_as_new_topic" ) ;
assert . equal (
composerActions . rowByIndex ( 1 ) . value ( ) ,
"reply_as_private_message"
) ;
assert . equal ( composerActions . rowByIndex ( 2 ) . value ( ) , "reply_to_topic" ) ;
assert . equal ( composerActions . rowByIndex ( 3 ) . value ( ) , "toggle_whisper" ) ;
2018-08-09 20:48:30 -04:00
assert . equal ( composerActions . rowByIndex ( 4 ) . value ( ) , "toggle_topic_bump" ) ;
assert . equal ( composerActions . rows ( ) . length , 5 ) ;
2018-02-08 05:46:55 -05:00
2018-07-29 16:51:32 -04:00
await composerActions . selectRowByValue ( "reply_as_new_topic" ) ;
await composerActions . expand ( ) ;
2018-02-08 05:46:55 -05:00
2018-06-15 11:03:24 -04:00
assert . equal (
find ( ".action-title" )
. text ( )
. trim ( ) ,
I18n . t ( "topic.create_long" )
) ;
assert . ok (
find ( ".d-editor-input" )
. val ( )
. includes ( quote )
) ;
assert . equal ( composerActions . rowByIndex ( 0 ) . value ( ) , "reply_to_post" ) ;
assert . equal (
composerActions . rowByIndex ( 1 ) . value ( ) ,
"reply_as_private_message"
) ;
assert . equal ( composerActions . rowByIndex ( 2 ) . value ( ) , "reply_to_topic" ) ;
assert . equal ( composerActions . rowByIndex ( 3 ) . value ( ) , "shared_draft" ) ;
2018-05-23 09:52:15 -04:00
assert . equal ( composerActions . rows ( ) . length , 4 ) ;
2018-02-08 05:46:55 -05:00
2018-07-29 16:51:32 -04:00
await composerActions . selectRowByValue ( "reply_as_private_message" ) ;
await composerActions . expand ( ) ;
2018-05-22 04:50:54 -04:00
2018-06-15 11:03:24 -04:00
assert . equal (
find ( ".action-title" )
. text ( )
. trim ( ) ,
I18n . t ( "topic.private_message" )
) ;
assert . ok (
find ( ".d-editor-input" )
. val ( )
. indexOf ( "Continuing the discussion" ) === 0
) ;
assert . equal ( composerActions . rowByIndex ( 0 ) . value ( ) , "reply_as_new_topic" ) ;
assert . equal ( composerActions . rowByIndex ( 1 ) . value ( ) , "reply_to_post" ) ;
assert . equal ( composerActions . rowByIndex ( 2 ) . value ( ) , "reply_to_topic" ) ;
2018-05-23 09:52:15 -04:00
assert . equal ( composerActions . rows ( ) . length , 3 ) ;
2018-02-01 10:42:56 -05:00
} ) ;
2018-08-09 20:48:30 -04:00
QUnit . test ( "replying to post - toggle_topic_bump" , async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_3 button.reply" ) ;
assert . ok (
find ( ".composer-fields .no-bump" ) . length === 0 ,
"no-bump text is not visible"
) ;
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "toggle_topic_bump" ) ;
2018-08-11 15:51:13 -04:00
assert . ok (
find ( ".composer-fields .no-bump" ) . length === 1 ,
"no-bump icon is visible"
2018-08-09 20:48:30 -04:00
) ;
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "toggle_topic_bump" ) ;
assert . ok (
find ( ".composer-fields .no-bump" ) . length === 0 ,
2018-08-11 15:51:13 -04:00
"no-bump icon is not visible"
2018-08-09 20:48:30 -04:00
) ;
} ) ;
QUnit . test ( "replying to post as staff" , async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
2019-07-24 16:01:08 -04:00
updateCurrentUser ( { admin : true } ) ;
2018-08-09 20:48:30 -04:00
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_3 button.reply" ) ;
await composerActions . expand ( ) ;
assert . equal ( composerActions . rows ( ) . length , 5 ) ;
assert . equal ( composerActions . rowByIndex ( 4 ) . value ( ) , "toggle_topic_bump" ) ;
} ) ;
2019-01-02 14:15:12 -05:00
QUnit . test ( "replying to post as TL3 user" , async assert => {
2018-08-09 20:48:30 -04:00
const composerActions = selectKit ( ".composer-actions" ) ;
2019-07-24 16:01:08 -04:00
updateCurrentUser ( { moderator : false , admin : false , trust _level : 3 } ) ;
2018-08-09 20:48:30 -04:00
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_3 button.reply" ) ;
await composerActions . expand ( ) ;
assert . equal ( composerActions . rows ( ) . length , 3 ) ;
Array . from ( composerActions . rows ( ) ) . forEach ( row => {
assert . notEqual (
row . value ,
"toggle_topic_bump" ,
"toggle button is not visible"
) ;
} ) ;
} ) ;
2018-08-23 05:09:35 -04:00
2019-01-02 14:15:12 -05:00
QUnit . test ( "replying to post as TL4 user" , async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
2019-07-24 16:01:08 -04:00
updateCurrentUser ( { moderator : false , admin : false , trust _level : 4 } ) ;
2019-01-02 14:15:12 -05:00
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_3 button.reply" ) ;
await composerActions . expand ( ) ;
assert . equal ( composerActions . rows ( ) . length , 4 ) ;
assert . equal ( composerActions . rowByIndex ( 3 ) . value ( ) , "toggle_topic_bump" ) ;
} ) ;
2018-08-23 05:09:35 -04:00
QUnit . test (
"replying to first post - reply_as_private_message" ,
async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_1 button.reply" ) ;
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "reply_as_private_message" ) ;
assert . equal ( find ( ".users-input .item:eq(0)" ) . text ( ) , "uwe_keim" ) ;
assert . ok (
find ( ".d-editor-input" )
. val ( )
. indexOf ( "Continuing the discussion" ) >= 0
) ;
}
) ;
2020-02-04 10:59:56 -05:00
2020-05-14 01:56:45 -04:00
QUnit . test ( "editing post" , async assert => {
const composerActions = selectKit ( ".composer-actions" ) ;
await visit ( "/t/internationalization-localization/280" ) ;
await click ( "article#post_1 button.show-more-actions" ) ;
await click ( "article#post_1 button.edit" ) ;
await composerActions . expand ( ) ;
assert . equal ( composerActions . rows ( ) . length , 1 ) ;
assert . equal ( composerActions . rowByIndex ( 0 ) . value ( ) , "reply_to_post" ) ;
} ) ;
2020-02-04 10:59:56 -05:00
acceptance ( "Composer Actions With New Topic Draft" , {
loggedIn : true ,
settings : {
enable _whispers : true
} ,
site : {
can _tag _topics : true
} ,
beforeEach ( ) {
_clearSnapshots ( ) ;
}
} ) ;
2020-03-02 14:24:31 -05:00
const stubDraftResponse = ( ) => {
sandbox . stub ( Draft , "get" ) . returns (
Promise . resolve ( {
draft :
'{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}' ,
draft _sequence : 0
} )
) ;
} ;
2020-02-04 10:59:56 -05:00
QUnit . test ( "shared draft" , async assert => {
2020-03-02 14:24:31 -05:00
stubDraftResponse ( ) ;
2020-02-04 10:59:56 -05:00
try {
toggleCheckDraftPopup ( true ) ;
const composerActions = selectKit ( ".composer-actions" ) ;
const tags = selectKit ( ".mini-tag-chooser" ) ;
await visit ( "/" ) ;
await click ( "#create-topic" ) ;
await fillIn (
"#reply-title" ,
"This is the new text for the title using 'quotes'"
) ;
await fillIn ( ".d-editor-input" , "This is the new text for the post" ) ;
await tags . expand ( ) ;
await tags . selectRowByValue ( "monkey" ) ;
await composerActions . expand ( ) ;
await composerActions . selectRowByValue ( "shared_draft" ) ;
assert . equal ( tags . header ( ) . value ( ) , "monkey" , "tags are not reset" ) ;
assert . equal (
find ( "#reply-title" ) . val ( ) ,
"This is the new text for the title using 'quotes'"
) ;
assert . equal (
find ( "#reply-control .btn-primary.create .d-button-label" ) . text ( ) ,
I18n . t ( "composer.create_shared_draft" )
) ;
assert . ok ( find ( "#reply-control.composing-shared-draft" ) . length === 1 ) ;
await click ( ".modal-footer .btn.btn-default" ) ;
} finally {
toggleCheckDraftPopup ( false ) ;
}
2020-03-02 14:24:31 -05:00
sandbox . restore ( ) ;
2020-02-04 10:59:56 -05:00
} ) ;
QUnit . test ( "reply_as_new_topic with new_topic draft" , async assert => {
await visit ( "/t/internationalization-localization/280" ) ;
await click ( ".create.reply" ) ;
const composerActions = selectKit ( ".composer-actions" ) ;
await composerActions . expand ( ) ;
2020-03-02 14:24:31 -05:00
stubDraftResponse ( ) ;
2020-02-04 10:59:56 -05:00
await composerActions . selectRowByValue ( "reply_as_new_topic" ) ;
assert . equal (
find ( ".bootbox .modal-body" ) . text ( ) ,
I18n . t ( "composer.composer_actions.reply_as_new_topic.confirm" )
) ;
await click ( ".modal-footer .btn.btn-default" ) ;
2020-03-02 14:24:31 -05:00
sandbox . restore ( ) ;
2020-02-04 10:59:56 -05:00
} ) ;