FIX: more resilient whisper state between composer states (#6687)

This commit is contained in:
Joffrey JAFFEUX 2018-11-29 16:16:34 +01:00 committed by GitHub
parent 8da8f5d0f7
commit 4f24d7dec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 12 deletions

View File

@ -194,9 +194,13 @@ export default Ember.Controller.extend({
canUnlistTopic: Em.computed.and("model.creatingTopic", "isStaffUser"), canUnlistTopic: Em.computed.and("model.creatingTopic", "isStaffUser"),
@computed("canWhisper", "model.whisper") @computed("canWhisper", "model.post")
showWhisperToggle(canWhisper, isWhisper) { showWhisperToggle(canWhisper, repliedToPost) {
return canWhisper && !isWhisper; const replyingToWhisper =
repliedToPost &&
repliedToPost.get("post_type") === this.site.post_types.whisper;
return canWhisper && !replyingToWhisper;
}, },
@computed("isStaffUser", "model.action") @computed("isStaffUser", "model.action")
@ -220,7 +224,7 @@ export default Ember.Controller.extend({
return option; return option;
}, },
@computed("model.composeState", "model.creatingTopic") @computed("model.composeState", "model.creatingTopic", "model.post")
popupMenuOptions(composeState) { popupMenuOptions(composeState) {
if (composeState === "open" || composeState === "fullscreen") { if (composeState === "open" || composeState === "fullscreen") {
let options = []; let options = [];

View File

@ -366,28 +366,36 @@ QUnit.test("Composer can toggle between edit and reply", async assert => {
}); });
QUnit.test("Composer can toggle whispers", async assert => { QUnit.test("Composer can toggle whispers", async assert => {
const menu = selectKit(".toolbar-popup-menu-options");
await visit("/t/this-is-a-test-topic/9"); await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply"); await click(".topic-post:eq(0) button.reply");
await selectKit(".toolbar-popup-menu-options").expand(); await menu.expand();
await selectKit(".toolbar-popup-menu-options").selectRowByValue( await menu.selectRowByValue("toggleWhisper");
"toggleWhisper"
);
assert.ok( assert.ok(
find(".composer-fields .whisper .d-icon-eye-slash").length === 1, find(".composer-fields .whisper .d-icon-eye-slash").length === 1,
"it sets the post type to whisper" "it sets the post type to whisper"
); );
await selectKit(".toolbar-popup-menu-options").expand(); await menu.expand();
await selectKit(".toolbar-popup-menu-options").selectRowByValue( await menu.selectRowByValue("toggleWhisper");
"toggleWhisper"
);
assert.ok( assert.ok(
find(".composer-fields .whisper .d-icon-eye-slash").length === 0, find(".composer-fields .whisper .d-icon-eye-slash").length === 0,
"it removes the whisper mode" "it removes the whisper mode"
); );
await menu.expand();
await menu.selectRowByValue("toggleWhisper");
await click(".toggle-fullscreen");
assert.ok(
menu.rowByValue("toggleWhisper").exists(),
"whisper toggling is still present when going fullscreen"
);
}); });
QUnit.test( QUnit.test(