saleor-dashboard/cypress/support/index.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

// / <reference types="cypress" />
import "./customCommands/user";
import "./customCommands/basicOperations";
import "./customCommands/deleteElementsViaApi";
import "./customCommands/softAssertions";
import "./customCommands/sharedElementsOperations/addressForm.js";
import "./customCommands/sharedElementsOperations/assignElementsForm.js";
import "./customCommands/sharedElementsOperations/confirmationMessages.js";
import "./customCommands/sharedElementsOperations/progressBar.js";
import "./customCommands/sharedElementsOperations/selects.js";
import "./customCommands/sharedElementsOperations/tables";
2022-01-14 10:08:25 +00:00
import "./customCommands/sharedElementsOperations/deleteElement";
import "cypress-mailhog";
import "cypress-file-upload";
import "cypress-mochawesome-reporter/register";
import { commandTimings } from "cypress-timings";
commandTimings();
import { urlList } from "../fixtures/urlList";
Cypress.Commands.add("clearSessionData", () => {
// Because of known cypress bug, not all local storage data are cleared.
// Here is workaround to ensure tests have no side effects.
// Suggested usage:
// beforeEach(() => {
// cy.clearSessionData();
// });
cy.clearCookies();
cy.clearLocalStorage();
cy.visit(urlList.homePage, {
onBeforeLoad: win => {
win.sessionStorage.clear();
}
});
});
2021-01-27 09:41:55 +00:00
2021-02-23 12:09:58 +00:00
Cypress.Commands.add("addAliasToGraphRequest", operationName => {
2021-02-11 14:17:00 +00:00
cy.intercept("POST", urlList.apiUri, req => {
req.statusCode = 200;
const requestBody = req.body;
if (Array.isArray(requestBody)) {
requestBody.forEach(element => {
if (element.operationName === operationName) {
req.alias = operationName;
}
});
} else {
if (requestBody.operationName === operationName) {
req.alias = operationName;
}
}
});
});
Cypress.Commands.add("sendRequestWithQuery", (query, authorization = "auth") =>
2021-02-19 09:57:25 +00:00
cy.request({
body: {
method: "POST",
query,
url: urlList.apiUri
},
2021-01-27 09:41:55 +00:00
headers: {
2021-02-19 09:57:25 +00:00
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`
2021-01-27 09:41:55 +00:00
},
method: "POST",
url: urlList.apiUri
2021-01-27 09:41:55 +00:00
})
);
Cypress.on(
"uncaught:exception",
(err, runnable) =>
// returning false here prevents Cypress from
// failing the test
false
);