Skip to content

Commit c0c19e2

Browse files
committed
cypress-test-config-experimental
1 parent 08ab081 commit c0c19e2

File tree

7 files changed

+117
-76
lines changed

7 files changed

+117
-76
lines changed

Diff for: cypress.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ module.exports = defineConfig({
2828
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
2929
testIsolation: false,
3030
},
31-
defaultCommandTimeout: 30_000,
31+
requestTimeout: 60_000,
3232
responseTimeout: 60_000,
3333
retries: 1,
3434
experimentalMemoryManagement: true,
35-
chromeWebSecurity: false,
3635
});

Diff for: cypress/e2e/content/actions.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe("Actions in content editor", () => {
122122
cy.getBySelector("ConfirmPublishButton").click();
123123

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

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

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

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

333-
cy.contains("Created Item", { timeout: 5000 }).should("exist");
333+
cy.contains("Created Item", { timeout: 30_000 }).should("exist");
334334
});
335335
});

Diff for: cypress/e2e/content/workflows.spec.js

+26-51
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import ContentItemPage from "./pages/ContentItemPage";
2-
import SettingsPage from "../settings/pages/SettingsPage";
3-
import instanceZUID from "../../../src/utility/instanceZUID";
42
import CONFIG from "../../../src/shell/app.config";
5-
import {
6-
AUTHORIZED_ROLES,
7-
colorMenu,
8-
} from "../../../src/apps/settings/src/app/views/User/Workflows/constants";
9-
10-
const INSTANCE_API = `${
11-
CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE_PROTOCOL
12-
}${instanceZUID}${CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE}`;
3+
import instanceZUID from "../../../src/utility/instanceZUID";
134

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

8273
after(() => {
8374
// Delete test content item
84-
// ContentItemPage.elements.moreMenu().should("exist").click();
85-
// ContentItemPage.elements.deleteItemButton().should("exist").click();
86-
// ContentItemPage.elements.confirmDeleteItemButton().should("exist").click();
87-
// cy.intercept("DELETE", "**/content/models/6-b6cde1aa9f-wftv50/items/*").as(
88-
// "deleteContentItem"
89-
// );
90-
// cy.wait("@deleteContentItem");
91-
92-
// // Delete allow publish label after test
93-
// SettingsPage.deactivateWorkflowLabel(TITLES.testLabel);
94-
// cy.get(
95-
// '[data-cy="active-labels-container"] [data-cy="status-label"]:visible'
96-
// )
97-
// .contains("Random Test Label")
98-
// .should("not.exist");
99-
// SettingsPage.deactivateWorkflowLabel(TITLES.publishLabel);
100-
// cy.get(
101-
// '[data-cy="active-labels-container"] [data-cy="status-label"]:visible'
102-
// )
103-
// .contains("Publish Approval")
104-
// .should("not.exist");
105-
cy.cleanTestData();
75+
cy.location("pathname").then((loc) => {
76+
const [_, __, modelZUID, itemZUID] = loc?.split("/");
77+
cy.apiRequest({
78+
method: "DELETE",
79+
url: `${INSTANCE_API}/content/models/${modelZUID}/items/${itemZUID}`,
80+
});
81+
});
82+
83+
// Delete test labels
84+
cy.apiRequest({ url: `${INSTANCE_API}/env/labels?showDeleted=true` }).then(
85+
(response) => {
86+
response?.data
87+
?.filter(
88+
(label) =>
89+
!label?.deletedAt &&
90+
[TITLES.publishLabel, TITLES.testLabel].includes(label?.name)
91+
)
92+
.forEach((label) => {
93+
cy.apiRequest({
94+
url: `${INSTANCE_API}/env/labels/${label.ZUID}`,
95+
method: "DELETE",
96+
});
97+
});
98+
}
99+
);
106100
});
107101

108102
it("Can add a workflow label", () => {
@@ -202,22 +196,3 @@ describe("Content Item Workflows", () => {
202196
ContentItemPage.elements.contentPublishedIndicator().should("exist");
203197
});
204198
});
205-
206-
Cypress.Commands.add("cleanTestData", () => {
207-
const labelsToDelete = ["Random Test Label", "Publish Approval"];
208-
209-
cy.apiRequest({ url: `${INSTANCE_API}/env/labels?showDeleted=true` }).then(
210-
(response) => {
211-
response?.data
212-
?.filter(
213-
(label) => !label?.deletedAt && labelsToDelete.includes(label?.name)
214-
)
215-
.forEach((label) => {
216-
cy.apiRequest({
217-
url: `${INSTANCE_API}/env/labels/${label.ZUID}`,
218-
method: "DELETE",
219-
});
220-
});
221-
}
222-
);
223-
});

Diff for: cypress/e2e/settings/workflows.spec.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77

88
const TIMEOUT = { timeout: 40_000 };
99

