From 1a84acec21f917f7b02846d70acbcc05723731a5 Mon Sep 17 00:00:00 2001 From: jumagura Date: Tue, 9 May 2023 03:17:22 -0400 Subject: [PATCH] DEV: Add created and read custom fields tests --- .../admin-custom-fields-unsuscribed-test.js | 106 +++++++++++++++++- test/javascripts/helpers/admin-wizard.js | 35 ------ 2 files changed, 105 insertions(+), 36 deletions(-) diff --git a/test/javascripts/acceptance/admin-custom-fields-unsuscribed-test.js b/test/javascripts/acceptance/admin-custom-fields-unsuscribed-test.js index 38c726e6..4510c3ab 100644 --- a/test/javascripts/acceptance/admin-custom-fields-unsuscribed-test.js +++ b/test/javascripts/acceptance/admin-custom-fields-unsuscribed-test.js @@ -29,12 +29,45 @@ acceptance("Admin | Custom Fields Unsuscribed", function (needs) { server.get("/admin/wizards/custom-fields", () => { return helper.response(getCustomFields); }); + server.put("/admin/wizards/custom-fields", () => { + return helper.response({ success: "OK" }); + }); }); + async function selectTypeAndSerializerAndFillInName( + type, + serializer, + name, + summaryName + ) { + const typeDropdown = selectKit( + `.admin-wizard-container details:has(summary[name="${summaryName}"])` + ); + await typeDropdown.expand(); + await click( + `.select-kit-collection li[data-value="${type.toLowerCase()}"]` + ); + + const serializerDropdown = selectKit( + ".admin-wizard-container details.multi-select" + ); + await serializerDropdown.expand(); + await click( + `.select-kit-collection li[data-value="${serializer + .toLowerCase() + .replace(/ /g, "_")}"]` + ); + + await fillIn(".admin-wizard-container input", name); + } + test("Navigate to custom fields tab", async (assert) => { await visit("/admin/wizards/custom-fields"); assert.ok(find("table")); - assert.ok(findAll("table tbody tr").length === 9); + assert.ok( + findAll("table tbody tr").length === 4, + "Display loaded custom fields" + ); assert.ok( query(".message-content").innerText.includes( "View, create, edit and destroy custom fields" @@ -135,4 +168,75 @@ acceptance("Admin | Custom Fields Unsuscribed", function (needs) { "There is one enabled option in the serializer dropdown for Post" ); }); + + test("Create Topic and Post custom fields", async (assert) => { + await visit("/admin/wizards/custom-fields"); + assert.ok( + findAll("table tbody tr").length === 4, + "Display loaded custom fields" + ); + await click(".admin-wizard-controls .btn-icon-text"); + + const dropdownTopic = selectKit( + '.admin-wizard-container details:has(summary[name="Filter by: Select a class"])' + ); + await dropdownTopic.expand(); + await click('.select-kit-collection li[data-value="topic"]'); + + await selectTypeAndSerializerAndFillInName( + "String", + "Topic View", + "Topic Custom Field", + "Filter by: Select a type" + ); + + await click(".actions .save"); + + assert.ok( + query( + ".admin-wizard-container tbody tr:first-child td:nth-child(1) label" + ).innerText.includes("topic"), + "Topic custom field is displayed" + ); + assert.ok( + query( + ".admin-wizard-container tbody tr:first-child td:nth-child(3) label" + ).innerText.includes("Topic Custom Field"), + "Topic custom field name is displayed" + ); + + await click(".admin-wizard-controls .btn-icon-text"); + + const dropdownPost = selectKit( + '.admin-wizard-container details:has(summary[name="Filter by: Select a class"])' + ); + await dropdownPost.expand(); + await click('.select-kit-collection li[data-value="post"]'); + + await selectTypeAndSerializerAndFillInName( + "Boolean", + "Post", + "Post Custom Field", + "Filter by: Select a type" + ); + + await click(".actions .save"); + + assert.ok( + query( + ".admin-wizard-container tbody tr:first-child td:nth-child(1) label" + ).innerText.includes("post"), + "Post custom field is displayed" + ); + assert.ok( + query( + ".admin-wizard-container tbody tr:first-child td:nth-child(3) label" + ).innerText.includes("Post Custom Field"), + "Post custom field name is displayed" + ); + assert.ok( + findAll("table tbody tr").length === 6, + "Display added custom fields" + ); + }); }); diff --git a/test/javascripts/helpers/admin-wizard.js b/test/javascripts/helpers/admin-wizard.js index ef6a73c4..ab37e1e3 100644 --- a/test/javascripts/helpers/admin-wizard.js +++ b/test/javascripts/helpers/admin-wizard.js @@ -254,41 +254,6 @@ const getCustomFields = { 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, - }, ], }; const getWizardTestingLog = {