This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/integration/components/date-time-input-test.js
Joffrey JAFFEUX e2e936715e
UX: uses native date picker when possible (eg: not safari) (#12668)
Note that this is only applied on date-input and not the old date-picker for now.

This commit is also slightly modifying admin report dates form to ensure the native picker is correctly used, as a result: it doesn’t auto refresh on date change and fixes a border bug.
2021-04-22 10:34:23 +02:00

83 lines
1.9 KiB
JavaScript

import componentTest, {
setupRenderingTest,
} from "discourse/tests/helpers/component-test";
import {
discourseModule,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import hbs from "htmlbars-inline-precompile";
function dateInput() {
return query(".date-picker");
}
function timeInput() {
return query(".d-time-input .combo-box-header");
}
function setDate(date) {
this.set("date", date);
}
const DEFAULT_DATE_TIME = moment("2019-01-29 14:45");
discourseModule("Integration | Component | date-time-input", function (hooks) {
setupRenderingTest(hooks);
componentTest("default", {
template: hbs`{{date-time-input date=date}}`,
beforeEach() {
this.setProperties({ date: DEFAULT_DATE_TIME });
},
test(assert) {
assert.equal(dateInput().value, "2019-01-29");
assert.equal(timeInput().dataset.name, "14:45");
},
});
componentTest("prevents mutations", {
template: hbs`{{date-time-input date=date}}`,
beforeEach() {
this.setProperties({ date: DEFAULT_DATE_TIME });
},
async test(assert) {
dateInput().value = "2019-01-02";
assert.ok(this.date.isSame(DEFAULT_DATE_TIME));
},
});
componentTest("allows mutations through actions", {
template: hbs`{{date-time-input date=date onChange=onChange}}`,
beforeEach() {
this.setProperties({ date: DEFAULT_DATE_TIME });
this.set("onChange", setDate);
},
async test(assert) {
dateInput().value = "2019-01-02";
dateInput().dispatchEvent(new Event("change"));
assert.ok(this.date.isSame(moment("2019-01-02 14:45")));
},
});
componentTest("can hide time", {
template: hbs`{{date-time-input date=date showTime=false}}`,
beforeEach() {
this.setProperties({ date: DEFAULT_DATE_TIME });
},
async test(assert) {
assert.notOk(exists(timeInput()));
},
});
});