2022-12-20 06:01:32 +01:00
|
|
|
import {
|
|
|
|
acceptance,
|
|
|
|
query,
|
|
|
|
visible,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2022-12-19 16:46:52 +01:00
|
|
|
import { test } from "qunit";
|
2022-12-22 05:12:29 +01:00
|
|
|
import { findAll, visit } from "@ember/test-helpers";
|
2022-12-19 16:46:52 +01:00
|
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
2022-12-22 05:12:29 +01:00
|
|
|
import {
|
|
|
|
getAdminTestingWizard,
|
|
|
|
getCreatedWizard,
|
|
|
|
getCustomFields,
|
|
|
|
getUnsubscribedAdminWizards,
|
|
|
|
getWizard,
|
|
|
|
} from "../helpers/admin-wizard";
|
2022-12-19 16:46:52 +01:00
|
|
|
|
2022-12-20 17:22:01 +01:00
|
|
|
acceptance("Admin | Custom Wizard Unsuscribed", function (needs) {
|
2022-12-19 16:46:52 +01:00
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
|
|
|
custom_wizard_enabled: true,
|
|
|
|
available_locales: JSON.stringify([{ name: "English", value: "en" }]),
|
|
|
|
});
|
|
|
|
|
|
|
|
needs.pretender((server, helper) => {
|
2022-12-21 05:18:10 +01:00
|
|
|
server.get("/admin/wizards/wizard", () => {
|
2022-12-22 05:12:29 +01:00
|
|
|
return helper.response(getWizard);
|
2022-12-19 16:46:52 +01:00
|
|
|
});
|
2022-12-21 05:18:10 +01:00
|
|
|
server.get("/admin/wizards/custom-fields", () => {
|
2022-12-22 05:12:29 +01:00
|
|
|
return helper.response(getCustomFields);
|
2022-12-20 17:05:27 +01:00
|
|
|
});
|
2022-12-19 16:46:52 +01:00
|
|
|
server.get("/admin/wizards", () => {
|
2022-12-22 05:12:29 +01:00
|
|
|
return helper.response(getUnsubscribedAdminWizards);
|
2022-12-19 16:46:52 +01:00
|
|
|
});
|
2022-12-21 05:18:10 +01:00
|
|
|
server.get("/admin/wizards/api", () => {
|
2022-12-19 16:46:52 +01:00
|
|
|
return helper.response({ success: "OK" });
|
|
|
|
});
|
2022-12-21 05:18:10 +01:00
|
|
|
server.get("/admin/customize/user_fields", () => {
|
2022-12-19 16:46:52 +01:00
|
|
|
return helper.response({ user_fields: [] });
|
|
|
|
});
|
2022-12-21 05:18:10 +01:00
|
|
|
server.get("/admin/wizards/wizard/this_is_testing_wizard", () => {
|
2022-12-22 05:12:29 +01:00
|
|
|
return helper.response(getAdminTestingWizard);
|
2022-12-19 16:46:52 +01:00
|
|
|
});
|
2022-12-20 17:05:27 +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", () => {
|
2022-12-22 05:12:29 +01:00
|
|
|
return helper.response(getCreatedWizard);
|
2022-12-20 17:05:27 +01:00
|
|
|
});
|
2022-12-19 16:46:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("viewing content for a selected wizard", async (assert) => {
|
|
|
|
await visit("/admin/wizards/wizard");
|
|
|
|
assert.ok(
|
|
|
|
query(".message-content").innerText.includes(
|
|
|
|
"Select a wizard, or create a new one"
|
|
|
|
),
|
|
|
|
"it displays wizard message"
|
|
|
|
);
|
|
|
|
const wizards = selectKit(".select-kit");
|
|
|
|
await wizards.expand();
|
|
|
|
await wizards.selectRowByValue("this_is_testing_wizard");
|
|
|
|
assert.ok(
|
|
|
|
query(".message-content").innerText.includes("You're editing a wizard"),
|
|
|
|
"it displays wizard message for a selected wizard"
|
|
|
|
);
|
|
|
|
await wizards.expand();
|
|
|
|
const li = find('[data-name="Select a wizard"]');
|
|
|
|
await click(li);
|
|
|
|
const wizardContainerDiv = find(".admin-wizard-container");
|
2022-12-20 06:01:32 +01:00
|
|
|
assert.ok(
|
|
|
|
wizardContainerDiv.children().length === 0,
|
|
|
|
"the content is empty when no wizard is selected"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
test("creting a new wizard", async (assert) => {
|
|
|
|
await visit("/admin/wizards/wizard");
|
|
|
|
await click('button:contains("Create Wizard")');
|
|
|
|
assert.ok(
|
|
|
|
query(".message-content").innerText.includes(
|
|
|
|
"You're creating a new wizard"
|
|
|
|
),
|
|
|
|
"it displays wizard creation message"
|
|
|
|
);
|
|
|
|
assert.step("Step 1: Inserting a title");
|
|
|
|
const wizardTitle = "New wizard for testing";
|
|
|
|
await fillIn(".wizard-header input", wizardTitle);
|
|
|
|
assert.equal(
|
|
|
|
$(".wizard-header input").val(),
|
|
|
|
wizardTitle,
|
|
|
|
"The title input is inserted"
|
|
|
|
);
|
|
|
|
const wizardLink = find("div.wizard-url a");
|
|
|
|
assert.equal(wizardLink.length, 1, "Wizard link was created");
|
|
|
|
assert.equal(
|
|
|
|
$.trim($("a[title='Subscribe to use these features']").text()),
|
|
|
|
"Not Subscribed",
|
|
|
|
"Show messsage and link of user not subscribed"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
find(".wizard-subscription-container").length,
|
|
|
|
1,
|
|
|
|
"Wizard subscription features are not accesible"
|
|
|
|
);
|
|
|
|
assert.step("Step 2: Creating a step section");
|
|
|
|
const stepAddBtn = find(".step .link-list button:contains('Add')");
|
|
|
|
await click(stepAddBtn);
|
|
|
|
const stepOneText = "step_1 (step_1)";
|
|
|
|
const stepOneBtn = find(`.step button:contains(${stepOneText})`);
|
|
|
|
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(
|
|
|
|
find(".wizard-subscription-container").length,
|
|
|
|
2,
|
|
|
|
"Steps subscription features are not accesible"
|
|
|
|
);
|
|
|
|
assert.step("Step 3: Creating a field section");
|
|
|
|
const fieldAddBtn = find(".field .link-list button:contains('Add')");
|
|
|
|
await click(fieldAddBtn);
|
|
|
|
assert.ok(
|
|
|
|
!visible(".wizard-custom-field button.undo-changes"),
|
|
|
|
"clear button is not rendered"
|
|
|
|
);
|
|
|
|
const fieldOneText = "step_1_field_1 (step_1_field_1)";
|
|
|
|
const fieldOneBtn = find(`.field button:contains(${fieldOneText})`);
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
const clearBtn = find(`.wizard-custom-field button.undo-changes`);
|
|
|
|
await click(clearBtn);
|
|
|
|
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(
|
|
|
|
find(".wizard-subscription-container").length,
|
|
|
|
3,
|
|
|
|
"Field subscription features are not accesible"
|
|
|
|
);
|
|
|
|
assert.step("Step 4: Creating a action section");
|
|
|
|
const actionAddBtn = find(".action .link-list button:contains('Add')");
|
|
|
|
await click(actionAddBtn);
|
|
|
|
const actionOneText = "action_1 (action_1)";
|
|
|
|
const actionOneBtn = find(`.action button:contains(${actionOneText})`);
|
|
|
|
assert.equal(actionOneBtn.length, 1, "Creating an action");
|
2022-12-20 17:05:27 +01:00
|
|
|
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();
|
|
|
|
const listEnabled = findAll(
|
|
|
|
".wizard-custom-action .setting .setting-value ul li:not(.disabled)"
|
|
|
|
);
|
|
|
|
const listDisabled = findAll(
|
|
|
|
".wizard-custom-action .setting .setting-value ul li.disabled"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
listDisabled.length === 6,
|
|
|
|
"disabled items displayed correctly in action dropdown"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
listEnabled.length === 4,
|
|
|
|
"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"
|
|
|
|
);
|
|
|
|
let listTopicSettings = findAll(
|
|
|
|
".admin-wizard-container .wizard-custom-action .setting"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
listTopicSettings.length === 10,
|
|
|
|
"Display all settings of create topic"
|
|
|
|
);
|
|
|
|
await actionTypeDropdown.expand();
|
|
|
|
await actionTypeDropdown.selectRowByValue("open_composer");
|
|
|
|
listTopicSettings = findAll(
|
|
|
|
".admin-wizard-container .wizard-custom-action .setting"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
listTopicSettings.length === 8,
|
|
|
|
"Display all settings of open composer"
|
|
|
|
);
|
|
|
|
await actionTypeDropdown.expand();
|
|
|
|
await actionTypeDropdown.selectRowByValue("update_profile");
|
|
|
|
listTopicSettings = findAll(
|
|
|
|
".admin-wizard-container .wizard-custom-action .setting"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
listTopicSettings.length === 4,
|
|
|
|
"Display all settings of update profile"
|
|
|
|
);
|
|
|
|
await actionTypeDropdown.expand();
|
|
|
|
await actionTypeDropdown.selectRowByValue("route_to");
|
|
|
|
listTopicSettings = findAll(
|
|
|
|
".admin-wizard-container .wizard-custom-action .setting"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
listTopicSettings.length === 4,
|
|
|
|
"Display all settings of route to"
|
|
|
|
);
|
|
|
|
await actionTypeDropdown.expand();
|
|
|
|
const li = find('[data-name="Select a type"]');
|
|
|
|
await click(li);
|
|
|
|
listTopicSettings = findAll(
|
|
|
|
".admin-wizard-container .wizard-custom-action .setting"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
listTopicSettings.length === 2,
|
|
|
|
"the settings options is empty when no action is selected"
|
|
|
|
);
|
|
|
|
await actionTypeDropdown.expand();
|
|
|
|
await actionTypeDropdown.selectRowByValue("create_topic");
|
|
|
|
assert.step("Step 5: Save changes");
|
|
|
|
const saveButton = find(
|
|
|
|
'.admin-wizard-buttons button:contains("Save Changes")'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
!visible('.admin-wizard-buttons button:contains("Delete Wizard")'),
|
|
|
|
"delete wizard button not displayed"
|
|
|
|
);
|
|
|
|
await click(saveButton);
|
|
|
|
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"
|
|
|
|
);
|
2022-12-20 06:01:32 +01:00
|
|
|
assert.verifySteps(
|
|
|
|
[
|
|
|
|
"Step 1: Inserting a title",
|
|
|
|
"Step 2: Creating a step section",
|
|
|
|
"Step 3: Creating a field section",
|
|
|
|
"Step 4: Creating a action section",
|
2022-12-20 17:05:27 +01:00
|
|
|
"Step 5: Save changes",
|
2022-12-20 06:01:32 +01:00
|
|
|
],
|
|
|
|
"All steps completed"
|
|
|
|
);
|
2022-12-19 16:46:52 +01:00
|
|
|
});
|
|
|
|
});
|