0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-14 22:02:53 +01:00
discourse-custom-wizard/test/javascripts/acceptance/admin-wizards-standard-subscription-test.js

267 Zeilen
9 KiB
JavaScript

2022-12-20 17:22:24 +01:00
import {
acceptance,
2023-10-06 17:37:24 +02:00
exists,
2022-12-20 17:22:24 +01:00
query,
2024-01-26 16:18:11 +01:00
queryAll,
2022-12-20 17:22:24 +01:00
visible,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
2024-01-26 16:18:11 +01:00
import { click, currentURL, fillIn, visit } from "@ember/test-helpers";
2022-12-20 17:22:24 +01:00
import selectKit from "discourse/tests/helpers/select-kit-helper";
import {
getAdminTestingWizard,
getCreatedWizard,
getCustomFields,
getStandardAdminWizard,
getSuppliersAuthorized,
2023-09-25 17:07:41 +02:00
getWizard,
} from "../helpers/admin-wizard";
2022-12-20 17:22:24 +01:00
2022-12-20 18:27:00 +01:00
acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
2022-12-20 17:22:24 +01:00
needs.user();
needs.settings({
custom_wizard_enabled: true,
available_locales: JSON.stringify([{ name: "English", value: "en" }]),
});
needs.pretender((server, helper) => {
server.get("/admin/wizards/wizard", () => {
return helper.response(getWizard);
2022-12-20 17:22:24 +01:00
});
server.get("/admin/wizards/custom-fields", () => {
return helper.response(getCustomFields);
2022-12-20 17:22:24 +01:00
});
2023-09-24 18:16:40 +02:00
server.get("/admin/wizards/subscription", () => {
return helper.response(getStandardAdminWizard);
2022-12-20 17:22:24 +01:00
});
server.get("/admin/wizards/api", () => {
2022-12-20 17:22:24 +01:00
return helper.response({ success: "OK" });
});
server.get("/admin/customize/user_fields", () => {
2022-12-20 17:22:24 +01:00
return helper.response({ user_fields: [] });
});
server.get("/admin/wizards/wizard/this_is_testing_wizard", () => {
return helper.response(getAdminTestingWizard);
2022-12-20 17:22:24 +01:00
});
server.put("/admin/wizards/wizard/new_wizard_for_testing", () => {
return helper.response({
success: "OK",
wizard_id: "new_wizard_for_testing",
});
});
server.get("/admin/wizards/wizard/new_wizard_for_testing", () => {
return helper.response(getCreatedWizard);
2022-12-20 17:22:24 +01:00
});
2023-09-25 16:41:01 +02:00
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliersAuthorized);
2023-09-25 16:41:01 +02:00
});
2022-12-20 17:22:24 +01:00
});
test("Displaying all tabs except API", async (assert) => {
await visit("/admin/wizards");
2024-01-26 16:18:11 +01:00
const list = queryAll(".admin-controls li");
const count = list.length;
assert.equal(count, 5, "There should be 5 admin tabs");
});
2023-10-06 17:37:24 +02:00
test("shows authorized and subscribed", async (assert) => {
await visit("/admin/wizards");
assert.notOk(
2023-11-15 17:42:53 +01:00
exists(".supplier-authorize .btn-primary:not(.update)"),
"the authorize button not shown."
);
assert.strictEqual(
query("button.wizard-subscription-badge span").innerText.trim(),
"Support"
);
});
test("creating a new wizard", async (assert) => {
2022-12-20 17:22:24 +01:00
await visit("/admin/wizards/wizard");
await click(".admin-wizard-controls button");
2022-12-20 17:22:24 +01:00
assert.ok(
query(".message-content").innerText.includes(
"You're creating a new wizard"
),
"it displays wizard creation message"
);
// ("Step 1: Inserting a title")
2022-12-20 17:22:24 +01:00
const wizardTitle = "New wizard for testing";
await fillIn(".wizard-header input", wizardTitle);
assert.equal(
$(".wizard-header input").val(),
wizardTitle,
"The title input is inserted"
);
2024-01-26 16:18:11 +01:00
const wizardLink = queryAll("div.wizard-url a");
2022-12-20 17:22:24 +01:00
assert.equal(wizardLink.length, 1, "Wizard link was created");
assert.equal(
2024-01-26 16:18:11 +01:00
queryAll(".wizard-subscription-container a:contains('Subscribed')")
.length,
2022-12-20 17:22:24 +01:00
1,
"Wizard subscription features are accesible"
);
2024-01-26 16:18:11 +01:00
const subsFeature = queryAll(
2022-12-20 18:27:00 +01:00
".wizard-subscription-container .subscription-settings .setting-value input"
);
await click(
".wizard-subscription-container .subscription-settings .setting-value input"
);
2022-12-20 18:27:00 +01:00
assert.ok(subsFeature.is(":checked"), "subscription feature available");
// ("Step 2: Creating a step section")
await click(".step .link-list button");
2022-12-20 17:22:24 +01:00
const stepOneText = "step_1 (step_1)";
2024-01-26 16:18:11 +01:00
const stepOneBtn = queryAll(`.step button:contains(${stepOneText})`);
2022-12-20 17:22:24 +01:00
assert.equal(stepOneBtn.length, 1, "Creating a step");
const stepTitle = "step title";
await fillIn(".wizard-custom-step input[name='title']", stepTitle);
const stepButtonText = $.trim(
$(".step div[data-id='step_1'] button").text()
);
assert.ok(
stepButtonText.includes(stepTitle),
"The step button changes according to title"
);
assert.equal(
2024-01-26 16:18:11 +01:00
queryAll(".wizard-subscription-container a:contains('Subscribed')")
.length,
2022-12-20 17:22:24 +01:00
2,
"Steps subscription features are accesible"
);
// step("Step 3: Creating a field section")
await click(".field .link-list button");
2022-12-20 17:22:24 +01:00
assert.ok(
!visible(".wizard-custom-field button.undo-changes"),
"clear button is not rendered"
);
const fieldOneText = "step_1_field_1 (step_1_field_1)";
2024-01-26 16:18:11 +01:00
const fieldOneBtn = queryAll(`.field button:contains(${fieldOneText})`);
2022-12-20 17:22:24 +01:00
assert.equal(fieldOneBtn.length, 1, "Creating a field");
const fieldTitle = "field title";
await fillIn(".wizard-custom-field input[name='label']", fieldTitle);
assert.ok(
visible(".wizard-custom-field button.undo-changes"),
"clear button is rendered after filling content"
);
let fieldButtonText = $.trim(
$(".field div[data-id='step_1_field_1'] button").text()
);
assert.ok(
fieldButtonText.includes(fieldTitle),
"The step button changes according to title"
);
await click(`.wizard-custom-field button.undo-changes`);
2022-12-20 17:22:24 +01:00
fieldButtonText = $(".field div[data-id='step_1_field_1'] button")
.text()
.trim();
assert.ok(
fieldButtonText.includes("step_1_field_1 (step_1_field_1)"),
"The field button changes to default title after clear button is clicked"
);
const fieldTypeDropdown = selectKit(
".wizard-custom-field .setting-value .select-kit"
);
await fieldTypeDropdown.expand();
await fieldTypeDropdown.selectRowByValue("text");
assert.ok(
query(".wizard-custom-field .message-content").innerText.includes(
"You're editing a field"
),
"Text tipe for field correctly selected"
);
assert.equal(
2024-01-26 16:18:11 +01:00
queryAll(".wizard-subscription-container a:contains('Subscribed')")
.length,
2022-12-20 17:22:24 +01:00
3,
"Field subscription features are accesible"
);
// ("Step 4: Creating a action section")
await click(".action .link-list button");
2022-12-20 17:22:24 +01:00
const actionOneText = "action_1 (action_1)";
2024-01-26 16:18:11 +01:00
const actionOneBtn = queryAll(`.action button:contains(${actionOneText})`);
2022-12-20 17:22:24 +01:00
assert.equal(actionOneBtn.length, 1, "Creating an action");
assert.ok(
query(
".wizard-custom-action .wizard-message .message-content"
).innerText.includes("Select an action type"),
"it displays wizard select action message"
);
const actionTypeDropdown = selectKit(
".wizard-custom-action .setting-value .select-kit"
);
await actionTypeDropdown.expand();
2024-01-26 16:18:11 +01:00
const listEnabled = queryAll(
2022-12-20 17:22:24 +01:00
".wizard-custom-action .setting .setting-value ul li:not(.disabled)"
);
2024-01-26 16:18:11 +01:00
const listDisabled = queryAll(
2022-12-20 17:22:24 +01:00
".wizard-custom-action .setting .setting-value ul li.disabled"
);
assert.ok(
2022-12-29 19:55:08 +01:00
listDisabled.length === 4,
2022-12-20 18:27:00 +01:00
"Disabled items displayed correctly in action dropdown"
2022-12-20 17:22:24 +01:00
);
assert.ok(
listEnabled.length === 7,
"Enabled items displayed correctly in action dropdown"
);
await actionTypeDropdown.selectRowByValue("create_topic");
assert.ok(
query(".wizard-custom-action .message-content").innerText.includes(
"You're editing an action"
),
"Create type action correctly selected"
);
2024-01-26 16:18:11 +01:00
let listTopicSettings = queryAll(
2022-12-20 17:22:24 +01:00
".admin-wizard-container .wizard-custom-action .setting"
);
assert.ok(
2024-07-09 11:54:36 +02:00
listTopicSettings.length === 12,
2022-12-20 17:22:24 +01:00
"Display all settings of create topic"
);
await actionTypeDropdown.expand();
2022-12-20 18:27:00 +01:00
await actionTypeDropdown.selectRowByValue("send_message");
2024-01-26 16:18:11 +01:00
listTopicSettings = queryAll(
2022-12-20 17:22:24 +01:00
".admin-wizard-container .wizard-custom-action .setting"
);
assert.ok(
2024-07-09 11:54:36 +02:00
listTopicSettings.length === 11,
2022-12-20 18:27:00 +01:00
"Display all settings of send message"
2022-12-20 17:22:24 +01:00
);
await actionTypeDropdown.expand();
2022-12-20 18:27:00 +01:00
await actionTypeDropdown.selectRowByValue("watch_categories");
2024-01-26 16:18:11 +01:00
listTopicSettings = queryAll(
2022-12-20 17:22:24 +01:00
".admin-wizard-container .wizard-custom-action .setting"
);
assert.ok(
2022-12-20 18:27:00 +01:00
listTopicSettings.length === 7,
"Display all settings of watch categories"
2022-12-20 17:22:24 +01:00
);
await actionTypeDropdown.expand();
2022-12-20 18:27:00 +01:00
await actionTypeDropdown.selectRowByValue("add_to_group");
2024-01-26 16:18:11 +01:00
listTopicSettings = queryAll(
2022-12-20 17:22:24 +01:00
".admin-wizard-container .wizard-custom-action .setting"
);
assert.ok(
2022-12-20 18:27:00 +01:00
listTopicSettings.length === 3,
"Display all settings of add to group"
2022-12-20 17:22:24 +01:00
);
await actionTypeDropdown.expand();
await actionTypeDropdown.selectRowByValue("create_topic");
// step("Step 5: Save wizard");
2022-12-20 17:22:24 +01:00
assert.ok(
!visible('.admin-wizard-buttons button:contains("Delete Wizard")'),
"delete wizard button not displayed"
);
await click(".admin-wizard-buttons button");
2022-12-20 17:22:24 +01:00
assert.equal(
currentURL(),
"/admin/wizards/wizard/new_wizard_for_testing",
"clicking the button navigates to the correct URL"
);
assert.ok(
visible('.admin-wizard-buttons button:contains("Delete Wizard")'),
"delete wizard button visible"
);
});
});