2020-11-12 16:40:28 -05:00
|
|
|
|
import { currentRouteName, visit } from "@ember/test-helpers";
|
2020-10-06 12:54:05 -04:00
|
|
|
|
import { module, test } from "qunit";
|
2019-10-30 09:48:24 -04:00
|
|
|
|
import { run } from "@ember/runloop";
|
2016-09-13 15:14:17 -04:00
|
|
|
|
import startApp from "wizard/test/helpers/start-app";
|
|
|
|
|
|
|
|
|
|
var wizard;
|
2020-10-06 12:54:05 -04:00
|
|
|
|
module("Acceptance: wizard", {
|
2016-09-13 15:14:17 -04:00
|
|
|
|
beforeEach() {
|
|
|
|
|
wizard = startApp();
|
|
|
|
|
},
|
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
|
afterEach() {
|
2019-10-30 09:48:24 -04:00
|
|
|
|
run(wizard, "destroy");
|
2016-09-13 15:14:17 -04:00
|
|
|
|
},
|
|
|
|
|
});
|
2016-08-24 14:35:07 -04:00
|
|
|
|
|
2020-10-27 14:54:38 -04:00
|
|
|
|
function exists(selector) {
|
|
|
|
|
return document.querySelector(selector) !== null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
|
test("Wizard starts", async function (assert) {
|
2018-07-29 16:51:32 -04:00
|
|
|
|
await visit("/");
|
|
|
|
|
assert.ok(exists(".wizard-column-contents"));
|
2020-11-12 16:40:28 -05:00
|
|
|
|
assert.equal(currentRouteName(), "step");
|
2016-08-25 13:14:56 -04:00
|
|
|
|
});
|
|
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
|
test("Going back and forth in steps", async function (assert) {
|
2018-07-29 16:51:32 -04: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"
|
|
|
|
|
);
|
2018-11-15 14:44:19 -05:00
|
|
|
|
assert.ok(!exists(".wizard-btn.finish"), "can’t finish on first step");
|
2018-07-29 16:51:32 -04: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-25 13:14:56 -04:00
|
|
|
|
|
|
|
|
|
// invalid data
|
2018-07-29 16:51:32 -04:00
|
|
|
|
await click(".wizard-btn.next");
|
|
|
|
|
assert.ok(exists(".invalid .field-full-name"));
|
2016-08-25 13:14:56 -04:00
|
|
|
|
|
|
|
|
|
// server validation fail
|
2018-07-29 16:51:32 -04: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-25 13:14:56 -04:00
|
|
|
|
|
|
|
|
|
// server validation ok
|
2018-07-29 16:51:32 -04: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"));
|
2018-11-15 14:44:19 -05:00
|
|
|
|
assert.ok(
|
|
|
|
|
exists(".wizard-btn.finish"),
|
|
|
|
|
"shows finish on an intermediate step"
|
|
|
|
|
);
|
2016-09-02 11:42:14 -04:00
|
|
|
|
|
2018-11-15 14:44:19 -05:00
|
|
|
|
await click(".wizard-btn.next");
|
2018-07-29 16:51:32 -04: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");
|
2018-11-15 14:44:19 -05:00
|
|
|
|
assert.ok(!exists(".wizard-step-title"));
|
|
|
|
|
assert.ok(!exists(".wizard-btn.finish"), "can’t finish on last step");
|
2016-08-25 13:14:56 -04:00
|
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
|
await click(".action-link.back");
|
|
|
|
|
assert.ok(exists(".wizard-step-title"));
|
|
|
|
|
assert.ok(exists(".wizard-btn.next"));
|
|
|
|
|
assert.ok(!exists(".wizard-prev"));
|
2016-08-24 14:35:07 -04:00
|
|
|
|
});
|