From fc1c367eafc53f62376af5f9f9520a72ae83098f Mon Sep 17 00:00:00 2001
From: wojteknowacki <124166231+wojteknowacki@users.noreply.github.com>
Date: Wed, 5 Apr 2023 09:09:53 +0200
Subject: [PATCH] dashboard demo tests (#3431)
* dashboard demo tests
---
cypress/e2e/demo/demoDashboard.js | 43 +++++++++++++++++++
cypress/elements/channels/index.js | 3 +-
cypress/elements/index.js | 3 +-
cypress/elements/shared/sharedElements.js | 1 +
.../fixtures/errors/demo/orderDratCreate.js | 1 +
cypress/fixtures/index.js | 4 +-
.../customCommands/basicOperations/index.js | 6 +++
.../sharedElementsOperations/selects.js | 3 ++
cypress/support/customCommands/user/index.js | 1 -
cypress/support/e2e.js | 1 +
cypress/support/pages/index.js | 3 ++
cypress/support/pages/ordersOperations.js | 11 +++++
package.json | 1 +
13 files changed, 77 insertions(+), 4 deletions(-)
create mode 100644 cypress/e2e/demo/demoDashboard.js
create mode 100644 cypress/fixtures/errors/demo/orderDratCreate.js
create mode 100644 cypress/support/pages/index.js
create mode 100644 cypress/support/pages/ordersOperations.js
diff --git a/cypress/e2e/demo/demoDashboard.js b/cypress/e2e/demo/demoDashboard.js
new file mode 100644
index 000000000..4c22e74db
--- /dev/null
+++ b/cypress/e2e/demo/demoDashboard.js
@@ -0,0 +1,43 @@
+///
+///
+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");
+ });
+ },
+ );
+});
diff --git a/cypress/elements/channels/index.js b/cypress/elements/channels/index.js
index 9928cf9e4..a556c2fc9 100644
--- a/cypress/elements/channels/index.js
+++ b/cypress/elements/channels/index.js
@@ -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 };
diff --git a/cypress/elements/index.js b/cypress/elements/index.js
index 8f7d0056a..26b12f042 100644
--- a/cypress/elements/index.js
+++ b/cypress/elements/index.js
@@ -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,
diff --git a/cypress/elements/shared/sharedElements.js b/cypress/elements/shared/sharedElements.js
index f86a8b9f3..d92de3351 100644
--- a/cypress/elements/shared/sharedElements.js
+++ b/cypress/elements/shared/sharedElements.js
@@ -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"]',
diff --git a/cypress/fixtures/errors/demo/orderDratCreate.js b/cypress/fixtures/errors/demo/orderDratCreate.js
new file mode 100644
index 000000000..d69c8f6b4
--- /dev/null
+++ b/cypress/fixtures/errors/demo/orderDratCreate.js
@@ -0,0 +1 @@
+export const orderDraftCreateDemoResponse = "API runs in read-only mode!";
diff --git a/cypress/fixtures/index.js b/cypress/fixtures/index.js
index 5d6dd3608..c076821af 100644
--- a/cypress/fixtures/index.js
+++ b/cypress/fixtures/index.js
@@ -1,3 +1,5 @@
import { bodyMockHomePage } from "./bodyMocks";
+import { orderDraftCreateDemoResponse } from "./errors/demo/orderDratCreate";
+import { urlList } from "./urlList";
-export { bodyMockHomePage };
+export { bodyMockHomePage, orderDraftCreateDemoResponse, urlList };
diff --git a/cypress/support/customCommands/basicOperations/index.js b/cypress/support/customCommands/basicOperations/index.js
index be42bb8a9..857521095 100644
--- a/cypress/support/customCommands/basicOperations/index.js
+++ b/cypress/support/customCommands/basicOperations/index.js
@@ -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;
diff --git a/cypress/support/customCommands/sharedElementsOperations/selects.js b/cypress/support/customCommands/sharedElementsOperations/selects.js
index e806119a0..f69243fb8 100644
--- a/cypress/support/customCommands/sharedElementsOperations/selects.js
+++ b/cypress/support/customCommands/sharedElementsOperations/selects.js
@@ -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);
diff --git a/cypress/support/customCommands/user/index.js b/cypress/support/customCommands/user/index.js
index cce4adf64..a31f24b68 100644
--- a/cypress/support/customCommands/user/index.js
+++ b/cypress/support/customCommands/user/index.js
@@ -31,7 +31,6 @@ Cypress.Commands.add(
const mutation = `mutation TokenAuth{
tokenCreate(email: "${user.email}", password: "${user.password}") {
token
- csrfToken
refreshToken
errors: errors {
code
diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js
index 1681c7452..9f4717b53 100644
--- a/cypress/support/e2e.js
+++ b/cypress/support/e2e.js
@@ -48,6 +48,7 @@ Cypress.Commands.add("addAliasToGraphRequest", operationName => {
}
});
});
+
Cypress.Commands.add(
"addAliasToGraphRequestAndUseMockedResponseBody",
(operationName, bodyMock) => {
diff --git a/cypress/support/pages/index.js b/cypress/support/pages/index.js
new file mode 100644
index 000000000..8abecf811
--- /dev/null
+++ b/cypress/support/pages/index.js
@@ -0,0 +1,3 @@
+import * as ordersOperationsHelpers from "./ordersOperations";
+
+export { ordersOperationsHelpers };
diff --git a/cypress/support/pages/ordersOperations.js b/cypress/support/pages/ordersOperations.js
new file mode 100644
index 000000000..1d2b2d6dd
--- /dev/null
+++ b/cypress/support/pages/ordersOperations.js
@@ -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();
+}
diff --git a/package.json b/package.json
index 8892c5238..fd0505d30 100644
--- a/package.json
+++ b/package.json
@@ -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",