Skip to content

Commit

Permalink
cypress-test-config-experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
geodem127 committed Jan 10, 2025
1 parent 08ab081 commit c0c19e2
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 76 deletions.
3 changes: 1 addition & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ module.exports = defineConfig({
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
testIsolation: false,
},
defaultCommandTimeout: 30_000,
requestTimeout: 60_000,
responseTimeout: 60_000,
retries: 1,
experimentalMemoryManagement: true,
chromeWebSecurity: false,
});
10 changes: 5 additions & 5 deletions cypress/e2e/content/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("Actions in content editor", () => {
cy.getBySelector("ConfirmPublishButton").click();

cy.intercept("GET", "**/publishings").as("publish");
cy.wait("@publish");
cy.wait("@publish", { timeout: 30_000 });

cy.getBySelector("ContentPublishedIndicator").should("exist");
});
Expand Down Expand Up @@ -257,9 +257,9 @@ describe("Actions in content editor", () => {
// these waits are due to a delay
// dealing with these specific endpoints
// the local environment is slow
cy.contains("Successfully sent workflow request", { timeout: 5000 }).should(
"exist"
);
cy.contains("Successfully sent workflow request", {
timeout: 15_000,
}).should("exist");
});

// it("Refreshes the CDN cache", () => {
Expand Down Expand Up @@ -330,6 +330,6 @@ describe("Actions in content editor", () => {

cy.getBySelector("CreateItemSaveButton").click();

cy.contains("Created Item", { timeout: 5000 }).should("exist");
cy.contains("Created Item", { timeout: 30_000 }).should("exist");
});
});
77 changes: 26 additions & 51 deletions cypress/e2e/content/workflows.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import ContentItemPage from "./pages/ContentItemPage";
import SettingsPage from "../settings/pages/SettingsPage";
import instanceZUID from "../../../src/utility/instanceZUID";
import CONFIG from "../../../src/shell/app.config";
import {
AUTHORIZED_ROLES,
colorMenu,
} from "../../../src/apps/settings/src/app/views/User/Workflows/constants";

const INSTANCE_API = `${
CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE_PROTOCOL
}${instanceZUID}${CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE}`;
import instanceZUID from "../../../src/utility/instanceZUID";