10-
const INSTANCE_API = `${
10+
const INSTANCE_API_ENDPOINT = `${
1111
CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE_PROTOCOL
1212
}${instanceZUID}${CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE}`;
1313

@@ -474,27 +474,25 @@ Cypress.Commands.add("cleanTestData", function () {
474474
TEST_DATA?.temp3?.name,
475475
];
476476

477-
cy.apiRequest({ url: `${INSTANCE_API}/env/labels?showDeleted=true` }).then(
478-
(response) => {
479-
response?.data
480-
?.filter(
481-
(label) => !label?.deletedAt && testLabels.includes(label?.name)
482-
)
483-
.forEach((label) => {
484-
cy.apiRequest({
485-
url: `${INSTANCE_API}/env/labels/${label.ZUID}`,
486-
method: "DELETE",
487-
});
477+
cy.apiRequest({
478+
url: `${INSTANCE_API_ENDPOINT}/env/labels?showDeleted=true`,
479+
}).then((response) => {
480+
response?.data
481+
?.filter((label) => !label?.deletedAt && testLabels.includes(label?.name))
482+
.forEach((label) => {
483+
cy.apiRequest({
484+
url: `${INSTANCE_API_ENDPOINT}/env/labels/${label.ZUID}`,
485+
method: "DELETE",
488486
});
489-
}
490-
);
487+
});
488+
});
491489
});
492490

493491
Cypress.Commands.add("createTestData", () => {
494492
const testLabels = [TEST_DATA?.temp1, TEST_DATA?.temp2, TEST_DATA?.temp3];
495493
testLabels.forEach((label) => {
496494
cy.apiRequest({
497-
url: `${INSTANCE_API}/env/labels`,
495+
url: `${INSTANCE_API_ENDPOINT}/env/labels`,
498496
method: "POST",
499497
body: {
500498
...label,
@@ -507,7 +505,7 @@ Cypress.Commands.add("createTestData", () => {
507505
Cypress.Commands.add("getStatusLabels", () => {
508506
return cy
509507
.apiRequest({
510-
url: `${INSTANCE_API}/env/labels?showDeleted=true`,
508+
url: `${INSTANCE_API_ENDPOINT}/env/labels?showDeleted=true`,
511509
})
512510
.then((response) => {
513511
return parseStatusLabels(response?.data);

Diff for: cypress/support/commands.js

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
import instanceZUID from "../../src/utility/instanceZUID";
2+
import CONFIG from "../../src/shell/app.config";
3+
4+
const INSTANCE_API_ENDPOINT = `${
5+
CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE_PROTOCOL
6+
}${instanceZUID}${CONFIG?.[process.env.NODE_ENV]?.API_INSTANCE}`;
7+
8+
const DEFAULT_STATUS_LABELS_ZUIDS = [
9+
"36-14b315-4pp20v3d",
10+
"36-14b315-d24ft",
11+
"36-n33d5-23v13w",
12+
];
13+
14+
const DEFAULT_STATUS_LABELS_NAMES = ["Approved", "Needs Review", "Draft"];
15+
116
Cypress.Commands.add("login", () => {
217
const formBody = new FormData();
318

@@ -8,14 +23,16 @@ Cypress.Commands.add("login", () => {
823
.request({
924
url: `${Cypress.env("API_AUTH")}/login`,
1025
method: "POST",
11-
credentials: "include",
1226
body: formBody,
1327
})
1428
.then(async (res) => {
1529
const response = await new Response(res.body).json();
1630
// We need the cookie value returned reset so it is unsecure and
1731
// accessible by javascript
1832
cy.setCookie(Cypress.env("COOKIE_NAME"), response.meta.token);
33+
})
34+
.then(() => {
35+
return cy.get("body");
1936
});
2037
});
2138

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

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

4966
Cypress.Commands.add("blockAnnouncements", () => {
@@ -71,3 +88,25 @@ Cypress.Commands.add(
7188
});
7289
}
7390
);
91+
92+
Cypress.Commands.add("workflowStatusLabelCleanUp", function () {
93+
cy.apiRequest({
94+
url: `${INSTANCE_API_ENDPOINT}/env/labels?showDeleted=true`,
95+
}).then((response) => {
96+
console.debug("workflowStatusLabelCleanUp | response LABELS: ", response);
97+
98+
response?.data
99+
?.filter(
100+
(label) =>
101+
!label?.deletedAt &&
102+
!DEFAULT_STATUS_LABELS_NAMES.includes(label?.name) &&
103+
!DEFAULT_STATUS_LABELS_ZUIDS.includes(label?.ZUID)
104+
)
105+
.forEach((label) => {
106+
cy.apiRequest({
107+
url: `${INSTANCE_API_ENDPOINT}/env/labels/${label.ZUID}`,
108+
method: "DELETE",
109+
});
110+
});
111+
});
112+
});

Diff for: cypress/support/e2e.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ before(() => {
4545

4646
// Blocks the api call to render the announcement popup
4747
cy.blockAnnouncements();
48+
cy.workflowStatusLabelCleanUp();
4849
});
4950

5051
// Before each test in spec

Diff for: cypress/support/index.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import "./commands";
2+
3+
declare global {
4+
namespace Cypress {
5+
interface Chainable {
6+
/**
7+
* Custom command to select DOM element by data-cy attribute.
8+
* @example cy.dataCy('greeting')
9+
*/
10+
waitOn(path: string, cb: () => void): Chainable<JQuery<HTMLElement>>;
11+
login(): Chainable<JQuery<HTMLElement>>;
12+
getBySelector(
13+
selector: string,
14+
...args: any[]
15+
): Chainable<JQuery<HTMLElement>>;
16+
blockLock(): Chainable<JQuery<HTMLElement>>;
17+
assertClipboardValue(value: string): Chainable<JQuery<HTMLElement>>;
18+
blockAnnouncements(): Chainable<JQuery<HTMLElement>>;
19+
apiRequest(
20+
options: Partial<Cypress.RequestOptions>
21+
): Chainable<Cypress.Response<any>>;
22+
workflowStatusLabelCleanUp(): Chainable<JQuery<HTMLElement>>;
23+
cleanTestData(): Chainable<JQuery<HTMLElement>>;
24+
createTestData(): Chainable<JQuery<HTMLElement>>;
25+
goToWorkflowsPage(): Chainable<JQuery<HTMLElement>>;
26+
getStatusLabel(): Chainable<JQuery<HTMLElement>>;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)