mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 15:25:10 +08:00
103 lines
2.3 KiB
JavaScript
103 lines
2.3 KiB
JavaScript
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());
|
|
}
|
|
});
|