const INSTANCE_API = `${
CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE_PROTOCOL
Expand Down Expand Up @@ -81,28 +72,31 @@ describe("Content Item Workflows", () => {

after(() => {
// Delete test content item
// ContentItemPage.elements.moreMenu().should("exist").click();
// ContentItemPage.elements.deleteItemButton().should("exist").click();
// ContentItemPage.elements.confirmDeleteItemButton().should("exist").click();
// cy.intercept("DELETE", "**/content/models/6-b6cde1aa9f-wftv50/items/*").as(
// "deleteContentItem"
// );
// cy.wait("@deleteContentItem");

// // Delete allow publish label after test
// SettingsPage.deactivateWorkflowLabel(TITLES.testLabel);
// cy.get(
// '[data-cy="active-labels-container"] [data-cy="status-label"]:visible'
// )
// .contains("Random Test Label")
// .should("not.exist");
// SettingsPage.deactivateWorkflowLabel(TITLES.publishLabel);
// cy.get(
// '[data-cy="active-labels-container"] [data-cy="status-label"]:visible'
// )
// .contains("Publish Approval")
// .should("not.exist");
cy.cleanTestData();
cy.location("pathname").then((loc) => {
const [_, __, modelZUID, itemZUID] = loc?.split("/");
cy.apiRequest({
method: "DELETE",
url: `${INSTANCE_API}/content/models/${modelZUID}/items/${itemZUID}`,
});
});

// Delete test labels
cy.apiRequest({ url: `${INSTANCE_API}/env/labels?showDeleted=true` }).then(
(response) => {
response?.data
?.filter(
(label) =>
!label?.deletedAt &&
[TITLES.publishLabel, TITLES.testLabel].includes(label?.name)
)
.forEach((label) => {
cy.apiRequest({
url: `${INSTANCE_API}/env/labels/${label.ZUID}`,
method: "DELETE",
});
});
}
);
});

it("Can add a workflow label", () => {
Expand Down Expand Up @@ -202,22 +196,3 @@ describe("Content Item Workflows", () => {
ContentItemPage.elements.contentPublishedIndicator().should("exist");
});
});

Cypress.Commands.add("cleanTestData", () => {
const labelsToDelete = ["Random Test Label", "Publish Approval"];

cy.apiRequest({ url: `${INSTANCE_API}/env/labels?showDeleted=true` }).then(
(response) => {
response?.data
?.filter(
(label) => !label?.deletedAt && labelsToDelete.includes(label?.name)
)
.forEach((label) => {
cy.apiRequest({
url: `${INSTANCE_API}/env/labels/${label.ZUID}`,
method: "DELETE",
});
});
}
);
});
30 changes: 14 additions & 16 deletions cypress/e2e/settings/workflows.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

const TIMEOUT = { timeout: 40_000 };

const INSTANCE_API = `${
const INSTANCE_API_ENDPOINT = `${
CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE_PROTOCOL
}${instanceZUID}${CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE}`;

Expand Down Expand Up @@ -474,27 +474,25 @@ Cypress.Commands.add("cleanTestData", function () {
TEST_DATA?.temp3?.name,
];

cy.apiRequest({ url: `${INSTANCE_API}/env/labels?showDeleted=true` }).then(
(response) => {
response?.data
?.filter(
(label) => !label?.deletedAt && testLabels.includes(label?.name)
)
.forEach((label) => {
cy.apiRequest({
url: `${INSTANCE_API}/env/labels/${label.ZUID}`,
method: "DELETE",
});
cy.apiRequest({
url: `${INSTANCE_API_ENDPOINT}/env/labels?showDeleted=true`,
}).then((response) => {
response?.data
?.filter((label) => !label?.deletedAt && testLabels.includes(label?.name))
.forEach((label) => {
cy.apiRequest({
url: `${INSTANCE_API_ENDPOINT}/env/labels/${label.ZUID}`,
method: "DELETE",
});
}
);
});
});
});

Cypress.Commands.add("createTestData", () => {
const testLabels = [TEST_DATA?.temp1, TEST_DATA?.temp2, TEST_DATA?.temp3];
testLabels.forEach((label) => {
cy.apiRequest({
url: `${INSTANCE_API}/env/labels`,
url: `${INSTANCE_API_ENDPOINT}/env/labels`,
method: "POST",
body: {
...label,
Expand All @@ -507,7 +505,7 @@ Cypress.Commands.add("createTestData", () => {
Cypress.Commands.add("getStatusLabels", () => {
return cy
.apiRequest({
url: `${INSTANCE_API}/env/labels?showDeleted=true`,
url: `${INSTANCE_API_ENDPOINT}/env/labels?showDeleted=true`,
})
.then((response) => {
return parseStatusLabels(response?.data);
Expand Down
43 changes: 41 additions & 2 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import instanceZUID from "../../src/utility/instanceZUID";
import CONFIG from "../../src/shell/app.config";

const INSTANCE_API_ENDPOINT = `${
CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE_PROTOCOL
}${instanceZUID}${CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE}`;

const DEFAULT_STATUS_LABELS_ZUIDS = [
"36-14b315-4pp20v3d",
"36-14b315-d24ft",
"36-n33d5-23v13w",
];

const DEFAULT_STATUS_LABELS_NAMES = ["Approved", "Needs Review", "Draft"];

Cypress.Commands.add("login", () => {
const formBody = new FormData();

Expand All @@ -8,14 +23,16 @@ Cypress.Commands.add("login", () => {
.request({
url: `${Cypress.env("API_AUTH")}/login`,
method: "POST",
credentials: "include",
body: formBody,
})
.then(async (res) => {
const response = await new Response(res.body).json();
// We need the cookie value returned reset so it is unsecure and
// accessible by javascript
cy.setCookie(Cypress.env("COOKIE_NAME"), response.meta.token);
})
.then(() => {
return cy.get("body");
});
});

Expand Down Expand Up @@ -43,7 +60,7 @@ Cypress.Commands.add("assertClipboardValue", (value) => {
});

Cypress.Commands.add("getBySelector", (selector, ...args) => {
return cy.get(`[data-cy=${selector}]`, { timeout: 50_000, ...args });
return cy.get(`[data-cy=${selector}]`, { timeout: 40_000, ...args });
});

Cypress.Commands.add("blockAnnouncements", () => {
Expand Down Expand Up @@ -71,3 +88,25 @@ Cypress.Commands.add(
});
}
);

Cypress.Commands.add("workflowStatusLabelCleanUp", function () {
cy.apiRequest({
url: `${INSTANCE_API_ENDPOINT}/env/labels?showDeleted=true`,
}).then((response) => {
console.debug("workflowStatusLabelCleanUp | response LABELS: ", response);

response?.data
?.filter(
(label) =>
!label?.deletedAt &&
!DEFAULT_STATUS_LABELS_NAMES.includes(label?.name) &&
!DEFAULT_STATUS_LABELS_ZUIDS.includes(label?.ZUID)
)
.forEach((label) => {
cy.apiRequest({
url: `${INSTANCE_API_ENDPOINT}/env/labels/${label.ZUID}`,
method: "DELETE",
});
});
});
});
1 change: 1 addition & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ before(() => {

// Blocks the api call to render the announcement popup
cy.blockAnnouncements();
cy.workflowStatusLabelCleanUp();
});

// Before each test in spec
Expand Down
29 changes: 29 additions & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import "./commands";

declare global {
namespace Cypress {
interface Chainable {
/**
* Custom command to select DOM element by data-cy attribute.
* @example cy.dataCy('greeting')
*/
waitOn(path: string, cb: () => void): Chainable<JQuery<HTMLElement>>;
login(): Chainable<JQuery<HTMLElement>>;
getBySelector(
selector: string,
...args: any[]
): Chainable<JQuery<HTMLElement>>;
blockLock(): Chainable<JQuery<HTMLElement>>;
assertClipboardValue(value: string): Chainable<JQuery<HTMLElement>>;
blockAnnouncements(): Chainable<JQuery<HTMLElement>>;
apiRequest(
options: Partial<Cypress.RequestOptions>
): Chainable<Cypress.Response<any>>;
workflowStatusLabelCleanUp(): Chainable<JQuery<HTMLElement>>;
cleanTestData(): Chainable<JQuery<HTMLElement>>;
createTestData(): Chainable<JQuery<HTMLElement>>;
goToWorkflowsPage(): Chainable<JQuery<HTMLElement>>;
getStatusLabel(): Chainable<JQuery<HTMLElement>>;
}
}
}

0 comments on commit c0c19e2

Please sign in to comment.