From 63307c303ac80a1cb506162238d54048d1696735 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 24 Nov 2017 02:48:45 +0100 Subject: [PATCH] FIX: regression preventing to set number of hours before closing This commit also adds a full test suite for editing topic timer. --- .../components/edit-topic-timer-form.hbs | 2 +- .../future-date-input-selector.js.es6 | 3 +- .../acceptance/topic-edit-timer-test.js.es6 | 153 ++++++++++++++++++ 3 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 test/javascripts/acceptance/topic-edit-timer-test.js.es6 diff --git a/app/assets/javascripts/discourse/templates/components/edit-topic-timer-form.hbs b/app/assets/javascripts/discourse/templates/components/edit-topic-timer-form.hbs index 7de08949191..f90534931b7 100644 --- a/app/assets/javascripts/discourse/templates/components/edit-topic-timer-form.hbs +++ b/app/assets/javascripts/discourse/templates/components/edit-topic-timer-form.hbs @@ -1,6 +1,6 @@
- {{combo-box allowInitialValueMutation=true content=timerTypes value=selection}} + {{combo-box class="timer-type" allowInitialValueMutation=true content=timerTypes value=selection}}
diff --git a/app/assets/javascripts/select-kit/components/future-date-input-selector.js.es6 b/app/assets/javascripts/select-kit/components/future-date-input-selector.js.es6 index f91708655f1..edc562b7e88 100644 --- a/app/assets/javascripts/select-kit/components/future-date-input-selector.js.es6 +++ b/app/assets/javascripts/select-kit/components/future-date-input-selector.js.es6 @@ -114,6 +114,7 @@ export default ComboBoxComponent.extend(DatetimeMixin, { pluginApiIdentifiers: ["future-date-input-selector"], classNames: ["future-date-input-selector"], isCustom: Ember.computed.equal("value", "pick_date_and_time"), + isBasedOnLastPost: Ember.computed.equal("value", "set_based_on_last_post"), clearable: true, rowComponent: "future-date-input-selector/future-date-input-selector-row", headerComponent: "future-date-input-selector/future-date-input-selector-header", @@ -154,7 +155,7 @@ export default ComboBoxComponent.extend(DatetimeMixin, { }, mutateValue(value) { - if (this.get("isCustom")) { + if (this.get("isCustom") || this.get("isBasedOnLastPost")) { this.set("value", value); } else { let input = null; diff --git a/test/javascripts/acceptance/topic-edit-timer-test.js.es6 b/test/javascripts/acceptance/topic-edit-timer-test.js.es6 new file mode 100644 index 00000000000..431a0813e9c --- /dev/null +++ b/test/javascripts/acceptance/topic-edit-timer-test.js.es6 @@ -0,0 +1,153 @@ +import { acceptance } from 'helpers/qunit-helpers'; +acceptance('Topic - Edit timer', { loggedIn: true }); + +QUnit.test('default', assert => { + visit('/t/internationalization-localization'); + click('.toggle-admin-menu'); + click('.topic-admin-status-update button'); + + andThen(() => { + assert.equal(selectKit('.select-kit.timer-type').header.name(), 'Auto-Close Topic'); + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Select a timeframe'); + }); + + click('#private-topic-timer'); + + andThen(() => { + assert.equal(selectKit('.select-kit.timer-type').header.name(), 'Remind Me'); + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Select a timeframe'); + }); +}); + +QUnit.test('autoclose - specific time', assert => { + visit('/t/internationalization-localization'); + click('.toggle-admin-menu'); + click('.topic-admin-status-update button'); + expandSelectKit('.future-date-input-selector'); + selectKitSelectRow('later_today', { selector: '.future-date-input-selector' }); + + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Later today'); + const regex = /will automatically close in/g; + const html = find('.future-date-input .topic-status-info').html().trim(); + assert.ok(regex.test(html)); + }); +}); + +QUnit.test('autoclose', assert => { + visit('/t/internationalization-localization'); + click('.toggle-admin-menu'); + click('.topic-admin-status-update button'); + expandSelectKit('.future-date-input-selector'); + + selectKitSelectRow('later_today', { selector: '.future-date-input-selector' }); + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Later today'); + const regex = /will automatically close in/g; + const html = find('.future-date-input .topic-status-info').html().trim(); + assert.ok(regex.test(html)); + }); + + expandSelectKit('.future-date-input-selector'); + selectKitSelectRow('pick_date_and_time', { selector: '.future-date-input-selector' }); + fillIn('.future-date-input .date-picker', '2099-11-24'); + + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Pick date and time'); + const regex = /will automatically close in/g; + const html = find('.future-date-input .topic-status-info').html().trim(); + assert.ok(regex.test(html)); + }); + + expandSelectKit('.future-date-input-selector'); + selectKitSelectRow('set_based_on_last_post', { selector: '.future-date-input-selector' }); + fillIn('.future-date-input input[type=number]', '2'); + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Close based on last post'); + const regex = /This topic will close.*after the last reply/g; + const html = find('.future-date-input .topic-status-info').html().trim(); + assert.ok(regex.test(html)); + }); +}); + +QUnit.test('close temporarily', assert => { + visit('/t/internationalization-localization'); + click('.toggle-admin-menu'); + click('.topic-admin-status-update button'); + + expandSelectKit('.select-kit.timer-type'); + selectKitSelectRow('open', { selector: '.select-kit.timer-type' }); + + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Select a timeframe'); + }); + + expandSelectKit('.future-date-input-selector'); + selectKitSelectRow('tomorrow', { selector: '.future-date-input-selector' }); + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Tomorrow'); + const regex = /will automatically open in/g; + const html = find('.future-date-input .topic-status-info').html().trim(); + assert.ok(regex.test(html)); + }); + + expandSelectKit('.future-date-input-selector'); + selectKitSelectRow('pick_date_and_time', { selector: '.future-date-input-selector' }); + fillIn('.future-date-input .date-picker', '2099-11-24'); + + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Pick date and time'); + const regex = /will automatically open in/g; + const html = find('.future-date-input .topic-status-info').html().trim(); + assert.ok(regex.test(html)); + }); +}); + +QUnit.test('schedule', assert => { + visit('/t/internationalization-localization'); + click('.toggle-admin-menu'); + click('.topic-admin-status-update button'); + + expandSelectKit('.select-kit.timer-type'); + selectKitSelectRow('publish_to_category', { selector: '.select-kit.timer-type' }); + + andThen(() => { + assert.equal(selectKit('.modal-body .category-chooser').header.name(), 'uncategorized'); + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Select a timeframe'); + }); + + expandSelectKit('.modal-body .category-chooser'); + selectKitSelectRow('7', { selector: '.modal-body .category-chooser' }); + + expandSelectKit('.future-date-input-selector'); + selectKitSelectRow('next_week', { selector: '.future-date-input-selector' }); + + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Next week'); + const regex = /will be published to #dev/g; + const text = find('.future-date-input .topic-status-info').text().trim(); + assert.ok(regex.test(text)); + }); +}); + +QUnit.test('auto delete', assert => { + visit('/t/internationalization-localization'); + click('.toggle-admin-menu'); + click('.topic-admin-status-update button'); + + expandSelectKit('.select-kit.timer-type'); + selectKitSelectRow('delete', { selector: '.select-kit.timer-type' }); + + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Select a timeframe'); + }); + + expandSelectKit('.future-date-input-selector'); + selectKitSelectRow('next_month', { selector: '.future-date-input-selector' }); + andThen(() => { + assert.equal(selectKit('.future-date-input-selector').header.name(), 'Next month'); + const regex = /will be automatically deleted/g; + const html = find('.future-date-input .topic-status-info').html().trim(); + assert.ok(regex.test(html)); + }); +});