From 0ec88cdb1ecd408357b392f2878d1a0a4234da58 Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Tue, 20 Jul 2021 13:59:23 +0300 Subject: [PATCH] all tests for site settings (#1236) --- cypress/apiRequests/shopSettings.js | 41 ++++++++++ .../siteSettings/site-settings-details.js | 5 ++ .../allEnv/configuration/siteSettings.js | 78 +++++++++++++++++++ cypress/steps/shared/addressForm.js | 14 ++-- cypress/url/urlList.js | 2 +- 5 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 cypress/elements/siteSettings/site-settings-details.js create mode 100644 cypress/integration/allEnv/configuration/siteSettings.js diff --git a/cypress/apiRequests/shopSettings.js b/cypress/apiRequests/shopSettings.js index cb0d48bc8..f38c10b2f 100644 --- a/cypress/apiRequests/shopSettings.js +++ b/cypress/apiRequests/shopSettings.js @@ -1,3 +1,5 @@ +import { getDefaultAddress } from "./utils/Utils"; + export function updateShopWeightUnit(weightUnit) { const mutation = `mutation{ shopSettingsUpdate(input:{ @@ -14,3 +16,42 @@ export function updateShopWeightUnit(weightUnit) { }`; return cy.sendRequestWithQuery(mutation).its("body.data.shopSettingsUpdate"); } + +export function updateShopAddress(address) { + const input = getDefaultAddress(address, "input"); + const mutation = `mutation{ + shopAddressUpdate(${input}){ + errors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); +} + +export function getShopInfo() { + const query = `query{ + shop{ + name + domain{ + host + } + description + companyAddress{ + companyName + streetAddress1 + streetAddress2 + city + cityArea + postalCode + country{ + code + } + countryArea + phone + } + } + }`; + return cy.sendRequestWithQuery(query).its("body.data.shop"); +} diff --git a/cypress/elements/siteSettings/site-settings-details.js b/cypress/elements/siteSettings/site-settings-details.js new file mode 100644 index 000000000..04bda8c53 --- /dev/null +++ b/cypress/elements/siteSettings/site-settings-details.js @@ -0,0 +1,5 @@ +export const SITE_SETTINGS_DETAILS = { + nameInput: '[name="name"]', + urlInput: '[name="domain"]', + descriptionInput: '[name="description"]' +}; diff --git a/cypress/integration/allEnv/configuration/siteSettings.js b/cypress/integration/allEnv/configuration/siteSettings.js new file mode 100644 index 000000000..bb7f4487e --- /dev/null +++ b/cypress/integration/allEnv/configuration/siteSettings.js @@ -0,0 +1,78 @@ +import faker from "faker"; + +import { + getShopInfo, + updateShopAddress +} from "../../../apiRequests/shopSettings"; +import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; +import { SITE_SETTINGS_DETAILS } from "../../../elements/siteSettings/site-settings-details"; +import { fillUpBasicAddress } from "../../../steps/shared/addressForm"; +import { confirmationMessageShouldDisappear } from "../../../steps/shared/confirmationMessage"; +import { urlList } from "../../../url/urlList"; + +describe("Tests for site settings", () => { + let address; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + cy.fixture("addresses").then(({ usAddress, plAddress }) => { + address = usAddress; + updateShopAddress(plAddress); + }); + }); + + beforeEach(() => { + cy.clearSessionData() + .loginUserViaRequest() + .visit(urlList.siteSettings); + }); + + it("should change store name", () => { + const name = `Cypress-${faker.datatype.number()}`; + + cy.get(SITE_SETTINGS_DETAILS.nameInput) + .clearAndType(name) + .get(BUTTON_SELECTORS.confirm) + .click(); + confirmationMessageShouldDisappear(); + getShopInfo().then(shopInfo => { + expect(shopInfo.name).to.eq(name); + }); + }); + + it("should change site url", () => { + const url = `http://cypress${faker.datatype.number()}.saleor.com`; + + cy.get(SITE_SETTINGS_DETAILS.urlInput) + .clearAndType(url) + .get(BUTTON_SELECTORS.confirm) + .click(); + confirmationMessageShouldDisappear(); + getShopInfo().then(shopInfo => { + expect(shopInfo.domain.host).to.eq(url); + }); + }); + + it("should change store description", () => { + const description = faker.lorem.sentence(); + + cy.get(SITE_SETTINGS_DETAILS.descriptionInput) + .clearAndType(description) + .get(BUTTON_SELECTORS.confirm) + .click(); + confirmationMessageShouldDisappear(); + getShopInfo().then(shopInfo => { + expect(shopInfo.description).to.eq(description); + }); + }); + + it("should change store address", () => { + fillUpBasicAddress(address); + cy.get(BUTTON_SELECTORS.confirm).click(); + confirmationMessageShouldDisappear(); + getShopInfo().then(({ companyAddress }) => { + expect(companyAddress.companyName).to.eq(address.companyName); + cy.expectCorrectBasicAddress(companyAddress, address); + }); + }); +}); diff --git a/cypress/steps/shared/addressForm.js b/cypress/steps/shared/addressForm.js index 812f158d7..8349a93c8 100644 --- a/cypress/steps/shared/addressForm.js +++ b/cypress/steps/shared/addressForm.js @@ -17,17 +17,17 @@ export function fillUpAddressForm(address) { export function fillUpBasicAddress(address) { cy.get(ADDRESS_SELECTORS.companyName) - .type(address.companyName) + .clearAndType(address.companyName) .get(ADDRESS_SELECTORS.phone) - .type(address.phone) + .clearAndType(address.phone) .get(ADDRESS_SELECTORS.streetAddress1) - .type(address.streetAddress1) + .clearAndType(address.streetAddress1) .get(ADDRESS_SELECTORS.streetAddress2) - .type(address.streetAddress2) + .clearAndType(address.streetAddress2) .get(ADDRESS_SELECTORS.city) - .type(address.city) + .clearAndType(address.city) .get(ADDRESS_SELECTORS.postalCode) - .type(address.postalCode); + .clearAndType(address.postalCode); fillAutocompleteSelect(ADDRESS_SELECTORS.country, address.countryFullName); - cy.get(ADDRESS_SELECTORS.countryArea).type(address.countryArea); + cy.get(ADDRESS_SELECTORS.countryArea).clearAndType(address.countryArea); } diff --git a/cypress/url/urlList.js b/cypress/url/urlList.js index a9c03bd5d..016df3ae0 100644 --- a/cypress/url/urlList.js +++ b/cypress/url/urlList.js @@ -17,9 +17,9 @@ export const urlList = { permissionsGroups: "permission-groups/", products: "products/", productTypes: "product-types/", - shippingMethods: "shipping/", sales: "discounts/sales/", shippingMethods: "shipping/", + siteSettings: "site-settings/", staffMembers: "staff/", vouchers: "discounts/vouchers/", warehouses: "warehouses/",