1
0
Fork 0

DEV: Add helper values for admin standard acceptance tests

Dieser Commit ist enthalten in:
jumagura 2022-12-22 00:11:57 -04:00
Ursprung 828ded7c05
Commit f0f27769fd

Datei anzeigen

@ -4,8 +4,15 @@ import {
visible, visible,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { findAll, settled, visit } from "@ember/test-helpers"; import { findAll, visit } from "@ember/test-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import {
getAdminTestingWizard,
getCreatedWizard,
getCustomFields,
getStandardAdminWizard,
getWizard,
} from "../helpers/admin-wizard";
acceptance("Admin | Custom Wizard Standard Subscription", function (needs) { acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
needs.user(); needs.user();
@ -16,308 +23,13 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
needs.pretender((server, helper) => { needs.pretender((server, helper) => {
server.get("/admin/wizards/wizard", () => { server.get("/admin/wizards/wizard", () => {
return helper.response({ return helper.response(getWizard);
wizard_list: [
{ id: "this_is_testing_wizard", name: "This is testing wizard" },
],
field_types: {
text: {
min_length: null,
max_length: null,
prefill: null,
char_counter: null,
validations: null,
placeholder: null,
},
textarea: {
min_length: null,
max_length: null,
prefill: null,
char_counter: null,
placeholder: null,
},
composer: {
min_length: null,
max_length: null,
char_counter: null,
placeholder: null,
},
text_only: {},
composer_preview: { preview_template: null },
date: { format: "YYYY-MM-DD" },
time: { format: "HH:mm" },
date_time: { format: "" },
number: {},
checkbox: {},
url: { min_length: null },
upload: { file_types: ".jpg,.jpeg,.png" },
dropdown: { prefill: null, content: null },
tag: { limit: null, prefill: null, content: null, tag_groups: null },
category: { limit: 1, property: "id", prefill: null, content: null },
group: { prefill: null, content: null },
user_selector: {},
},
realtime_validations: {
similar_topics: {
types: ["text"],
component: "similar-topics-validator",
backend: true,
required_params: [],
},
},
custom_fields: [
{
id: "external",
klass: "category",
name: "require_topic_approval",
type: "boolean",
serializers: null,
},
{
id: "external",
klass: "category",
name: "require_reply_approval",
type: "boolean",
serializers: null,
},
{
id: "external",
klass: "category",
name: "num_auto_bump_daily",
type: "integer",
serializers: null,
},
{
id: "external",
klass: "category",
name: "has_chat_enabled",
type: "boolean",
serializers: null,
},
{
id: "external",
klass: "post",
name: "missing uploads",
type: "json",
serializers: null,
},
{
id: "external",
klass: "post",
name: "missing uploads ignored",
type: "boolean",
serializers: null,
},
{
id: "external",
klass: "post",
name: "notice",
type: "json",
serializers: null,
},
{
id: "external",
klass: "post",
name: "local_dates",
type: "json",
serializers: null,
},
{
id: "external",
klass: "post",
name: "has_polls",
type: "boolean",
serializers: null,
},
],
});
}); });
server.get("/admin/wizards/custom-fields", () => { server.get("/admin/wizards/custom-fields", () => {
return helper.response({ return helper.response(getCustomFields);
custom_fields: [
{
id: "external",
klass: "category",
name: "require_topic_approval",
type: "boolean",
serializers: null,
},
{
id: "external",
klass: "category",
name: "require_reply_approval",
type: "boolean",
serializers: null,
},
{
id: "external",
klass: "category",
name: "num_auto_bump_daily",
type: "integer",
serializers: null,
},
{
id: "external",
klass: "category",
name: "has_chat_enabled",
type: "boolean",
serializers: null,
},
{
id: "external",
klass: "post",
name: "missing uploads",
type: "json",
serializers: null,
},
{
id: "external",
klass: "post",
name: "missing uploads ignored",
type: "boolean",
serializers: null,
},
{
id: "external",
klass: "post",
name: "notice",
type: "json",
serializers: null,
},
{
id: "external",
klass: "post",
name: "local_dates",
type: "json",
serializers: null,
},
{
id: "external",
klass: "post",
name: "has_polls",
type: "boolean",
serializers: null,
},
],
});
}); });
server.get("/admin/wizards", () => { server.get("/admin/wizards", () => {
return helper.response({ return helper.response(getStandardAdminWizard);
subscribed: true,
subscription_type: "standard",
subscription_attributes: {
wizard: {
required: {
none: [],
standard: ["*"],
business: ["*"],
community: ["*"],
},
permitted: {
none: [],
standard: ["*"],
business: ["*"],
community: ["*"],
},
restart_on_revisit: {
none: [],
standard: ["*"],
business: ["*"],
community: ["*"],
},
},
step: {
condition: {
none: [],
standard: ["*"],
business: ["*"],
community: ["*"],
},
required_data: {
none: [],
standard: ["*"],
business: ["*"],
community: ["*"],
},
permitted_params: {
none: [],
standard: ["*"],
business: ["*"],
community: ["*"],
},
},
field: {
condition: {
none: [],
standard: ["*"],
business: ["*"],
community: ["*"],
},
type: {
none: [
"text",
"textarea",
"text_only",
"date",
"time",
"date_time",
"number",
"checkbox",
"dropdown",
"upload",
],
standard: ["*"],
business: ["*"],
community: ["*"],
},
realtime_validations: {
none: [],
standard: ["*"],
business: ["*"],
community: ["*"],
},
},
action: {
type: {
none: [
"create_topic",
"update_profile",
"open_composer",
"route_to",
],
standard: [
"create_topic",
"update_profile",
"open_composer",
"route_to",
"send_message",
"watch_categories",
"add_to_group",
],
business: ["*"],
community: ["*"],
},
},
custom_field: {
klass: {
none: ["topic", "post"],
standard: ["topic", "post"],
business: ["*"],
community: ["*"],
},
type: {
none: ["string", "boolean", "integer"],
standard: ["string", "boolean", "integer"],
business: ["*"],
community: ["*"],
},
},
api: {
all: { none: [], standard: [], business: ["*"], community: ["*"] },
},
},
subscription_client_installed: false,
});
}); });
server.get("/admin/wizards/api", () => { server.get("/admin/wizards/api", () => {
return helper.response({ success: "OK" }); return helper.response({ success: "OK" });
@ -326,58 +38,7 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
return helper.response({ user_fields: [] }); return helper.response({ user_fields: [] });
}); });
server.get("/admin/wizards/wizard/this_is_testing_wizard", () => { server.get("/admin/wizards/wizard/this_is_testing_wizard", () => {
return helper.response({ return helper.response(getAdminTestingWizard);
id: "this_is_testing_wizard",
name: "This is testing wizard",
save_submissions: true,
after_time: false,
after_time_scheduled: "2022-12-12T13:45:00.000Z",
prompt_completion: true,
steps: [
{
id: "step_1",
title: "step 1",
raw_description: "This is a description for step 1 sads",
fields: [
{
id: "step_1_field_1",
label: "label field",
description: "this is the label description",
type: "textarea",
placeholder: "insert a textarea text here.",
},
],
description: "This is a description for step 1 sads",
},
],
actions: [
{
id: "action_1",
run_after: "wizard_completion",
type: "create_topic",
skip_redirect: false,
post: "step_1_field_1",
post_builder: false,
title: [
{
type: "assignment",
output: "Testing title",
output_type: "text",
output_connector: "set",
pairs: [],
},
],
category: [
{
type: "assignment",
output_type: "category",
output_connector: "set",
output: [30],
},
],
},
],
});
}); });
server.put("/admin/wizards/wizard/new_wizard_for_testing", () => { server.put("/admin/wizards/wizard/new_wizard_for_testing", () => {
return helper.response({ return helper.response({
@ -386,40 +47,13 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
}); });
}); });
server.get("/admin/wizards/wizard/new_wizard_for_testing", () => { server.get("/admin/wizards/wizard/new_wizard_for_testing", () => {
return helper.response({ return helper.response(getCreatedWizard);
id: "new_wizard_for_testing",
name: "new wizard for testing",
save_submissions: true,
steps: [
{
id: "step_1",
fields: [
{
id: "step_1_field_1",
type: "text",
validations: {
similar_topics: {},
},
},
],
},
],
actions: [
{
id: "action_1",
run_after: "wizard_completion",
type: "create_topic",
},
],
});
}); });
}); });
test("creting a new wizard", async (assert) => { test("creting a new wizard", async (assert) => {
await visit("/admin/wizards/wizard"); await visit("/admin/wizards/wizard");
await settled();
await click('button:contains("Create Wizard")'); await click('button:contains("Create Wizard")');
await settled();
assert.ok( assert.ok(
query(".message-content").innerText.includes( query(".message-content").innerText.includes(
"You're creating a new wizard" "You're creating a new wizard"
@ -429,7 +63,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
assert.step("Step 1: Inserting a title"); assert.step("Step 1: Inserting a title");
const wizardTitle = "New wizard for testing"; const wizardTitle = "New wizard for testing";
await fillIn(".wizard-header input", wizardTitle); await fillIn(".wizard-header input", wizardTitle);
await settled();
assert.equal( assert.equal(
$(".wizard-header input").val(), $(".wizard-header input").val(),
wizardTitle, wizardTitle,
@ -451,18 +84,15 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
".wizard-subscription-container .subscription-settings .setting-value input" ".wizard-subscription-container .subscription-settings .setting-value input"
); );
await click(subsFeature); await click(subsFeature);
await settled();
assert.ok(subsFeature.is(":checked"), "subscription feature available"); assert.ok(subsFeature.is(":checked"), "subscription feature available");
assert.step("Step 2: Creating a step section"); assert.step("Step 2: Creating a step section");
const stepAddBtn = find(".step .link-list button:contains('Add')"); const stepAddBtn = find(".step .link-list button:contains('Add')");
await click(stepAddBtn); await click(stepAddBtn);
await settled();
const stepOneText = "step_1 (step_1)"; const stepOneText = "step_1 (step_1)";
const stepOneBtn = find(`.step button:contains(${stepOneText})`); const stepOneBtn = find(`.step button:contains(${stepOneText})`);
assert.equal(stepOneBtn.length, 1, "Creating a step"); assert.equal(stepOneBtn.length, 1, "Creating a step");
const stepTitle = "step title"; const stepTitle = "step title";
await fillIn(".wizard-custom-step input[name='title']", stepTitle); await fillIn(".wizard-custom-step input[name='title']", stepTitle);
await settled();
const stepButtonText = $.trim( const stepButtonText = $.trim(
$(".step div[data-id='step_1'] button").text() $(".step div[data-id='step_1'] button").text()
); );
@ -478,7 +108,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
assert.step("Step 3: Creating a field section"); assert.step("Step 3: Creating a field section");
const fieldAddBtn = find(".field .link-list button:contains('Add')"); const fieldAddBtn = find(".field .link-list button:contains('Add')");
await click(fieldAddBtn); await click(fieldAddBtn);
await settled();
assert.ok( assert.ok(
!visible(".wizard-custom-field button.undo-changes"), !visible(".wizard-custom-field button.undo-changes"),
"clear button is not rendered" "clear button is not rendered"
@ -488,7 +117,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
assert.equal(fieldOneBtn.length, 1, "Creating a field"); assert.equal(fieldOneBtn.length, 1, "Creating a field");
const fieldTitle = "field title"; const fieldTitle = "field title";
await fillIn(".wizard-custom-field input[name='label']", fieldTitle); await fillIn(".wizard-custom-field input[name='label']", fieldTitle);
await settled();
assert.ok( assert.ok(
visible(".wizard-custom-field button.undo-changes"), visible(".wizard-custom-field button.undo-changes"),
"clear button is rendered after filling content" "clear button is rendered after filling content"
@ -502,7 +130,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
); );
const clearBtn = find(`.wizard-custom-field button.undo-changes`); const clearBtn = find(`.wizard-custom-field button.undo-changes`);
await click(clearBtn); await click(clearBtn);
await settled();
fieldButtonText = $(".field div[data-id='step_1_field_1'] button") fieldButtonText = $(".field div[data-id='step_1_field_1'] button")
.text() .text()
.trim(); .trim();
@ -515,14 +142,12 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
); );
await fieldTypeDropdown.expand(); await fieldTypeDropdown.expand();
await fieldTypeDropdown.selectRowByValue("text"); await fieldTypeDropdown.selectRowByValue("text");
await settled();
assert.ok( assert.ok(
query(".wizard-custom-field .message-content").innerText.includes( query(".wizard-custom-field .message-content").innerText.includes(
"You're editing a field" "You're editing a field"
), ),
"Text tipe for field correctly selected" "Text tipe for field correctly selected"
); );
assert.equal( assert.equal(
find(".wizard-subscription-container a:contains('Subscribed')").length, find(".wizard-subscription-container a:contains('Subscribed')").length,
3, 3,
@ -531,7 +156,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
assert.step("Step 4: Creating a action section"); assert.step("Step 4: Creating a action section");
const actionAddBtn = find(".action .link-list button:contains('Add')"); const actionAddBtn = find(".action .link-list button:contains('Add')");
await click(actionAddBtn); await click(actionAddBtn);
await settled();
const actionOneText = "action_1 (action_1)"; const actionOneText = "action_1 (action_1)";
const actionOneBtn = find(`.action button:contains(${actionOneText})`); const actionOneBtn = find(`.action button:contains(${actionOneText})`);
assert.equal(actionOneBtn.length, 1, "Creating an action"); assert.equal(actionOneBtn.length, 1, "Creating an action");
@ -545,14 +169,12 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
".wizard-custom-action .setting-value .select-kit" ".wizard-custom-action .setting-value .select-kit"
); );
await actionTypeDropdown.expand(); await actionTypeDropdown.expand();
await settled();
const listEnabled = findAll( const listEnabled = findAll(
".wizard-custom-action .setting .setting-value ul li:not(.disabled)" ".wizard-custom-action .setting .setting-value ul li:not(.disabled)"
); );
const listDisabled = findAll( const listDisabled = findAll(
".wizard-custom-action .setting .setting-value ul li.disabled" ".wizard-custom-action .setting .setting-value ul li.disabled"
); );
assert.ok( assert.ok(
listDisabled.length === 3, listDisabled.length === 3,
"Disabled items displayed correctly in action dropdown" "Disabled items displayed correctly in action dropdown"
@ -562,7 +184,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
"Enabled items displayed correctly in action dropdown" "Enabled items displayed correctly in action dropdown"
); );
await actionTypeDropdown.selectRowByValue("create_topic"); await actionTypeDropdown.selectRowByValue("create_topic");
await settled();
assert.ok( assert.ok(
query(".wizard-custom-action .message-content").innerText.includes( query(".wizard-custom-action .message-content").innerText.includes(
"You're editing an action" "You're editing an action"
@ -578,7 +199,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
); );
await actionTypeDropdown.expand(); await actionTypeDropdown.expand();
await actionTypeDropdown.selectRowByValue("send_message"); await actionTypeDropdown.selectRowByValue("send_message");
await settled();
listTopicSettings = findAll( listTopicSettings = findAll(
".admin-wizard-container .wizard-custom-action .setting" ".admin-wizard-container .wizard-custom-action .setting"
); );
@ -588,7 +208,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
); );
await actionTypeDropdown.expand(); await actionTypeDropdown.expand();
await actionTypeDropdown.selectRowByValue("watch_categories"); await actionTypeDropdown.selectRowByValue("watch_categories");
await settled();
listTopicSettings = findAll( listTopicSettings = findAll(
".admin-wizard-container .wizard-custom-action .setting" ".admin-wizard-container .wizard-custom-action .setting"
); );
@ -598,7 +217,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
); );
await actionTypeDropdown.expand(); await actionTypeDropdown.expand();
await actionTypeDropdown.selectRowByValue("add_to_group"); await actionTypeDropdown.selectRowByValue("add_to_group");
await settled();
listTopicSettings = findAll( listTopicSettings = findAll(
".admin-wizard-container .wizard-custom-action .setting" ".admin-wizard-container .wizard-custom-action .setting"
); );
@ -608,7 +226,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
); );
await actionTypeDropdown.expand(); await actionTypeDropdown.expand();
await actionTypeDropdown.selectRowByValue("create_topic"); await actionTypeDropdown.selectRowByValue("create_topic");
await settled();
assert.step("Step 5: Save wizard"); assert.step("Step 5: Save wizard");
const saveButton = find( const saveButton = find(
'.admin-wizard-buttons button:contains("Save Changes")' '.admin-wizard-buttons button:contains("Save Changes")'
@ -618,7 +235,6 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
"delete wizard button not displayed" "delete wizard button not displayed"
); );
await click(saveButton); await click(saveButton);
await settled();
assert.equal( assert.equal(
currentURL(), currentURL(),
"/admin/wizards/wizard/new_wizard_for_testing", "/admin/wizards/wizard/new_wizard_for_testing",