mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
FEATURE: new date/time components (#7898)
This commit is contained in:
102
test/javascripts/components/date-time-input-range-test.js.es6
Normal file
102
test/javascripts/components/date-time-input-range-test.js.es6
Normal file
@ -0,0 +1,102 @@
|
||||
import componentTest from "helpers/component-test";
|
||||
|
||||
moduleForComponent("date-time-input-range", { integration: true });
|
||||
|
||||
function fromDateInput() {
|
||||
return find(".from .date-picker");
|
||||
}
|
||||
|
||||
function fromHoursInput() {
|
||||
return find(".from .field.hours");
|
||||
}
|
||||
|
||||
function fromMinutesInput() {
|
||||
return find(".from .field.minutes");
|
||||
}
|
||||
|
||||
function toDateInput() {
|
||||
return find(".to .date-picker");
|
||||
}
|
||||
|
||||
function toHoursInput() {
|
||||
return find(".to .field.hours");
|
||||
}
|
||||
|
||||
function toMinutesInput() {
|
||||
return find(".to .field.minutes");
|
||||
}
|
||||
|
||||
function setDates(dates) {
|
||||
this.setProperties(dates);
|
||||
}
|
||||
|
||||
async function pika(year, month, day) {
|
||||
await click(
|
||||
`.pika-button.pika-day[data-pika-year="${year}"][data-pika-month="${month}"][data-pika-day="${day}"]`
|
||||
);
|
||||
}
|
||||
|
||||
const DEFAULT_DATE_TIME = new Date(2019, 0, 29, 14, 45);
|
||||
|
||||
componentTest("default", {
|
||||
template: `{{date-time-input-range from=date to=to}}`,
|
||||
|
||||
beforeEach() {
|
||||
this.setProperties({ date: DEFAULT_DATE_TIME, to: null });
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(fromDateInput().val(), "January 29, 2019");
|
||||
assert.equal(fromHoursInput().val(), "14");
|
||||
assert.equal(fromMinutesInput().val(), "45");
|
||||
|
||||
assert.equal(toDateInput().val(), "");
|
||||
assert.equal(toHoursInput().val(), "");
|
||||
assert.equal(toMinutesInput().val(), "");
|
||||
}
|
||||
});
|
||||
|
||||
componentTest("can switch panels", {
|
||||
template: `{{date-time-input-range}}`,
|
||||
|
||||
async test(assert) {
|
||||
assert.ok(exists(".panel.from.visible"));
|
||||
assert.notOk(exists(".panel.to.visible"));
|
||||
|
||||
await click(".panels .to-panel");
|
||||
|
||||
assert.ok(exists(".panel.to.visible"));
|
||||
assert.notOk(exists(".panel.from.visible"));
|
||||
}
|
||||
});
|
||||
|
||||
componentTest("prevents toDate to be before fromDate", {
|
||||
template: `{{date-time-input-range from=from to=to onChange=onChange}}`,
|
||||
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
from: DEFAULT_DATE_TIME,
|
||||
to: DEFAULT_DATE_TIME,
|
||||
onChange: setDates
|
||||
});
|
||||
},
|
||||
|
||||
async test(assert) {
|
||||
assert.notOk(exists(".error"));
|
||||
|
||||
await click(toDateInput());
|
||||
await pika(2019, 0, 1);
|
||||
|
||||
assert.ok(exists(".error"));
|
||||
assert.ok(
|
||||
this.to.getTime() === DEFAULT_DATE_TIME.getTime(),
|
||||
"it didnt trigger a mutation"
|
||||
);
|
||||
|
||||
await click(toDateInput());
|
||||
await pika(2019, 0, 30);
|
||||
|
||||
assert.notOk(exists(".error"));
|
||||
assert.ok(this.to.getTime() === new Date(2019, 0, 30, 14, 45).getTime());
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user