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/time-input-test.js
Jarek Radosz 189bebb2e4
DEV: Modernize component tests (#17368)
* Use QUnit `module` instead of `discourseModule`
* Use QUnit `test` instead of `componentTest`
* Use angle-bracket syntax
* Remove jQuery usage
* Improve assertions (and actually fix some of them)
2022-07-11 12:29:44 +02:00

53 lines
1.5 KiB
JavaScript

import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import selectKit from "discourse/tests/helpers/select-kit-helper";
function setTime(time) {
this.setProperties(time);
}
module("Integration | Component | time-input", function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.set("subject", selectKit());
});
test("default", async function (assert) {
this.setProperties({ hours: "14", minutes: "58" });
await render(
hbs`<TimeInput @hours={{this.hours}} @minutes={{this.minutes}} />`
);
assert.strictEqual(this.subject.header().name(), "14:58");
});
test("prevents mutations", async function (assert) {
this.setProperties({ hours: "14", minutes: "58" });
await render(
hbs`<TimeInput @hours={{this.hours}} @minutes={{this.minutes}} />`
);
await this.subject.expand();
await this.subject.selectRowByIndex(3);
assert.strictEqual(this.subject.header().name(), "14:58");
});
test("allows mutations through actions", async function (assert) {
this.setProperties({ hours: "14", minutes: "58" });
this.set("onChange", setTime);
await render(
hbs`<TimeInput @hours={{this.hours}} @minutes={{this.minutes}} @onChange={{this.onChange}} />`
);
await this.subject.expand();
await this.subject.selectRowByIndex(3);
assert.strictEqual(this.subject.header().name(), "00:45");
});
});