2019-07-18 11:29:41 -04:00
|
|
|
import componentTest from "helpers/component-test";
|
|
|
|
|
|
|
|
moduleForComponent("date-time-input", { integration: true });
|
|
|
|
|
|
|
|
function dateInput() {
|
2020-04-22 16:17:53 -04:00
|
|
|
return find(".date-picker")[0];
|
2019-07-18 11:29:41 -04:00
|
|
|
}
|
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
function timeInput() {
|
|
|
|
return find(".d-time-input .combo-box-header")[0];
|
2019-07-18 11:29:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setDate(date) {
|
|
|
|
this.set("date", date);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function pika(year, month, day) {
|
|
|
|
await click(
|
|
|
|
`.pika-button.pika-day[data-pika-year="${year}"][data-pika-month="${month}"][data-pika-day="${day}"]`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
const DEFAULT_DATE_TIME = moment("2019-01-29 14:45");
|
2019-07-18 11:29:41 -04:00
|
|
|
|
|
|
|
componentTest("default", {
|
|
|
|
template: `{{date-time-input date=date}}`,
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
this.setProperties({ date: DEFAULT_DATE_TIME });
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2020-04-22 16:17:53 -04:00
|
|
|
assert.equal(dateInput().value, "January 29, 2019");
|
|
|
|
assert.equal(timeInput().dataset.name, "14:45");
|
2019-07-18 11:29:41 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
componentTest("prevents mutations", {
|
|
|
|
template: `{{date-time-input date=date}}`,
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
this.setProperties({ date: DEFAULT_DATE_TIME });
|
|
|
|
},
|
|
|
|
|
|
|
|
async test(assert) {
|
|
|
|
await click(dateInput());
|
|
|
|
await pika(2019, 0, 2);
|
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
assert.ok(this.date.isSame(DEFAULT_DATE_TIME));
|
2019-07-18 11:29:41 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
componentTest("allows mutations through actions", {
|
|
|
|
template: `{{date-time-input date=date onChange=onChange}}`,
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
this.setProperties({ date: DEFAULT_DATE_TIME });
|
|
|
|
this.set("onChange", setDate);
|
|
|
|
},
|
|
|
|
|
|
|
|
async test(assert) {
|
|
|
|
await click(dateInput());
|
|
|
|
await pika(2019, 0, 2);
|
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
assert.ok(this.date.isSame(moment("2019-01-02 14:45")));
|
2019-07-18 11:29:41 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
componentTest("can hide time", {
|
|
|
|
template: `{{date-time-input date=date showTime=false}}`,
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
this.setProperties({ date: DEFAULT_DATE_TIME });
|
|
|
|
},
|
|
|
|
|
|
|
|
async test(assert) {
|
2020-04-22 16:17:53 -04:00
|
|
|
assert.notOk(exists(timeInput()));
|
2019-07-18 11:29:41 -04:00
|
|
|
}
|
|
|
|
});
|