FIX: Don't show the Tis Weekend option in date pickers on Sundays

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

View File

@ -168,6 +168,41 @@ discourseModule(
},
});
componentTest("doesn't show 'This Weekend' on Sundays", {
/*
We need this test to avoid regressions.
We tend to write such conditions and think that
they mean the beginning of work 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
includeWeekend=true
}}
`,
beforeEach() {
const timezone = moment.tz.guess();
this.clock = fakeTime("2100-04-25 18:00:00", timezone, true); // Sunday
},
async test(assert) {
await this.subject.expand();
const options = getOptions();
const thisWeekend = I18n.t("topic.auto_update_input.this_weekend");
assert.not(options.includes(thisWeekend));
},
});
componentTest(
"shows 'Later This Week' instead of 'Later Today' at the end of the day",
{

View File

@ -46,7 +46,7 @@ export const TIMEFRAMES = [
buildTimeframe({
id: "this_weekend",
format: "ddd, h a",
enabled: (opts) => opts.day < 5 && opts.includeWeekend,
enabled: (opts) => opts.day > 0 && opts.day < 5 && opts.includeWeekend,
when: (time, timeOfDay) => time.day(6).hour(timeOfDay).minute(0),
icon: "bed",
}),