From f847c76d67bde48094878d2fcd64475a5432f69d Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Thu, 15 Jul 2021 13:25:39 +0300 Subject: [PATCH] Saleor 3826 tests for customers (#1226) * added test for customers * add test for customer --- cypress/apiRequests/Customer.js | 30 +++++++++ cypress/elements/customer/customer-details.js | 6 ++ cypress/elements/customer/customers-list.js | 3 + .../allEnv/configuration/customer.js | 63 +++++++++++++++++++ .../allEnv/configuration/warehouse.js | 24 +------ cypress/steps/shared/addressForm.js | 6 +- cypress/support/softAssertions/index.js | 37 +++++++++++ cypress/url/urlList.js | 3 +- .../CustomerListPage/CustomerListPage.tsx | 7 ++- .../__snapshots__/Stories.test.ts.snap | 3 + 10 files changed, 157 insertions(+), 25 deletions(-) create mode 100644 cypress/elements/customer/customer-details.js create mode 100644 cypress/elements/customer/customers-list.js create mode 100644 cypress/integration/allEnv/configuration/customer.js diff --git a/cypress/apiRequests/Customer.js b/cypress/apiRequests/Customer.js index 9fb0c3207..71e62ec57 100644 --- a/cypress/apiRequests/Customer.js +++ b/cypress/apiRequests/Customer.js @@ -63,3 +63,33 @@ export function getCustomers(startsWith) { }`; return cy.sendRequestWithQuery(query); } + +export function getCustomer(customerId) { + const query = `query{ + user(id:"${customerId}"){ + id + email + firstName + lastName + isStaff + isActive + note + addresses{ + firstName + lastName + companyName + streetAddress1 + streetAddress2 + city + cityArea + postalCode + country{ + code + } + countryArea + phone + } + } + }`; + return cy.sendRequestWithQuery(query).its("body.data.user"); +} diff --git a/cypress/elements/customer/customer-details.js b/cypress/elements/customer/customer-details.js new file mode 100644 index 000000000..967f6cba2 --- /dev/null +++ b/cypress/elements/customer/customer-details.js @@ -0,0 +1,6 @@ +export const CUSTOMER_DETAILS = { + nameInput: '[name="customerFirstName"]', + lastNameInput: '[name="customerLastName"]', + emailInput: '[name="email"]', + noteInput: '[name="note"]' +}; diff --git a/cypress/elements/customer/customers-list.js b/cypress/elements/customer/customers-list.js new file mode 100644 index 000000000..cab9dd3bd --- /dev/null +++ b/cypress/elements/customer/customers-list.js @@ -0,0 +1,3 @@ +export const CUSTOMERS_LIST = { + createCustomerButton: '[data-test-id="createCustomer"]' +}; diff --git a/cypress/integration/allEnv/configuration/customer.js b/cypress/integration/allEnv/configuration/customer.js new file mode 100644 index 000000000..660d4460c --- /dev/null +++ b/cypress/integration/allEnv/configuration/customer.js @@ -0,0 +1,63 @@ +import faker from "faker"; + +import { getCustomer } from "../../../apiRequests/Customer"; +import { ONE_PERMISSION_USERS } from "../../../Data/users"; +import { CUSTOMER_DETAILS } from "../../../elements/customer/customer-details"; +import { CUSTOMERS_LIST } from "../../../elements/customer/customers-list"; +import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; +import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements"; +import { fillUpAddressForm } from "../../../steps/shared/addressForm"; +import { confirmationMessageShouldDisappear } from "../../../steps/shared/confirmationMessage"; +import { urlList } from "../../../url/urlList"; + +describe("Tests for customer", () => { + const channelStartsWith = `Customers`; + + it("should create customer", () => { + const randomName = `${channelStartsWith}${faker.datatype.number()}`; + const email = `${randomName}@example.com`; + const note = faker.lorem.paragraph(); + let address; + + cy.clearSessionData() + .loginUserViaRequest("auth", ONE_PERMISSION_USERS.user) + .visit(urlList.customers) + .get(CUSTOMERS_LIST.createCustomerButton) + .click() + .get(SHARED_ELEMENTS.progressBar) + .should("not.be.visible") + .get(CUSTOMER_DETAILS.nameInput) + .type(randomName) + .get(CUSTOMER_DETAILS.lastNameInput) + .type(randomName) + .get(CUSTOMER_DETAILS.emailInput) + .type(email) + .fixture("addresses") + .then(({ usAddress }) => { + address = usAddress; + fillUpAddressForm(address); + }) + .get(CUSTOMER_DETAILS.noteInput) + .type(note) + .addAliasToGraphRequest("CreateCustomer") + .get(BUTTON_SELECTORS.confirm) + .click(); + confirmationMessageShouldDisappear(); + cy.wait("@CreateCustomer") + .its("response.body.data.customerCreate.user") + .then(customer => { + getCustomer(customer.id); + }) + .then(customer => { + chai + .softExpect(customer.firstName, "Expect correct first name") + .to.eq(randomName); + chai + .softExpect(customer.lastName, "Expect correct last name") + .to.eq(randomName); + chai.softExpect(customer.email, "Expect correct email").to.eq(email); + chai.softExpect(customer.note, "Expect correct note").to.eq(note); + cy.expectCorrectFullAddress(customer.addresses[0], address); + }); + }); +}); diff --git a/cypress/integration/allEnv/configuration/warehouse.js b/cypress/integration/allEnv/configuration/warehouse.js index db2576cea..11f28c5c3 100644 --- a/cypress/integration/allEnv/configuration/warehouse.js +++ b/cypress/integration/allEnv/configuration/warehouse.js @@ -50,28 +50,8 @@ describe("Warehouse settings", () => { }) .then(warehouse => { const addressResp = warehouse.address; - expect(warehouse.name).to.be.eq(name); - expect(addressResp).to.have.property( - "city", - usAddress.city.toUpperCase() - ); - expect(addressResp).to.have.property( - "countryArea", - usAddress.countryArea - ); - expect(addressResp).to.have.property("phone", usAddress.phone); - expect(addressResp).to.have.property( - "postalCode", - usAddress.postalCode - ); - expect(addressResp).to.have.property( - "streetAddress1", - usAddress.streetAddress1 - ); - expect(addressResp).to.have.property( - "streetAddress2", - usAddress.streetAddress2 - ); + chai.softExpect(warehouse.name).to.be.eq(name); + cy.expectCorrectBasicAddress(addressResp, usAddress); }); }); diff --git a/cypress/steps/shared/addressForm.js b/cypress/steps/shared/addressForm.js index 779bf4b45..812f158d7 100644 --- a/cypress/steps/shared/addressForm.js +++ b/cypress/steps/shared/addressForm.js @@ -2,13 +2,17 @@ import { ADDRESS_SELECTORS } from "../../elements/shared/addressForm"; import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; import { fillAutocompleteSelect } from "./selects"; +export function fillUpAddressFormAndSubmit(address) { + fillUpAddressForm(); + cy.get(BUTTON_SELECTORS.submit).click(); +} + export function fillUpAddressForm(address) { cy.get(ADDRESS_SELECTORS.firstName) .type(address.firstName) .get(ADDRESS_SELECTORS.lastName) .type(address.lastName); fillUpBasicAddress(address); - cy.get(BUTTON_SELECTORS.submit).click(); } export function fillUpBasicAddress(address) { diff --git a/cypress/support/softAssertions/index.js b/cypress/support/softAssertions/index.js index 93e7e0f11..811d290e5 100644 --- a/cypress/support/softAssertions/index.js +++ b/cypress/support/softAssertions/index.js @@ -91,3 +91,40 @@ Cypress.Commands.add("softAssertVisibility", selector => { chai.softExpect(element, "element should be visible").to.be.visible ); }); + +Cypress.Commands.add( + "expectCorrectBasicAddress", + (responseAddress, expectedAddress) => { + chai + .softExpect(responseAddress) + .to.have.property("city", expectedAddress.city.toUpperCase()); + chai + .softExpect(responseAddress) + .to.have.property("countryArea", expectedAddress.countryArea); + chai + .softExpect(responseAddress) + .to.have.property("phone", expectedAddress.phone); + chai + .softExpect(responseAddress) + .to.have.property("postalCode", expectedAddress.postalCode); + chai + .softExpect(responseAddress) + .to.have.property("streetAddress1", expectedAddress.streetAddress1); + chai + .softExpect(responseAddress) + .to.have.property("streetAddress2", expectedAddress.streetAddress2); + } +); + +Cypress.Commands.add( + "expectCorrectFullAddress", + (responseAddress, expectedAddress) => { + chai + .softExpect(responseAddress) + .to.have.property("firstName", expectedAddress.firstName); + chai + .softExpect(responseAddress) + .to.have.property("firstName", expectedAddress.lastName); + cy.expectCorrectBasicAddress(responseAddress, expectedAddress); + } +); diff --git a/cypress/url/urlList.js b/cypress/url/urlList.js index 8e02d49c3..8c6b5075b 100644 --- a/cypress/url/urlList.js +++ b/cypress/url/urlList.js @@ -16,7 +16,8 @@ export const urlList = { permissionsGroups: "permission-groups/", weightRete: "weight/", attributes: "attributes/", - productTypes: "product-types/" + productTypes: "product-types/", + customers: "customers/" }; export const productDetailsUrl = productId => `${urlList.products}${productId}`; diff --git a/src/customers/components/CustomerListPage/CustomerListPage.tsx b/src/customers/components/CustomerListPage/CustomerListPage.tsx index 65c4c2fb6..a59da2222 100644 --- a/src/customers/components/CustomerListPage/CustomerListPage.tsx +++ b/src/customers/components/CustomerListPage/CustomerListPage.tsx @@ -52,7 +52,12 @@ const CustomerListPage: React.FC = ({ return ( -