FIX: Don't show the Later This Week option in date pickers on Sundays

This commit is contained in:
Andrei Prigorshnev 2021-07-24 18:34:38 +04:00 committed by Alan Guo Xiang Tan
parent ed9e63b00e
commit 814781780d
2 changed files with 29 additions and 1 deletions

View File

@ -209,6 +209,34 @@ discourseModule(
},
});
componentTest("doesn't show 'Later This Week' on Sundays", {
/* We need this test to avoid regressions.
We tend to write such conditions and think that
they mean the beginning of business week
(Monday, Tuesday and Wednesday in this specific case):
if (date.day < 3) {
...
}
In fact, Sunday will pass this check too, because
in moment.js 0 stands for Sunday. */
template: hbs`{{future-date-input-selector}}`,
beforeEach() {
const timezone = moment.tz.guess();
this.clock = fakeTime("2100-04-25 18:00:00", timezone, true); // Sunday evening
},
async test(assert) {
await this.subject.expand();
const options = getOptions();
const laterThisWeek = I18n.t("topic.auto_update_input.later_this_week");
assert.not(options.includes(laterThisWeek));
},
});
componentTest("doesn't show 'Next Month' on the last day of the month", {
template: hbs`{{future-date-input-selector}}`,

View File

@ -40,7 +40,7 @@ export const TIMEFRAMES = [
buildTimeframe({
id: "later_this_week",
format: "ddd, h a",
enabled: (opts) => !opts.canScheduleToday && opts.day < 4,
enabled: (opts) => !opts.canScheduleToday && opts.day > 0 && opts.day < 4,
when: (time, timeOfDay) => time.add(2, "day").hour(timeOfDay).minute(0),
}),
buildTimeframe({