From b06ea42092ce2674de3731a04cad6c23a262957f Mon Sep 17 00:00:00 2001 From: Vojtech Salbaba Date: Thu, 6 Jul 2023 07:59:43 +0200 Subject: [PATCH] Add tests for the Configuration => Undertow => Global settings page Extract expression input functionality into cy.textExpression() function Extract expression input functionality into cy.text() function Extract expression verification into separate methods https://github.com/hal/berg/issues/37 --- .../manual-test-matrix-workflow.yaml | 1 + .../scheduled-run-all-tests-workflow.yaml | 1 + ...n-subsystem-undertow-global-settings.cy.ts | 126 ++++++++++++++++++ .../testsuite/cypress/support/form-editing.ts | 51 ++++++- .../cypress/support/resource-utils.ts | 20 +++ .../cypress/support/verification-utils.ts | 22 +++ 6 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 packages/testsuite/cypress/e2e/undertow/test-configuration-subsystem-undertow-global-settings.cy.ts diff --git a/.github/workflows/manual-test-matrix-workflow.yaml b/.github/workflows/manual-test-matrix-workflow.yaml index 9e53404c1..e3789c189 100644 --- a/.github/workflows/manual-test-matrix-workflow.yaml +++ b/.github/workflows/manual-test-matrix-workflow.yaml @@ -35,6 +35,7 @@ jobs: "homepage", "smoke", "update-manager", + "undertow", ] exclude: - specs: "update-manager" diff --git a/.github/workflows/scheduled-run-all-tests-workflow.yaml b/.github/workflows/scheduled-run-all-tests-workflow.yaml index 13a0dac4a..bd74d908d 100644 --- a/.github/workflows/scheduled-run-all-tests-workflow.yaml +++ b/.github/workflows/scheduled-run-all-tests-workflow.yaml @@ -37,6 +37,7 @@ jobs: "homepage", "smoke", "update-manager", + "undertow", ] exclude: - specs: "update-manager" diff --git a/packages/testsuite/cypress/e2e/undertow/test-configuration-subsystem-undertow-global-settings.cy.ts b/packages/testsuite/cypress/e2e/undertow/test-configuration-subsystem-undertow-global-settings.cy.ts new file mode 100644 index 000000000..dfb5f8f03 --- /dev/null +++ b/packages/testsuite/cypress/e2e/undertow/test-configuration-subsystem-undertow-global-settings.cy.ts @@ -0,0 +1,126 @@ +describe("TESTS: Configuration => Subsystem => Undertow => Global settings", () => { + let managementEndpoint: string; + const address = ["subsystem", "undertow"]; + const globalSettingsForm = { + formId: "undertow-global-settings-form", + defaultSecurityDomain: "default-security-domain", + defaultServer: "default-server", + defaultServletContainer: "default-servlet-container", + defaultVirtualHost: "default-virtual-host", + instanceId: "instance-id", + statisticsEnabled: "statistics-enabled", + }; + const testValues = { + serverName: "new-server", + servletContainer: "new-servlet-container", + serverHost: "new-host-in-new-server", + instanceId: "new-instaince-id", + statisticsEnabledExpression: "${wildfly.statistics-enabled:true}", + }; + + before(() => { + cy.startWildflyContainer() + .then((result) => { + managementEndpoint = result as string; + }) + .then(() => { + // create fixtures + cy.task("execute:cli", { + managementApi: managementEndpoint + "/management", + address: ["subsystem", "undertow", "server", testValues.serverName], + operation: "add", + }); + cy.task("execute:cli", { + managementApi: managementEndpoint + "/management", + address: ["subsystem", "undertow", "servlet-container", testValues.servletContainer], + operation: "add", + }); + cy.task("execute:cli", { + managementApi: managementEndpoint + "/management", + address: ["subsystem", "undertow", "server", testValues.serverName, "host", testValues.serverHost], + operation: "add", + }); + }); + }); + + after(() => { + cy.task("stop:containers"); + }); + + beforeEach(() => { + cy.navigateTo(managementEndpoint, "undertow"); + // the form takes a brief moment to initialize + cy.wait(200); + }); + + it("Should update the default security domain configuration ", () => { + cy.editForm(globalSettingsForm.formId); + cy.text(globalSettingsForm.formId, globalSettingsForm.defaultSecurityDomain, "some test value"); + cy.saveForm(globalSettingsForm.formId); + cy.verifySuccess(); + cy.verifyAttribute(managementEndpoint, address, "default-security-domain", "some test value"); + }); + + it("Should update the default server configuration", () => { + cy.editForm(globalSettingsForm.formId); + cy.text(globalSettingsForm.formId, globalSettingsForm.defaultServer, testValues.serverName); + cy.saveForm(globalSettingsForm.formId); + cy.verifySuccess(); + cy.verifyAttribute(managementEndpoint, address, "default-server", testValues.serverName); + }); + + it("Should update the default servlet container configuration", () => { + cy.editForm(globalSettingsForm.formId); + cy.text(globalSettingsForm.formId, globalSettingsForm.defaultServletContainer, testValues.servletContainer); + cy.saveForm(globalSettingsForm.formId); + cy.verifySuccess(); + cy.verifyAttribute(managementEndpoint, address, "default-servlet-container", testValues.servletContainer); + }); + + it("Should update the default virtual host configuration", () => { + cy.editForm(globalSettingsForm.formId); + cy.text(globalSettingsForm.formId, globalSettingsForm.defaultVirtualHost, testValues.serverHost); + cy.saveForm(globalSettingsForm.formId); + cy.verifySuccess(); + cy.verifyAttribute(managementEndpoint, address, "default-virtual-host", testValues.serverHost); + }); + + it("Should update the instance ID configuration", () => { + cy.editForm(globalSettingsForm.formId); + cy.text(globalSettingsForm.formId, globalSettingsForm.instanceId, testValues.instanceId); + cy.saveForm(globalSettingsForm.formId); + cy.verifySuccess(); + cy.verifyAttribute(managementEndpoint, address, "instance-id", testValues.instanceId); + }); + + it("Should update the statistics-enabled configuration by changing the expression", () => { + cy.editForm(globalSettingsForm.formId); + const expressionFormInputSelector = "input#undertow-global-settings-form-statistics-enabled-editing.form-control"; + cy.textExpression( + globalSettingsForm.formId, + globalSettingsForm.statisticsEnabled, + testValues.statisticsEnabledExpression, + { + selector: expressionFormInputSelector, + } + ); + + cy.saveForm(globalSettingsForm.formId); + cy.verifySuccess(); + cy.verifyAttributeAsExpression( + managementEndpoint, + address, + "statistics-enabled", + testValues.statisticsEnabledExpression + ); + }); + + it("Should update the statistics-enabled configuration by flipping the switch", () => { + cy.editForm(globalSettingsForm.formId); + cy.get('button[title="Switch to normal mode"]').click(); + cy.flip(globalSettingsForm.formId, "statistics-enabled", false); + cy.saveForm(globalSettingsForm.formId); + cy.verifySuccess(); + cy.verifyAttribute(managementEndpoint, address, "statistics-enabled", true); + }); +}); diff --git a/packages/testsuite/cypress/support/form-editing.ts b/packages/testsuite/cypress/support/form-editing.ts index d3960863d..033b9ded3 100644 --- a/packages/testsuite/cypress/support/form-editing.ts +++ b/packages/testsuite/cypress/support/form-editing.ts @@ -114,11 +114,27 @@ Cypress.Commands.add("flip", (formId, attributeName, value) => { }); }); -Cypress.Commands.add("text", (formId, attributeName, value) => { - cy.formInput(formId, attributeName).click({ force: true }).wait(200).clear(); - cy.formInput(formId, attributeName).type(value as string); - cy.formInput(formId, attributeName).should("have.value", value); - cy.formInput(formId, attributeName).trigger("change"); +Cypress.Commands.add( + "text", + (formId, attributeName, value, options = { selector: "", parseSpecialCharSequences: true }) => { + const selector = options.selector; + const parseSpecialCharSequences = options.parseSpecialCharSequences; + let formInput; + if (selector) { + formInput = cy.get(selector); + } else { + formInput = cy.formInput(formId, attributeName); + } + + formInput.click({ force: true }).wait(200).clear(); + formInput.type(value as string, { parseSpecialCharSequences: parseSpecialCharSequences }); + formInput.should("have.value", value); + formInput.trigger("change"); + } +); + +Cypress.Commands.add("textExpression", (formId, attributeName, value, options = { selector: "" }) => { + cy.text(formId, attributeName, value, { selector: options.selector, parseSpecialCharSequences: false }); }); Cypress.Commands.add("clearAttribute", (formId, attributeName) => { @@ -222,8 +238,31 @@ declare global { * @param formId - The ID of section which contain form inputs. * @param attributeName - specific ID part of form input with text form input. * @param value - the value which needs to be write to form input. + * @param options - an object which might contain any of the following: + * - a custom selector for text field (the name of the text field will not be guessed) + */ + text( + formId: string, + attributeName: string, + value: string | number, + options?: { selector?: string; parseSpecialCharSequences?: boolean } + ): Chainable; + /** + * Set text value to form input. + * @category Data inserting + * + * @param formId - The ID of section which contain form inputs. + * @param attributeName - specific ID part of form input with text form input. + * @param value - the value which needs to be write to form input. + * @param options - an object which might contain any of the following: + * - a custom selector for text field (the name of the text field will not be guessed) */ - text(formId: string, attributeName: string, value: string | number): Chainable; + textExpression( + formId: string, + attributeName: string, + value: string | number, + options?: { selector?: string } + ): Chainable; /** * Clear all selected list attribute items from the form input. * @category Data removing diff --git a/packages/testsuite/cypress/support/resource-utils.ts b/packages/testsuite/cypress/support/resource-utils.ts index fa41a8933..2ae05d5e9 100644 --- a/packages/testsuite/cypress/support/resource-utils.ts +++ b/packages/testsuite/cypress/support/resource-utils.ts @@ -125,6 +125,12 @@ Cypress.Commands.add("readAttributeAsObjectList", (managementEndpoint, address, }); }); +Cypress.Commands.add("readAttributeAsExpression", (managementEndpoint, address, name) => { + cy.readAttributeAsObject(managementEndpoint, address, name).then((result) => { + return (result as { EXPRESSION_VALUE: string })["EXPRESSION_VALUE"]; + }); +}); + Cypress.Commands.add("writeAttribute", (managementEndpoint, address, name, value) => { cy.task("execute:cli", { managementApi: managementEndpoint + "/management", @@ -279,6 +285,20 @@ declare global { name: string, value: string | boolean | number ): Chainable; + + /** + * Executes :read-attribute operation at given address and attribute name. + * The managementEndpoint API is expected to return JSON with key "EXPRESSION_VALUE" + * Returns read value as string. + * + * @param managementEndpoint - Management endpoint of the WildFly server container instance. + * @param address - CLI address of subsystem. + * @param name - name of attribute from subsystem configuration. The attribute value is expected to be an expression + * + * @returns The the attribute value of subsystem configuration as string. + */ + readAttributeAsExpression(managementEndpoint: string, address: string[], name: string): Chainable; + /** * Get HTML element from form. * @category Get value diff --git a/packages/testsuite/cypress/support/verification-utils.ts b/packages/testsuite/cypress/support/verification-utils.ts index 659ca63db..44a9ab61b 100644 --- a/packages/testsuite/cypress/support/verification-utils.ts +++ b/packages/testsuite/cypress/support/verification-utils.ts @@ -65,6 +65,12 @@ Cypress.Commands.add("verifyRemovedFromTable", (tableId, resourceName) => { cy.get(`${tableWrapper} td:contains("${resourceName}")`).should("not.exist"); }); +Cypress.Commands.add("verifyAttributeAsExpression", (managementEndpoint, address, attributeName, expectedValue) => { + cy.readAttributeAsExpression(managementEndpoint, address, attributeName).then((result) => { + expect(result).to.equal(expectedValue); + }); +}); + export {}; declare global { @@ -152,6 +158,22 @@ declare global { * @param resourceName - The name of a resource */ verifyRemovedFromTable(tableId: string, resourceName: string): void; + + /** + * Verify the specific configuration is saved. + * @category Verification + * + * @param managementEndpoint - Host name of currently used container. + * @param address - CLI address of subsystem which needs to be verified. + * @param attributeName - Attribute of subsystem which needs to be verified. + * @param expectedValue - The expected value of the attribute. The value is expected to be an expression + */ + verifyAttributeAsExpression( + managementEndpoint: string, + address: string[], + attributeName: string, + expectedValue: string + ): void; } } }