1
0
Fork 0

DEV: Add admin submissions modal action tests

Dieser Commit ist enthalten in:
jumagura 2023-05-11 01:44:23 -04:00
Ursprung ed37c13664
Commit 9793ef6453
2 geänderte Dateien mit 197 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -3,6 +3,7 @@ import { test } from "qunit";
import { click, findAll, visit } from "@ember/test-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import {
getAnotherWizardSubmission,
getUnsubscribedAdminWizards,
getWizard,
getWizardSubmissions,
@ -18,11 +19,15 @@ acceptance("Admin | Submissions", function (needs) {
server.get("/admin/wizards/submissions", () => {
return helper.response([
{ id: "this_is_testing_wizard", name: "This is testing wizard" },
{ id: "another_wizard", name: "another wizard" },
]);
});
server.get("/admin/wizards/submissions/this_is_testing_wizard", () => {
return helper.response(getWizardSubmissions);
});
server.get("/admin/wizards/submissions/another_wizard", () => {
return helper.response(getAnotherWizardSubmission);
});
server.get("/admin/wizards", () => {
return helper.response(getUnsubscribedAdminWizards);
});
@ -30,7 +35,7 @@ acceptance("Admin | Submissions", function (needs) {
return helper.response(getWizard);
});
});
test("viewing submissions fields tab", async (assert) => {
test("View submissions fields tab and content", async (assert) => {
await visit("/admin/wizards/submissions");
const wizards = selectKit(".select-kit");
assert.ok(
@ -51,7 +56,33 @@ acceptance("Admin | Submissions", function (needs) {
),
"it displays submissions for a selected wizard"
);
assert.ok(find("table"));
const submissions = getWizardSubmissions.submissions; // Get submissions data from your JSON file
const rows = findAll("table tbody tr");
for (let i = 0; i < submissions.length; i++) {
const dateCell = rows[i].querySelector("td:nth-child(1)");
const userCell = rows[i].querySelector("td:nth-child(2)");
const stepCell = rows[i].querySelector("td:nth-child(3)");
const expectedDate = moment(submissions[i].submitted_at).format(
"MMM D, YYYY h:mm a"
);
assert.equal(
dateCell.innerText,
expectedDate,
`Date is displayed correctly for submission ${i + 1}`
);
assert.equal(
userCell.innerText.trim(),
submissions[i].user.username,
`User is displayed correctly for submission ${i + 1}`
);
assert.equal(
stepCell.innerText.trim().split("\n")[0],
submissions[i].fields.step_1_field_1.value,
`Step is displayed correctly for submission ${i + 1}`
);
}
assert.ok(
findAll("table tbody tr").length >= 1,
"Displays submissions list"
@ -62,4 +93,116 @@ acceptance("Admin | Submissions", function (needs) {
const wizardContainerDiv = find(".admin-wizard-container");
assert.ok(wizardContainerDiv.children().length === 0, "the div is empty");
});
test("View submissions tab for another wizard with more steps", async (assert) => {
await visit("/admin/wizards/submissions");
const wizards = selectKit(".select-kit");
await wizards.expand();
await wizards.selectRowByValue("another_wizard");
assert.ok(
query(".message-content").innerText.includes(
"You're viewing the submissions of the another wizard"
),
"it displays submissions for another wizard"
);
const submissions = getAnotherWizardSubmission.submissions; // Get submissions data from your JSON file
const rows = findAll("table tbody tr");
for (let i = 0; i < submissions.length; i++) {
const dateCell = rows[i].querySelector("td:nth-child(1)");
const userCell = rows[i].querySelector("td:nth-child(2)");
const step1Cell = rows[i].querySelector("td:nth-child(3)");
const step2Cell = rows[i].querySelector("td:nth-child(4)");
const submission = submissions[i];
const expectedDate = moment(submission.submitted_at).format(
"MMM D, YYYY h:mm a"
);
assert.equal(
dateCell.innerText,
expectedDate,
`Date is displayed correctly for submission ${i + 1}`
);
assert.equal(
userCell.innerText.trim(),
submissions[i].user.username,
`User is displayed correctly for submission ${i + 1}`
);
assert.equal(
step1Cell.innerText.trim().split("\n")[0],
submissions[i].fields.step_1_field_1.value,
`Step 1 is displayed correctly for submission ${i + 1}`
);
assert.equal(
step2Cell.innerText.trim().split("\n")[0],
submissions[i].fields.step_2_field_1.value,
`Step 2 is displayed correctly for submission ${i + 1}`
);
}
assert.ok(
findAll("table tbody tr").length >= 1,
"Displays submissions list for another wizard"
);
});
test("Modal actions for submissions", async (assert) => {
await visit("/admin/wizards/submissions");
const wizards = await selectKit(".select-kit");
await wizards.expand();
await wizards.selectRowByValue("this_is_testing_wizard");
await click(".open-edit-columns-btn");
assert.dom(".modal-inner-container").exists("Modal is displayed");
const userCheckbox = find(
".edit-directory-columns-container .edit-directory-column:nth-child(2) .left-content .column-name input"
);
assert.ok(userCheckbox, "User checkbox is present");
assert.ok(userCheckbox[0].checked, "User checkbox is checked by default");
await click(userCheckbox[0]);
assert.notOk(
userCheckbox[0].checked,
"User checkbox is unchecked after clicking"
);
await click(".modal-footer .btn-primary");
assert
.dom("table thead th")
.doesNotIncludeText("User", "User column is not displayed");
await click(".open-edit-columns-btn");
const submittedAtCheckbox = find(
".edit-directory-columns-container .edit-directory-column:nth-child(1) .left-content .column-name input"
);
assert.ok(submittedAtCheckbox, "Submitted At checkbox is present");
assert.ok(
submittedAtCheckbox[0].checked,
"Submitted At checkbox is checked by default"
);
await click(submittedAtCheckbox[0]);
await click(".modal-footer .btn-primary");
assert.notOk(
submittedAtCheckbox[0].checked,
"Submitted At checkbox is unchecked after clicking"
);
assert
.dom("table thead th")
.doesNotIncludeText(
"Submitted At",
"Submitted At column is not displayed"
);
await click(".open-edit-columns-btn");
await click(".modal-footer .btn-secondary");
assert
.dom("table thead th:nth-child(1)")
.hasText("Submitted At", "Submitted At column is displayed after reset");
assert
.dom("table thead th:nth-child(2)")
.hasText("User", "User column is displayed after reset");
});
});

Datei anzeigen

@ -1,6 +1,7 @@
const getWizard = {
wizard_list: [
{ id: "this_is_testing_wizard", name: "This is testing wizard" },
{ id: "another_wizard", name: "another wizard" },
],
field_types: {
text: {
@ -317,6 +318,56 @@ const getWizardSubmissions = {
],
total: 1,
};
const getAnotherWizardSubmission = {
wizard: { id: "another_wizard", name: "another wizard" },
submissions: [
{
id: "00925bcd58366d07fb698dc5",
fields: {
step_1_field_1: {
value: "More content here by user",
type: "text",
label: "Content to be inserted",
},
step_2_field_1: {
value: "body of the content created by the user",
type: "textarea",
label: "Step 2 content",
},
},
submitted_at: "2023-05-10T20:58:11-04:00",
user: {
id: 29,
username: "anotheruser",
name: null,
avatar_template: "",
},
},
{
id: "dc094efcd4873d6da4666c1a",
fields: {
step_1_field_1: {
value: "Title for the content being created",
type: "text",
label: "Content to be inserted",
},
step_2_field_1: {
value: "THis is the body of the content that will be created",
type: "textarea",
label: "Step 2 content",
},
},
submitted_at: "2023-05-10T20:56:14-04:00",
user: {
id: 1,
username: "someuser",
name: null,
avatar_template: "",
},
},
],
total: 2,
};
const getBusinessAdminWizard = {
subscribed: true,
subscription_type: "business",
@ -694,4 +745,5 @@ export {
getCreatedWizard,
getNewApi,
putNewApi,
getAnotherWizardSubmission,
};