mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 12:31:06 +08:00
UX: rework date time input range (#9524)
This commit is contained in:
@ -3,40 +3,22 @@ import componentTest from "helpers/component-test";
|
||||
moduleForComponent("date-time-input-range", { integration: true });
|
||||
|
||||
function fromDateInput() {
|
||||
return find(".from .date-picker");
|
||||
return find(".from.d-date-time-input .date-picker")[0];
|
||||
}
|
||||
|
||||
function fromHoursInput() {
|
||||
return find(".from .field.hours");
|
||||
}
|
||||
|
||||
function fromMinutesInput() {
|
||||
return find(".from .field.minutes");
|
||||
function fromTimeInput() {
|
||||
return find(".from.d-date-time-input .d-time-input .combo-box-header")[0];
|
||||
}
|
||||
|
||||
function toDateInput() {
|
||||
return find(".to .date-picker");
|
||||
return find(".to.d-date-time-input .date-picker")[0];
|
||||
}
|
||||
|
||||
function toHoursInput() {
|
||||
return find(".to .field.hours");
|
||||
function toTimeInput() {
|
||||
return find(".to.d-date-time-input .d-time-input .combo-box-header")[0];
|
||||
}
|
||||
|
||||
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);
|
||||
const DEFAULT_DATE_TIME = moment("2019-01-29 14:45");
|
||||
|
||||
componentTest("default", {
|
||||
template: `{{date-time-input-range from=from to=to}}`,
|
||||
@ -46,60 +28,9 @@ componentTest("default", {
|
||||
},
|
||||
|
||||
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 button.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"), "it begins with no error");
|
||||
|
||||
await click(".panels button.to-panel");
|
||||
await click(toDateInput());
|
||||
await pika(2019, 0, 1);
|
||||
|
||||
assert.ok(exists(".error"), "it shows an error");
|
||||
assert.deepEqual(this.to, DEFAULT_DATE_TIME, "it didnt trigger a mutation");
|
||||
|
||||
await click(".panels button.to-panel");
|
||||
await click(toDateInput());
|
||||
await pika(2019, 0, 30);
|
||||
|
||||
assert.notOk(exists(".error"), "it removes the error");
|
||||
assert.deepEqual(
|
||||
this.to,
|
||||
new Date(2019, 0, 30, 14, 45),
|
||||
"it has changed the date"
|
||||
);
|
||||
assert.equal(fromDateInput().value, "January 29, 2019");
|
||||
assert.equal(fromTimeInput().dataset.name, "14:45");
|
||||
assert.equal(toDateInput().value, "");
|
||||
assert.equal(toTimeInput().dataset.name, "--:--");
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user