dashboard demo tests (#3431)

* dashboard demo tests
This commit is contained in:
wojteknowacki 2023-04-05 09:09:53 +02:00 committed by GitHub
parent aa2031eac3
commit fc1c367eaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 77 additions and 4 deletions

View file

@ -0,0 +1,43 @@
/// <reference types="cypress"/>
/// <reference types="../../support"/>
import {
BUTTON_SELECTORS,
HOMEPAGE_SELECTORS,
SHARED_ELEMENTS,
} from "../../elements";
import { orderDraftCreateDemoResponse, urlList } from "../../fixtures";
import { ordersOperationsHelpers } from "../../support/pages";
describe("Dashboard demo site tests", () => {
it("should be able to log in via UI", { tags: ["@demo-dashboard"] }, () => {
cy.addAliasToGraphRequest("Home")
.visit("/")
.get(BUTTON_SELECTORS.submit)
.should("be.visible")
.click()
.waitForRequestAndCheckIfNoErrors("@Home");
cy.get(SHARED_ELEMENTS.notificationMessage).should("have.length", 1);
cy.get(HOMEPAGE_SELECTORS.welcomeMessage).should("be.visible");
cy.get(SHARED_ELEMENTS.notificationMessage).should("not.exist");
});
it(
"should not be able to create new order",
{ tags: ["@demo-dashboard"] },
() => {
cy.addAliasToGraphRequest("OrderList");
cy.loginUserViaRequest().then(() => {
cy.visit(`${urlList.orders}`).waitForRequestAndCheckIfNoErrors(
"@OrderList",
);
ordersOperationsHelpers.pickAndSelectChannelOnCreateOrderFormByIndex(1);
cy.addAliasToGraphRequest("OrderDraftCreate")
.clickSubmitButton()
.waitForRequestAndErrorMessage(
"@OrderDraftCreate",
orderDraftCreateDemoResponse,
);
cy.get(SHARED_ELEMENTS.notificationMessage).should("exist");
});
},
);
});

View file

@ -1,3 +1,4 @@
import { CHANNEL_FORM_SELECTORS } from "./channel-form-selectors";
import { CHANNELS_SELECTORS } from "./channels-selectors";
export { CHANNELS_SELECTORS };
export { CHANNEL_FORM_SELECTORS, CHANNELS_SELECTORS };

View file

@ -12,7 +12,7 @@ import {
PRODUCT_DETAILS,
PRODUCTS_LIST,
} from "./catalog";
import { CHANNELS_SELECTORS } from "./channels";
import { CHANNEL_FORM_SELECTORS, CHANNELS_SELECTORS } from "./channels";
import { CONFIGURATION_SELECTORS } from "./configuration/configuration-selectors";
import {
CUSTOMER_DETAILS_SELECTORS,
@ -53,6 +53,7 @@ export {
BUTTON_SELECTORS,
CATEGORIES_LIST_SELECTORS,
CATEGORY_DETAILS_SELECTORS,
CHANNEL_FORM_SELECTORS,
CHANNELS_SELECTORS,
COLLECTION_SELECTORS,
CONFIGURATION_SELECTORS,

View file

@ -10,6 +10,7 @@ export const SHARED_ELEMENTS = {
notificationSuccess:
'[data-test-id="notification"][data-test-type="success"]',
notificationFailure: '[data-test-id="notification"][data-test-type="error"]',
notificationMessage: '[data-test-id="notification-message"]',
dialog: '[role="dialog"]',
searchInput: '[data-test-id="search-input"]',
selectOption: '[data-test-id*="select-field-option"]',

View file

@ -0,0 +1 @@
export const orderDraftCreateDemoResponse = "API runs in read-only mode!";

View file

@ -1,3 +1,5 @@
import { bodyMockHomePage } from "./bodyMocks";
import { orderDraftCreateDemoResponse } from "./errors/demo/orderDratCreate";
import { urlList } from "./urlList";
export { bodyMockHomePage };
export { bodyMockHomePage, orderDraftCreateDemoResponse, urlList };

View file

@ -27,6 +27,12 @@ Cypress.Commands.add("waitForRequestAndCheckIfNoErrors", alias => {
return resp;
});
});
Cypress.Commands.add("waitForRequestAndErrorMessage", (alias, error) => {
cy.wait(alias).then(resp => {
expect(resp.response.body.errors[0].message).to.contains(error);
return resp;
});
});
Cypress.Commands.add("checkIfDataAreNotNull", data => {
expect(data, "Created data should not be null").to.be.not.null;

View file

@ -17,6 +17,9 @@ Cypress.Commands.add("clickNextPagePaginationButton", () =>
Cypress.Commands.add("clickPrevPagePaginationButton", () =>
cy.get(PAGINATION.previousPagePaginationButton),
);
Cypress.Commands.add("clickSubmitButton", () =>
cy.get(BUTTON_SELECTORS.submit).click(),
);
Cypress.Commands.add("createNewOption", (selectSelector, newOption) => {
cy.get(selectSelector).type(newOption);

View file

@ -31,7 +31,6 @@ Cypress.Commands.add(
const mutation = `mutation TokenAuth{
tokenCreate(email: "${user.email}", password: "${user.password}") {
token
csrfToken
refreshToken
errors: errors {
code

View file

@ -48,6 +48,7 @@ Cypress.Commands.add("addAliasToGraphRequest", operationName => {
}
});
});
Cypress.Commands.add(
"addAliasToGraphRequestAndUseMockedResponseBody",
(operationName, bodyMock) => {

View file

@ -0,0 +1,3 @@
import * as ordersOperationsHelpers from "./ordersOperations";
export { ordersOperationsHelpers };

View file

@ -0,0 +1,11 @@
import { CHANNEL_FORM_SELECTORS, ORDERS_SELECTORS } from "../../elements";
export function pickAndSelectChannelOnCreateOrderFormByIndex(index) {
cy.get(ORDERS_SELECTORS.createOrderButton)
.click()
.get(CHANNEL_FORM_SELECTORS.channelSelect)
.click()
.get(CHANNEL_FORM_SELECTORS.channelOption)
.eq(index)
.click();
}

View file

@ -304,6 +304,7 @@
"cy:run:allEnv:parallel": "cypress run --record --env grepTags=@allEnv --parallel",
"cy:run:stable:parallel": "cypress run --record --env grepTags=@critical --parallel --tag Stable",
"cy:percy": "CYPRESS_demoTests=true percy exec -- npm run cy:run",
"cy:run:demo": "CYPRESS_demoTests=true npm run cy:run",
"test": "jest src/",
"test:watch": "jest --watch src/",
"lint": "eslint \"src/**/*.@(tsx|ts|jsx|js)\" --fix",