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-input-test.js
Robin Ward 71d37953d5 REFACTOR: Import QUnit and related helpers rather than globals
We used many global functions to handle tests when they should be
imported like other libraries in our application. This also gets us
closer to the way Ember CLI prefers our tests to be laid out.
2020-10-07 11:50:49 -04:00

67 lines
1.4 KiB
JavaScript

import { moduleForComponent } from "ember-qunit";
import componentTest from "discourse/tests/helpers/component-test";
moduleForComponent("date-input", { integration: true });
function dateInput() {
return find(".date-picker");
}
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}"]`
);
}
function noop() {}
const DEFAULT_DATE = moment("2019-01-29");
componentTest("default", {
template: `{{date-input date=date}}`,
beforeEach() {
this.setProperties({ date: DEFAULT_DATE });
},
test(assert) {
assert.equal(dateInput().val(), "January 29, 2019");
},
});
componentTest("prevents mutations", {
template: `{{date-input date=date onChange=onChange}}`,
beforeEach() {
this.setProperties({ date: DEFAULT_DATE });
this.set("onChange", noop);
},
async test(assert) {
await click(dateInput());
await pika(2019, 0, 2);
assert.ok(this.date.isSame(DEFAULT_DATE));
},
});
componentTest("allows mutations through actions", {
template: `{{date-input date=date onChange=onChange}}`,
beforeEach() {
this.setProperties({ date: DEFAULT_DATE });
this.set("onChange", setDate);
},
async test(assert) {
await click(dateInput());
await pika(2019, 0, 2);
assert.ok(this.date.isSame(moment("2019-01-02")));
},
});