DEV: add test for wizard last step and some minor optimizations (#17752)
This commit is contained in:
parent
862007fb18
commit
d3e8442937
|
@ -1,5 +1,11 @@
|
||||||
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { click, currentRouteName, fillIn, visit } from "@ember/test-helpers";
|
import {
|
||||||
|
click,
|
||||||
|
currentRouteName,
|
||||||
|
currentURL,
|
||||||
|
fillIn,
|
||||||
|
visit,
|
||||||
|
} from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
|
||||||
acceptance("Wizard", function (needs) {
|
acceptance("Wizard", function (needs) {
|
||||||
|
@ -54,7 +60,7 @@ acceptance("Wizard", function (needs) {
|
||||||
|
|
||||||
await click(".wizard-container__button.next");
|
await click(".wizard-container__button.next");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
exists(".dropdown-field.dropdown-snack"),
|
exists(".wizard-container__text-input#company_name"),
|
||||||
"went to the next step"
|
"went to the next step"
|
||||||
);
|
);
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
@ -67,14 +73,38 @@ acceptance("Wizard", function (needs) {
|
||||||
);
|
);
|
||||||
assert.ok(exists(".wizard-container__link.back"), "shows the back button");
|
assert.ok(exists(".wizard-container__link.back"), "shows the back button");
|
||||||
assert.ok(!exists(".wizard-container__step-title"));
|
assert.ok(!exists(".wizard-container__step-title"));
|
||||||
|
assert.ok(
|
||||||
|
!exists(".wizard-container__button.next"),
|
||||||
|
"does not show next button"
|
||||||
|
);
|
||||||
assert.ok(
|
assert.ok(
|
||||||
!exists(".wizard-container__button.finish"),
|
!exists(".wizard-container__button.finish"),
|
||||||
"cannot finish on last step"
|
"cannot finish on last step"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".wizard-container__link.back");
|
await click(".wizard-container__link.back");
|
||||||
assert.ok(exists(".wizard-container__step-title"));
|
assert.ok(exists(".wizard-container__step-title"), "shows the step title");
|
||||||
assert.ok(exists(".wizard-container__button.next"));
|
assert.ok(
|
||||||
assert.ok(!exists(".wizard-prev"));
|
exists(".wizard-container__button.next"),
|
||||||
|
"shows the next button"
|
||||||
|
);
|
||||||
|
await click(".wizard-container__button.next");
|
||||||
|
|
||||||
|
// server validation fail
|
||||||
|
await fillIn("input#company_name", "Server Fail");
|
||||||
|
await click(".wizard-container__button.jump-in");
|
||||||
|
assert.ok(
|
||||||
|
exists(".invalid #company_name"),
|
||||||
|
"highlights the field with error"
|
||||||
|
);
|
||||||
|
assert.ok(exists(".wizard-container__field .error"), "shows the error");
|
||||||
|
|
||||||
|
await fillIn("input#company_name", "Foo Bar");
|
||||||
|
await click(".wizard-container__button.jump-in");
|
||||||
|
assert.strictEqual(
|
||||||
|
currentURL(),
|
||||||
|
"/latest",
|
||||||
|
"it should transition to the homepage"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,10 +5,12 @@ import getUrl from "discourse-common/lib/get-url";
|
||||||
import { htmlSafe } from "@ember/template";
|
import { htmlSafe } from "@ember/template";
|
||||||
import { schedule } from "@ember/runloop";
|
import { schedule } from "@ember/runloop";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
const alreadyWarned = {};
|
const alreadyWarned = {};
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
|
router: service(),
|
||||||
classNameBindings: [":wizard-container__step", "stepClass"],
|
classNameBindings: [":wizard-container__step", "stepClass"],
|
||||||
saving: null,
|
saving: null,
|
||||||
|
|
||||||
|
@ -133,7 +135,7 @@ export default Component.extend({
|
||||||
|
|
||||||
@action
|
@action
|
||||||
quit() {
|
quit() {
|
||||||
document.location = getUrl("/");
|
this.router.transitionTo("discovery.latest");
|
||||||
},
|
},
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
@ -146,7 +148,7 @@ export default Component.extend({
|
||||||
|
|
||||||
step
|
step
|
||||||
.save()
|
.save()
|
||||||
.then(() => this.send("quit"))
|
.then((response) => this.goNext(response))
|
||||||
.finally(() => this.set("saving", false));
|
.finally(() => this.set("saving", false));
|
||||||
} else {
|
} else {
|
||||||
this.autoFocus();
|
this.autoFocus();
|
||||||
|
|
|
@ -12,8 +12,10 @@ export default Controller.extend({
|
||||||
|
|
||||||
if (response?.refresh_required) {
|
if (response?.refresh_required) {
|
||||||
document.location = getUrl(`/wizard/steps/${next}`);
|
document.location = getUrl(`/wizard/steps/${next}`);
|
||||||
} else if (response?.success) {
|
} else if (response?.success && next) {
|
||||||
this.transitionToRoute("wizard.step", next);
|
this.transitionToRoute("wizard.step", next);
|
||||||
|
} else if (response?.success) {
|
||||||
|
this.transitionToRoute("discovery.latest");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ export default function (helpers) {
|
||||||
id: "styling",
|
id: "styling",
|
||||||
title: "Second step",
|
title: "Second step",
|
||||||
index: 1,
|
index: 1,
|
||||||
fields: [{ id: "some-title", type: "text" }],
|
fields: [{ id: "some_title", type: "text" }],
|
||||||
previous: "hello-world",
|
previous: "hello-world",
|
||||||
next: "corporate",
|
next: "corporate",
|
||||||
},
|
},
|
||||||
|
@ -34,9 +34,8 @@ export default function (helpers) {
|
||||||
id: "corporate",
|
id: "corporate",
|
||||||
index: 2,
|
index: 2,
|
||||||
fields: [
|
fields: [
|
||||||
{ id: "snack", type: "dropdown", required: true },
|
{ id: "company_name", type: "text", required: true },
|
||||||
{ id: "theme-preview", type: "component" },
|
{ id: "theme_preview", type: "component" },
|
||||||
{ id: "an-image", type: "image" },
|
|
||||||
],
|
],
|
||||||
previous: "styling",
|
previous: "styling",
|
||||||
},
|
},
|
||||||
|
@ -52,6 +51,12 @@ export default function (helpers) {
|
||||||
return response(422, {
|
return response(422, {
|
||||||
errors: [{ field: "full_name", description: "Invalid name" }],
|
errors: [{ field: "full_name", description: "Invalid name" }],
|
||||||
});
|
});
|
||||||
|
} else if (body.fields.company_name === "Server Fail") {
|
||||||
|
return response(422, {
|
||||||
|
errors: [
|
||||||
|
{ field: "company_name", description: "Invalid company name" },
|
||||||
|
],
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return response(200, { success: true });
|
return response(200, { success: true });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue