0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-12-04 22:31:09 +01:00
discourse-custom-wizard/test/javascripts/acceptance/wizard-test.js

197 Zeilen
5,7 KiB
JavaScript

2022-07-27 16:30:45 +02:00
import { visit } from "@ember/test-helpers";
2022-07-27 12:47:50 +02:00
import { test } from "qunit";
import {
acceptance,
count,
exists,
2022-07-27 16:30:45 +02:00
query,
2022-07-27 12:47:50 +02:00
} from "discourse/tests/helpers/qunit-helpers";
import {
wizard,
wizardCompleted,
2023-01-26 11:26:24 +01:00
wizardGuest,
2022-07-27 12:47:50 +02:00
wizardNoUser,
wizardNotPermitted,
} from "../helpers/wizard";
2023-07-11 18:49:08 +02:00
import DiscourseURL from "discourse/lib/url";
import sinon from "sinon";
2022-07-27 12:47:50 +02:00
acceptance("Wizard | Not logged in", function (needs) {
needs.pretender((server, helper) => {
2022-07-27 16:30:45 +02:00
server.get("/w/wizard.json", () => helper.response(wizardNoUser));
2022-07-27 12:47:50 +02:00
});
test("Requires login", async function (assert) {
2022-07-27 12:47:50 +02:00
await visit("/w/wizard");
assert.ok(exists(".wizard-no-access.requires-login"));
});
test("Requires login if a step path is used", async function (assert) {
await visit("/w/wizard/steps/1");
assert.ok(exists(".wizard-no-access.requires-login"));
});
2022-07-27 12:47:50 +02:00
});
2022-07-27 15:50:49 +02:00
acceptance("Wizard | Not permitted", function (needs) {
needs.user();
needs.pretender((server, helper) => {
2022-07-27 16:36:22 +02:00
server.get("/w/wizard.json", () => helper.response(wizardNotPermitted));
2022-07-27 15:50:49 +02:00
});
2022-07-27 12:47:50 +02:00
2022-07-27 15:50:49 +02:00
test("Wizard no access not permitted", async function (assert) {
await visit("/w/wizard");
assert.ok(exists(".wizard-no-access.not-permitted"));
});
});
2022-07-27 12:47:50 +02:00
acceptance("Wizard | Completed", function (needs) {
needs.user();
needs.pretender((server, helper) => {
2022-07-27 16:30:45 +02:00
server.get("/w/wizard.json", () => helper.response(wizardCompleted));
2022-07-27 12:47:50 +02:00
});
test("Wizard no access completed", async function (assert) {
await visit("/w/wizard");
assert.ok(exists(".wizard-no-access.completed"));
});
});
2023-07-11 18:49:08 +02:00
acceptance("Wizard | Redirect", function (needs) {
needs.user({
2023-07-11 18:58:10 +02:00
redirect_to_wizard: "wizard",
2023-07-11 18:49:08 +02:00
});
needs.pretender((server, helper) => {
server.get("/w/wizard.json", () => {
return helper.response(wizard);
});
});
test("Redirect to pending Wizard", async function (assert) {
sinon.stub(DiscourseURL, "routeTo");
await visit("/latest");
assert.ok(
DiscourseURL.routeTo.calledWith("/w/wizard"),
"pending wizard routing works"
);
});
2023-09-08 08:13:52 +02:00
test("Don't redirect to pending Wizard when ingore redirect param is supplied", async function (assert) {
sinon.stub(DiscourseURL, "routeTo");
await visit("/latest?ignore_redirect=1");
assert.notOk(
DiscourseURL.routeTo.calledWith("/w/wizard"),
"pending wizard routing blocked"
);
});
2023-07-11 18:49:08 +02:00
});
2022-07-27 12:47:50 +02:00
acceptance("Wizard | Wizard", function (needs) {
needs.user();
needs.pretender((server, helper) => {
2022-07-27 16:30:45 +02:00
server.get("/w/wizard.json", () => {
2022-07-27 12:47:50 +02:00
return helper.response(wizard);
});
});
test("Starts", async function (assert) {
await visit("/w/wizard");
assert.ok(query(".wizard-column"), true);
});
2022-08-01 18:18:21 +02:00
test("Applies the wizard body class", async function (assert) {
await visit("/w/wizard");
assert.ok($("body.custom-wizard").length);
});
2022-07-27 12:47:50 +02:00
test("Applies the body background color", async function (assert) {
await visit("/w/wizard");
assert.ok($("body")[0].style.background);
});
test("Renders the wizard form", async function (assert) {
await visit("/w/wizard");
assert.ok(exists(".wizard-column-contents .wizard-step"), true);
assert.ok(exists(".wizard-footer img"), true);
});
test("Renders the first step", async function (assert) {
await visit("/w/wizard");
assert.strictEqual(
query(".wizard-step-title p").textContent.trim(),
"Text"
);
assert.strictEqual(
query(".wizard-step-description p").textContent.trim(),
"Text inputs!"
);
assert.strictEqual(
query(".wizard-step-description p").textContent.trim(),
"Text inputs!"
);
assert.strictEqual(count(".wizard-step-form .wizard-field"), 6);
assert.ok(exists(".wizard-step-footer .wizard-progress"), true);
assert.ok(exists(".wizard-step-footer .wizard-buttons"), true);
});
2022-08-01 18:18:21 +02:00
test("Removes the wizard body class when navigating away", async function (assert) {
await visit("/");
assert.strictEqual($("body.custom-wizard").length, 0);
});
2022-07-27 12:47:50 +02:00
});
2023-01-26 11:26:24 +01:00
acceptance("Wizard | Guest access", function (needs) {
needs.pretender((server, helper) => {
server.get("/w/wizard.json", () => helper.response(wizardGuest));
});
test("Does not require login", async function (assert) {
await visit("/w/wizard");
assert.ok(!exists(".wizard-no-access.requires-login"));
});
test("Starts", async function (assert) {
await visit("/w/wizard");
assert.ok(query(".wizard-column"), true);
});
test("Applies the wizard body class", async function (assert) {
await visit("/w/wizard");
assert.ok($("body.custom-wizard").length);
});
test("Applies the body background color", async function (assert) {
await visit("/w/wizard");
assert.ok($("body")[0].style.background);
});
test("Renders the wizard form", async function (assert) {
await visit("/w/wizard");
assert.ok(exists(".wizard-column-contents .wizard-step"), true);
assert.ok(exists(".wizard-footer img"), true);
});
test("Renders the first step", async function (assert) {
await visit("/w/wizard");
assert.strictEqual(
query(".wizard-step-title p").textContent.trim(),
"Text"
);
assert.strictEqual(
query(".wizard-step-description p").textContent.trim(),
"Text inputs!"
);
assert.strictEqual(
query(".wizard-step-description p").textContent.trim(),
"Text inputs!"
);
assert.strictEqual(count(".wizard-step-form .wizard-field"), 6);
assert.ok(exists(".wizard-step-footer .wizard-progress"), true);
assert.ok(exists(".wizard-step-footer .wizard-buttons"), true);
});
test("Removes the wizard body class when navigating away", async function (assert) {
await visit("/");
assert.strictEqual($("body.custom-wizard").length, 0);
});
2023-01-26 11:26:24 +01:00
});