discourse/app/assets/javascripts/wizard/test/acceptance/wizard-test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.5 KiB
JavaScript
Raw Normal View History

import { currentRouteName, visit } from "@ember/test-helpers";
import { module, test } from "qunit";
import { run } from "@ember/runloop";
2016-09-14 03:14:17 +08:00
import startApp from "wizard/test/helpers/start-app";
2021-01-27 19:39:20 +08:00
let wizard;
module("Acceptance: wizard", {
2016-09-14 03:14:17 +08:00
beforeEach() {
wizard = startApp();
},
2017-06-15 01:57:58 +08:00
afterEach() {
run(wizard, "destroy");
2016-09-14 03:14:17 +08:00
},
});
function exists(selector) {
return document.querySelector(selector) !== null;
}
test("Wizard starts", async function (assert) {
2018-07-30 04:51:32 +08:00
await visit("/");
assert.ok(exists(".wizard-column-contents"));
assert.strictEqual(currentRouteName(), "step");
2016-08-26 01:14:56 +08:00
});
test("Going back and forth in steps", async function (assert) {
2018-07-30 04:51:32 +08:00
await visit("/steps/hello-world");
assert.ok(exists(".wizard-step"));
assert.ok(
exists(".wizard-step-hello-world"),
"it adds a class for the step id"
);
assert.ok(!exists(".wizard-btn.finish"), "cant finish on first step");
2018-07-30 04:51:32 +08:00
assert.ok(exists(".wizard-progress"));
assert.ok(exists(".wizard-step-title"));
assert.ok(exists(".wizard-step-description"));
assert.ok(
!exists(".invalid .field-full-name"),
"don't show it as invalid until the user does something"
);
assert.ok(exists(".wizard-field .field-description"));
assert.ok(!exists(".wizard-btn.back"));
assert.ok(!exists(".wizard-field .field-error-description"));
2016-08-26 01:14:56 +08:00
// invalid data
2018-07-30 04:51:32 +08:00
await click(".wizard-btn.next");
assert.ok(exists(".invalid .field-full-name"));
2016-08-26 01:14:56 +08:00
// server validation fail
2018-07-30 04:51:32 +08:00
await fillIn("input.field-full-name", "Server Fail");
await click(".wizard-btn.next");
assert.ok(exists(".invalid .field-full-name"));
assert.ok(exists(".wizard-field .field-error-description"));
2016-08-26 01:14:56 +08:00
// server validation ok
2018-07-30 04:51:32 +08:00
await fillIn("input.field-full-name", "Evil Trout");
await click(".wizard-btn.next");
assert.ok(!exists(".wizard-field .field-error-description"));
assert.ok(!exists(".wizard-step-description"));
assert.ok(
exists(".wizard-btn.finish"),
"shows finish on an intermediate step"
);
2016-09-02 23:42:14 +08:00
await click(".wizard-btn.next");
2018-07-30 04:51:32 +08:00
assert.ok(exists(".select-kit.field-snack"), "went to the next step");
assert.ok(exists(".preview-area"), "renders the component field");
assert.ok(exists(".wizard-btn.done"), "last step shows a done button");
assert.ok(exists(".action-link.back"), "shows the back button");
assert.ok(!exists(".wizard-step-title"));
assert.ok(!exists(".wizard-btn.finish"), "cant finish on last step");
2016-08-26 01:14:56 +08:00
2018-07-30 04:51:32 +08:00
await click(".action-link.back");
assert.ok(exists(".wizard-step-title"));
assert.ok(exists(".wizard-btn.next"));
assert.ok(!exists(".wizard-prev"));
});