saleor-dashboard/cypress/support/index.js
Karolina 0157914edb
Saleor 1740 tests for draft orders (#1002)
* first test for draft orders

* tests for channels in draft orders

* tests for channels in draft orders

* tests for channels in draft orders

* test for moving draft order to orders

* test for orders

* test for orders

* tests for draft orders

* tests for draft orders

* tests for draft orders

* tests for draft orders

* test for moving draft order
2021-03-15 14:16:02 +01:00

56 lines
1.4 KiB
JavaScript

import "./user";
import "./softAssertions";
import "./deleteElement/index.js";
import "./elements/index";
import { urlList } from "../url/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();
}
});
});
Cypress.Commands.add("addAliasToGraphRequest", operationName => {
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") =>
cy.request({
body: {
method: "POST",
query,
url: urlList.apiUri
},
headers: {
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`
},
method: "POST",
url: urlList.apiUri
})
);