From 7c475669959a15bba66f486e3ae185c6263dab7a Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Fri, 11 Feb 2022 16:08:45 +0100 Subject: [PATCH] add tests for shipping for 3.1 (#1859) --- cypress/elements/giftCard/giftCardDialog.js | 18 +++ cypress/elements/shared/button-selectors.js | 4 +- .../shipping/shipping-rate-details.js | 4 +- .../elements/shipping/shipping-zones-list.js | 6 + .../shippingMethods/channelsInShipping.js | 23 ++-- .../shippingMethods/createShippingMethod.js | 116 +++++++++++++----- .../shippingMethods/editShippingMethod.js | 6 +- .../shippingMethods/editShippingZone.js | 27 +++- .../shippingMethods/postalCodes.js | 6 +- .../shippingWeights/shippingWeightsLimits.js | 6 +- .../shippingWeights/weightRecalculate.js | 8 +- cypress/support/pages/shippingMethodPage.js | 20 ++- cypress/support/pages/shippingZones.js | 63 ++++++++++ .../ShippingZonesList/ShippingZonesList.tsx | 6 +- src/shipping/views/ShippingZonesList.tsx | 1 + .../__snapshots__/Stories.test.ts.snap | 20 +++ 16 files changed, 263 insertions(+), 71 deletions(-) create mode 100644 cypress/elements/giftCard/giftCardDialog.js create mode 100644 cypress/support/pages/shippingZones.js diff --git a/cypress/elements/giftCard/giftCardDialog.js b/cypress/elements/giftCard/giftCardDialog.js new file mode 100644 index 000000000..50f647eef --- /dev/null +++ b/cypress/elements/giftCard/giftCardDialog.js @@ -0,0 +1,18 @@ +export const GIFT_CARD_DIALOG = { + amountInput: '[name="balanceAmount"]', + currencySelectButton: '[id="mui-component-select-balanceCurrency"]', + currenciesOptions: '[data-test-id="select-field-option"]', + expirationOptions: { + setExpiryDateCheckbox: '[name="expirySelected"]', + neverExpireRadioButton: '[value="NEVER_EXPIRE"]', + expiryPeriodRadioButton: '[value="EXPIRY_PERIOD"]', + expiryDateRadioButton: '[value="EXPIRY_DATE"]', + expiryPeriodAmount: '[name="expiryPeriodAmount"]', + expiryPeriodTypeButton: '[id*="select-expiryPeriodType"]', + expiryPeriodMonthType: '[data-test-id="MONTH"]', + expiryDateInput: '[name="expiryDate"]' + }, + noteInput: '[name="note"]', + cardCodeText: '[data-test-id="cardCode"]', + tagInput: '[data-test-id="gift-card-tag-select-field"]' +}; diff --git a/cypress/elements/shared/button-selectors.js b/cypress/elements/shared/button-selectors.js index 4f944fbae..fa51b054d 100644 --- a/cypress/elements/shared/button-selectors.js +++ b/cypress/elements/shared/button-selectors.js @@ -13,5 +13,7 @@ export const BUTTON_SELECTORS = { deleteIcon: '[data-test-id="delete-icon"]', showMoreButton: '[data-test-id="show-more-button"]', button: "button", - deleteAssignedItemsConsentCheckbox: '[name="delete-assigned-items-consent"]' + deleteAssignedItemsConsentCheckbox: '[name="delete-assigned-items-consent"]', + deleteSelectedElementsButton: + '[data-test-id = "delete-selected-elements-icon"]' }; diff --git a/cypress/elements/shipping/shipping-rate-details.js b/cypress/elements/shipping/shipping-rate-details.js index 59da1e618..320730eb8 100644 --- a/cypress/elements/shipping/shipping-rate-details.js +++ b/cypress/elements/shipping/shipping-rate-details.js @@ -8,8 +8,8 @@ export const SHIPPING_RATE_DETAILS = { min: '[name="min"]', max: '[name="max"]' }, - maxWeightInput: '[name*="maxValue"]', - minWeightInput: '[name*="minValue"]', + maxValueInput: '[name*="maxValue"]', + minValueInput: '[name*="minValue"]', minDeliveryTimeInput: '[name="minDays"]', maxDeliveryTimeInput: '[name="maxDays"]', restrictWeightLimitCheckbox: '[name="orderValueRestricted"]' diff --git a/cypress/elements/shipping/shipping-zones-list.js b/cypress/elements/shipping/shipping-zones-list.js index 69c24a374..c7ee511a2 100644 --- a/cypress/elements/shipping/shipping-zones-list.js +++ b/cypress/elements/shipping/shipping-zones-list.js @@ -3,3 +3,9 @@ export const SHIPPING_ZONES_LIST = { unitSelect: "[id='mui-component-select-unit']", saveUnit: '[data-test-id="save-unit"]' }; + +export const SHIPPING_ZONE_CHECKBOX = shippingId => + `[data-test-id="${shippingId}-checkbox"]`; + +export const SHIPPING_ZONE_NAME = shippingId => + `[data-test-id="${shippingId}-name"]`; diff --git a/cypress/integration/configuration/shippingMethods/channelsInShipping.js b/cypress/integration/configuration/shippingMethods/channelsInShipping.js index 73ca4429e..46802bc75 100644 --- a/cypress/integration/configuration/shippingMethods/channelsInShipping.js +++ b/cypress/integration/configuration/shippingMethods/channelsInShipping.js @@ -5,7 +5,6 @@ import faker from "faker"; import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements"; import { SHIPPING_ZONE_DETAILS } from "../../../elements/shipping/shipping-zone-details"; -import { urlList } from "../../../fixtures/urlList"; import { ONE_PERMISSION_USERS } from "../../../fixtures/users"; import { createChannel } from "../../../support/api/requests/Channels"; import { @@ -18,9 +17,13 @@ import filterTests from "../../../support/filterTests"; import { getCurrencyAndAmountInString } from "../../../support/formatData/formatCurrencyAmount"; import { getFormattedCurrencyAmount } from "../../../support/formatData/formatCurrencyAmount"; import { enterHomePageChangeChannelAndReturn } from "../../../support/pages/channelsPage"; +import { + enterAndSelectShippings, + enterShippingZone +} from "../../../support/pages/shippingZones"; filterTests({ definedTags: ["all"] }, () => { - describe("Channels in shippingMethod", () => { + describe("As a staff user I want have different shipping method prices for each channel", () => { const startsWith = "ChannelShippingMethod"; let defaultChannel; let plAddress; @@ -41,7 +44,7 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - it("should display different price for each channel", () => { + it("should be able to display different price for each channel. TC: SALEOR_0805", () => { const shippingName = `${startsWith}${faker.datatype.number()}`; const defaultChannelPrice = 11; const createdChannelPrice = 7; @@ -84,15 +87,11 @@ filterTests({ definedTags: ["all"] }, () => { } ) .then(() => { - cy.clearSessionData() - .loginUserViaRequest("auth", ONE_PERMISSION_USERS.shipping) - .visit(urlList.shippingMethods) - .get(SHARED_ELEMENTS.header) - .should("be.visible") - .waitForProgressBarToNotExist() - .addAliasToGraphRequest("ShippingZone") - .findElementOnTable(shippingZone.name, "ShippingZones") - .waitForRequestAndCheckIfNoErrors("@ShippingZone"); + cy.clearSessionData().loginUserViaRequest( + "auth", + ONE_PERMISSION_USERS.shipping + ); + enterAndSelectShippings(shippingZone.id, enterShippingZone); enterHomePageChangeChannelAndReturn(defaultChannel.name); cy.waitForProgressBarToNotBeVisible() .get(SHARED_ELEMENTS.skeleton) diff --git a/cypress/integration/configuration/shippingMethods/createShippingMethod.js b/cypress/integration/configuration/shippingMethods/createShippingMethod.js index 59515fd68..246ace2a8 100644 --- a/cypress/integration/configuration/shippingMethods/createShippingMethod.js +++ b/cypress/integration/configuration/shippingMethods/createShippingMethod.js @@ -6,8 +6,10 @@ import faker from "faker"; import { urlList } from "../../../fixtures/urlList"; import { ONE_PERMISSION_USERS } from "../../../fixtures/users"; import { createCheckout } from "../../../support/api/requests/Checkout"; +import { createVariant } from "../../../support/api/requests/Product"; import { createWarehouse } from "../../../support/api/requests/Warehouse"; import * as channelsUtils from "../../../support/api/utils/channelsUtils"; +import { createWaitingForCaptureOrder } from "../../../support/api/utils/ordersUtils"; import * as productsUtils from "../../../support/api/utils/products/productsUtils"; import * as shippingUtils from "../../../support/api/utils/shippingUtils"; import { isShippingAvailableInCheckout } from "../../../support/api/utils/storeFront/checkoutUtils"; @@ -19,15 +21,21 @@ import { } from "../../../support/pages/shippingMethodPage"; filterTests({ definedTags: ["all"] }, () => { - describe("Create shipping method", () => { + describe("As a staff user I want to create shipping zone and rate", () => { const startsWith = "CreateShippingMethods-"; const name = `${startsWith}${faker.datatype.number()}`; + const secondName = `${startsWith}${faker.datatype.number()}`; const price = 8; + const secondVariantPrice = 2; const deliveryTime = { min: 2, max: 5 }; let defaultChannel; - let plAddress; + let address; let variantsList; + let secondVariantsList; let warehouse; + let attribute; + let category; + let productType; before(() => { cy.clearSessionData().loginUserViaRequest(); @@ -41,8 +49,8 @@ filterTests({ definedTags: ["all"] }, () => { cy.fixture("addresses"); }) .then(addresses => { - plAddress = addresses.plAddress; - createWarehouse({ name, address: plAddress }); + address = addresses.usAddress; + createWarehouse({ name, address }); }) .then(warehouseResp => { warehouse = warehouseResp; @@ -56,6 +64,10 @@ filterTests({ definedTags: ["all"] }, () => { category: categoryResp, attribute: attributeResp }) => { + attribute = attributeResp; + category = categoryResp; + productType = productTypeResp; + productsUtils.createProductInChannel({ name, channelId: defaultChannel.id, @@ -63,12 +75,27 @@ filterTests({ definedTags: ["all"] }, () => { attributeId: attributeResp.id, categoryId: categoryResp.id, warehouseId: warehouse.id, - quantityInWarehouse: 10 + quantityInWarehouse: 10, + price }); } ) - .then(({ variantsList: variantsListResp }) => { + .then(({ variantsList: variantsListResp, product }) => { variantsList = variantsListResp; + createVariant({ + productId: product.id, + sku: secondName, + attributeId: attribute.id, + attributeName: "value2", + warehouseId: warehouse.id, + quantityInWarehouse: 10, + channelId: defaultChannel.id, + price: secondVariantPrice, + weight: 10 + }); + }) + .then(variantsListResp => { + secondVariantsList = variantsListResp; }); }); @@ -76,7 +103,7 @@ filterTests({ definedTags: ["all"] }, () => { cy.clearSessionData().loginUserViaRequest(); }); - it("should create price based shipping method", () => { + it("should be able to create price based shipping method. TC: SALEOR_0803", () => { const shippingName = `${startsWith}${faker.datatype.number()}`; cy.clearSessionData().loginUserViaRequest( "auth", @@ -86,32 +113,43 @@ filterTests({ definedTags: ["all"] }, () => { createShippingZone( shippingName, warehouse.name, - plAddress.countryFullName, + address.countryFullName, defaultChannel.name ); createShippingRate({ rateName: shippingName, price, + priceLimits: { min: price, max: 100 }, rateOption: rateOptions.PRICE_OPTION, deliveryTime }); - - createCheckout({ + createWaitingForCaptureOrder({ channelSlug: defaultChannel.slug, email: "test@example.com", variantsList, - address: plAddress, - auth: "token" - }).then(({ checkout }) => { - const isShippingAvailable = isShippingAvailableInCheckout( - checkout, - shippingName - ); - expect(isShippingAvailable).to.be.true; - }); + address, + shippingMethodName: shippingName + }) + .then(({ order }) => { + expect(order.id).to.be.ok; + createCheckout({ + channelSlug: defaultChannel.slug, + email: "test@example.com", + variantsList: secondVariantsList, + address, + auth: "token" + }); + }) + .then(({ checkout }) => { + const isShippingAvailable = isShippingAvailableInCheckout( + checkout, + shippingName + ); + expect(isShippingAvailable).to.be.false; + }); }); - it("should create weight based shipping method", () => { + it("should be able to create weight based shipping method. TC: SALEOR_0804", () => { const shippingName = `${startsWith}${faker.datatype.number()}`; cy.clearSessionData().loginUserViaRequest( "auth", @@ -121,28 +159,40 @@ filterTests({ definedTags: ["all"] }, () => { createShippingZone( shippingName, warehouse.name, - plAddress.countryFullName, + address.countryFullName, defaultChannel.name ); createShippingRate({ rateName: shippingName, price, rateOption: rateOptions.WEIGHT_OPTION, - deliveryTime + deliveryTime, + weightLimits: { min: 5, max: 10 } }); - createCheckout({ + createWaitingForCaptureOrder({ channelSlug: defaultChannel.slug, email: "test@example.com", - variantsList, - address: plAddress, - auth: "token" - }).then(({ checkout }) => { - const isShippingAvailable = isShippingAvailableInCheckout( - checkout, - shippingName - ); - expect(isShippingAvailable).to.be.true; - }); + variantsList: secondVariantsList, + address, + shippingMethodName: shippingName + }) + .then(({ order }) => { + expect(order.id).to.be.ok; + createCheckout({ + channelSlug: defaultChannel.slug, + email: "test@example.com", + variantsList, + address, + auth: "token" + }); + }) + .then(({ checkout }) => { + const isShippingAvailable = isShippingAvailableInCheckout( + checkout, + shippingName + ); + expect(isShippingAvailable).to.be.false; + }); }); }); }); diff --git a/cypress/integration/configuration/shippingMethods/editShippingMethod.js b/cypress/integration/configuration/shippingMethods/editShippingMethod.js index 85a1908df..8d2b9758d 100644 --- a/cypress/integration/configuration/shippingMethods/editShippingMethod.js +++ b/cypress/integration/configuration/shippingMethods/editShippingMethod.js @@ -19,7 +19,7 @@ import { } from "../../../support/pages/shippingMethodPage"; filterTests({ definedTags: ["all"] }, () => { - describe("Edit shipping method", () => { + describe("As a user I should be able to update and delete shipping method", () => { const startsWith = "EditShipping-"; const name = `${startsWith}${faker.datatype.number()}`; const price = 10; @@ -55,7 +55,7 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - it("Update shipping rate", () => { + it("should be able to update shipping rate. TC: SALEOR_0806", () => { const updatedRateName = `${startsWith}Updated`; const deliveryTime = { min: 1, max: 7 }; @@ -80,7 +80,7 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - it("Delete shipping rate", () => { + it("should be able to delete shipping rate. TC: SALEOR_0807", () => { cy.visit( priceRateUrl(shippingZone.id, shippingMethod.id) ).deleteElementWithReqAlias("DeleteShippingRate"); diff --git a/cypress/integration/configuration/shippingMethods/editShippingZone.js b/cypress/integration/configuration/shippingMethods/editShippingZone.js index 034608acc..2ffaf4381 100644 --- a/cypress/integration/configuration/shippingMethods/editShippingZone.js +++ b/cypress/integration/configuration/shippingMethods/editShippingZone.js @@ -3,6 +3,7 @@ import faker from "faker"; +import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; import { shippingZoneDetailsUrl } from "../../../fixtures/urlList"; import { createShippingZone, @@ -13,9 +14,10 @@ import { getDefaultChannel } from "../../../support/api/utils/channelsUtils"; import { deleteShippingStartsWith } from "../../../support/api/utils/shippingUtils"; import filterTests from "../../../support/filterTests"; import { fillUpShippingZoneData } from "../../../support/pages/shippingMethodPage"; +import { enterAndSelectShippings } from "../../../support/pages/shippingZones"; filterTests({ definedTags: ["all"] }, () => { - describe("Edit shipping zone", () => { + describe("As a user I should be able to update and delete shipping zone", () => { const startsWith = "EditShipping-"; const name = `${startsWith}${faker.datatype.number()}`; @@ -49,7 +51,7 @@ filterTests({ definedTags: ["all"] }, () => { ); }); - it("Update shipping zone", () => { + it("should be able to update shipping zone. TC: SALEOR_0808", () => { const updatedName = `${startsWith}Updated`; cy.visit(shippingZoneDetailsUrl(shippingZone.id)); @@ -68,11 +70,30 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - it("Delete shipping zone", () => { + it("should be able to delete shipping zone. TC: SALEOR_0809", () => { cy.visit( shippingZoneDetailsUrl(shippingZone.id) ).deleteElementWithReqAlias("DeleteShippingZone"); getShippingZone(shippingZone.id).should("be.null"); }); + + it("should be able to delete several shipping zones on shipping zones list page. TC: SALEOR_0810", () => { + let secondShippingZone; + + createShippingZone(`${startsWith}Second`, "US", defaultChannel.id).then( + shippingZoneResp => { + secondShippingZone = shippingZoneResp; + enterAndSelectShippings([shippingZone.id, secondShippingZone.id]); + cy.get(BUTTON_SELECTORS.deleteSelectedElementsButton) + .click() + .addAliasToGraphRequest("BulkDeleteShippingZone") + .get(BUTTON_SELECTORS.submit) + .click() + .wait("@BulkDeleteShippingZone"); + getShippingZone(shippingZone.id).should("be.null"); + getShippingZone(secondShippingZone.id).should("be.null"); + } + ); + }); }); }); diff --git a/cypress/integration/configuration/shippingMethods/postalCodes.js b/cypress/integration/configuration/shippingMethods/postalCodes.js index 7122fb378..f34bf78d2 100644 --- a/cypress/integration/configuration/shippingMethods/postalCodes.js +++ b/cypress/integration/configuration/shippingMethods/postalCodes.js @@ -23,7 +23,7 @@ import { } from "../../../support/pages/shippingMethodPage"; filterTests({ definedTags: ["all"] }, () => { - describe("Postal codes in shipping", () => { + describe("As a user I want to create shipping method with postal codes", () => { const startsWith = "CyShippingMethods-"; const name = `${startsWith}${faker.datatype.number()}`; @@ -89,7 +89,7 @@ filterTests({ definedTags: ["all"] }, () => { .visit(shippingZoneDetailsUrl(shippingZone.id)); }); - it("Create shipping method with included postal codes", () => { + it("should be able to create shipping method with included postal codes. TC: SALEOR_0801", () => { const rateName = `${startsWith}${faker.datatype.number()}`; createRateWithPostalCode({ @@ -107,7 +107,7 @@ filterTests({ definedTags: ["all"] }, () => { ); }); - it("Create shipping method with excluded postal codes", () => { + it("should be able to create shipping method with excluded postal codes. TC: SALEOR_0802", () => { const rateName = `${startsWith}${faker.datatype.number()}`; createRateWithPostalCode({ diff --git a/cypress/integration/configuration/shippingMethods/shippingWeights/shippingWeightsLimits.js b/cypress/integration/configuration/shippingMethods/shippingWeights/shippingWeightsLimits.js index dfdc809e9..408530afe 100644 --- a/cypress/integration/configuration/shippingMethods/shippingWeights/shippingWeightsLimits.js +++ b/cypress/integration/configuration/shippingMethods/shippingWeights/shippingWeightsLimits.js @@ -23,7 +23,7 @@ import { } from "../../../../support/pages/shippingMethodPage"; filterTests({ definedTags: ["all"] }, () => { - describe("Shipping weight limits", () => { + describe("As a staff user I want to manage shipping weights", () => { const startsWith = "CyWeightRates-"; const name = `${startsWith}${faker.datatype.number()}`; @@ -83,7 +83,7 @@ filterTests({ definedTags: ["all"] }, () => { .visit(shippingZoneDetailsUrl(shippingZone.id)); }); - it("should be possible to buy product in a shipping weight limits", () => { + it("should be possible to buy product in a shipping weight limits. TC: SALEOR_0902", () => { const rateName = `${startsWith}${faker.datatype.number()}`; createShippingRate({ @@ -108,7 +108,7 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - it("should not be possible to buy product not in a shipping weight limits", () => { + it("should not be possible to buy product not in a shipping weight limits. TC: SALEOR_0903", () => { const rateName = `${startsWith}${faker.datatype.number()}`; createShippingRate({ diff --git a/cypress/integration/configuration/shippingMethods/shippingWeights/weightRecalculate.js b/cypress/integration/configuration/shippingMethods/shippingWeights/weightRecalculate.js index ab2eb34af..c10284ef3 100644 --- a/cypress/integration/configuration/shippingMethods/shippingWeights/weightRecalculate.js +++ b/cypress/integration/configuration/shippingMethods/shippingWeights/weightRecalculate.js @@ -18,7 +18,7 @@ import filterTests from "../../../../support/filterTests"; import { changeWeightUnit } from "../../../../support/pages/shippingMethodPage"; filterTests({ definedTags: ["all"] }, () => { - describe("Recalculate weights", () => { + describe("As a staff user I want to change shop default weight unit", () => { const startsWith = "RecalculateWeight"; const name = `${startsWith}${faker.datatype.number()}`; @@ -48,7 +48,7 @@ filterTests({ definedTags: ["all"] }, () => { }); // Log in as user with shipping permissions after resolving SALEOR-3407 bug - it("should recalculate weight after changing shipping weight unit", () => { + it("should recalculate weight after changing shipping weight unit. TC: SALEOR_0901", () => { const rateName = `${startsWith}${faker.datatype.number()}`; const minWeightInKg = 1; const maxWeightInKg = 10; @@ -88,12 +88,12 @@ filterTests({ definedTags: ["all"] }, () => { expect(rate.minimumOrderWeight.unit).to.eq("G"); cy.get(SHIPPING_RATE_DETAILS.restrictWeightLimitCheckbox) .click() - .get(SHIPPING_RATE_DETAILS.minWeightInput) + .get(SHIPPING_RATE_DETAILS.minValueInput) .invoke("val"); }) .then(actualMinWeight => { expect(parseInt(actualMinWeight, 10)).to.eq(minWeightInG); - cy.get(SHIPPING_RATE_DETAILS.maxWeightInput).invoke("val"); + cy.get(SHIPPING_RATE_DETAILS.maxValueInput).invoke("val"); }) .then(actualMaxWeight => { expect(parseInt(actualMaxWeight, 10)).to.eq(maxWeightInG); diff --git a/cypress/support/pages/shippingMethodPage.js b/cypress/support/pages/shippingMethodPage.js index 89fe13cc0..ef094ea5e 100644 --- a/cypress/support/pages/shippingMethodPage.js +++ b/cypress/support/pages/shippingMethodPage.js @@ -80,14 +80,16 @@ export function createShippingRate({ price, rateOption, weightLimits, - deliveryTime + deliveryTime, + priceLimits }) { enterAndFillUpShippingRate({ rateName, price, rateOption, weightLimits, - deliveryTime + deliveryTime, + priceLimits }); return saveRate(); } @@ -97,6 +99,7 @@ export function enterAndFillUpShippingRate({ price, rateOption, weightLimits, + priceLimits, deliveryTime }) { cy.get(rateOption).click(); @@ -104,6 +107,7 @@ export function enterAndFillUpShippingRate({ rateName, price, weightLimits, + priceLimits, deliveryTime }); } @@ -112,6 +116,7 @@ export function fillUpShippingRate({ rateName, price, weightLimits, + priceLimits, deliveryTime }) { cy.waitForProgressBarToNotBeVisible() @@ -123,7 +128,10 @@ export function fillUpShippingRate({ fillUpDeliveryTime(deliveryTime); } if (weightLimits) { - fillUpWeightLimits(weightLimits); + fillUpLimits(weightLimits); + } + if (priceLimits) { + fillUpLimits(priceLimits); } cy.get(SHIPPING_RATE_DETAILS.priceInput).each($priceInput => { cy.wrap($priceInput).clearAndType(price); @@ -173,10 +181,10 @@ export function saveRateAfterUpdate() { .waitForRequestAndCheckIfNoErrors(`@ShippingMethodChannelListingUpdate`); } -export function fillUpWeightLimits({ max, min }) { - cy.get(SHIPPING_RATE_DETAILS.minWeightInput) +export function fillUpLimits({ max, min }) { + cy.get(SHIPPING_RATE_DETAILS.minValueInput) .type(min) - .get(SHIPPING_RATE_DETAILS.maxWeightInput) + .get(SHIPPING_RATE_DETAILS.maxValueInput) .type(max); } diff --git a/cypress/support/pages/shippingZones.js b/cypress/support/pages/shippingZones.js new file mode 100644 index 000000000..4c326d0c5 --- /dev/null +++ b/cypress/support/pages/shippingZones.js @@ -0,0 +1,63 @@ +import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; +import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements"; +import { + SHIPPING_ZONE_CHECKBOX, + SHIPPING_ZONE_NAME +} from "../../elements/shipping/shipping-zones-list"; +import { urlList } from "../../fixtures/urlList"; + +export function enterAndSelectShippings( + shippingIds, + actionFunction = selectShippingZone +) { + cy.addAliasToGraphRequest("ShippingZones").visit(urlList.shippingMethods); + selectShippingsOnTable(shippingIds, actionFunction); +} + +export function selectShippingsOnTable( + shippingIds, + actionFunction = selectShippingZone, + counter = 0 +) { + cy.get(SHARED_ELEMENTS.skeleton) + .should("not.exist") + .wait("@ShippingZones") + .its("response.body") + .then(body => { + const shippingResults = body.find(element => { + if (element.data.shippingZones) { + return element; + } + }); + const shippingList = shippingResults.data.shippingZones.edges; + const notSelectedShippings = []; + shippingIds = Array.isArray(shippingIds) ? shippingIds : [shippingIds]; + shippingIds.forEach(id => { + const isShippingOnList = shippingList.find( + element => element.node.id === id + ); + if (isShippingOnList) { + actionFunction(id); + counter += 1; + } else { + notSelectedShippings.push(id); + } + if (counter === shippingIds.length) { + return; + } + }); + if (counter === shippingIds.length) { + return; + } + cy.get(BUTTON_SELECTORS.nextPaginationButton).click(); + selectShippingsOnTable(notSelectedShippings, actionFunction, counter); + }); +} + +export function selectShippingZone(id) { + cy.get(SHIPPING_ZONE_CHECKBOX(id)).click(); +} + +export function enterShippingZone(id) { + cy.get(SHIPPING_ZONE_NAME(id)).click(); +} diff --git a/src/shipping/components/ShippingZonesList/ShippingZonesList.tsx b/src/shipping/components/ShippingZonesList/ShippingZonesList.tsx index bc954f4b8..9881afe6c 100644 --- a/src/shipping/components/ShippingZonesList/ShippingZonesList.tsx +++ b/src/shipping/components/ShippingZonesList/ShippingZonesList.tsx @@ -149,9 +149,13 @@ const ShippingZonesList: React.FC = props => { disabled={disabled} disableClickPropagation onChange={() => toggle(shippingZone.id)} + data-test-id={maybe(() => shippingZone.id + "-checkbox")} /> - + shippingZone.id + "-name")} + > {maybe( () => shippingZone.name, diff --git a/src/shipping/views/ShippingZonesList.tsx b/src/shipping/views/ShippingZonesList.tsx index 67f09ed17..bb25706bc 100644 --- a/src/shipping/views/ShippingZonesList.tsx +++ b/src/shipping/views/ShippingZonesList.tsx @@ -168,6 +168,7 @@ export const ShippingZonesList: React.FC = ({ toggleAll={toggleAll} toolbar={ diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index 07fb8117b..94e004ec5 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -236783,6 +236783,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list default 1`] = ` Europe @@ -236858,6 +236860,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list default 1`] = ` Oceania @@ -236933,6 +236937,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list default 1`] = ` Asia @@ -237008,6 +237014,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list default 1`] = ` Americas @@ -237083,6 +237091,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list default 1`] = ` Africa @@ -238211,6 +238221,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list no site settings perm Europe @@ -238286,6 +238298,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list no site settings perm Oceania @@ -238361,6 +238375,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list no site settings perm Asia @@ -238436,6 +238452,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list no site settings perm Americas @@ -238511,6 +238529,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list no site settings perm Africa