Skip to content

Commit

Permalink
[TEST] [E2E] Adding tests for bulk deleting shipping zones and updati…
Browse files Browse the repository at this point in the history
…ng one (#4632)

* adding tests for bulk deleting shipping zones and updating one

* Trigger Build
  • Loading branch information
yellowee authored Feb 10, 2024
1 parent 50404fc commit 465aa7b
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 51 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-bulldogs-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Adding e2e tests for bulk deleting shipping zones and updating one
49 changes: 49 additions & 0 deletions playwright/data/e2eTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ export const CHANNELS = {
plnChannel: {
id: "VGF4Q29uZmlndXJhdGlvbjox",
},
e2eChannelDoNotDelete: {
id: "Q2hhbm5lbDoyMzk0",
name: "e2e-channel-do-not-delete",
slug: "e2e-channel-do-not-delete",
},
channelUSD: {
id: "Q2hhbm5lbDoyMjQz",
name: "Channel-USD",
},
channelPLN: {
id: "Q2hhbm5lbDoyMjQ0",
name: "Channel-PLN",
},
};
export const GIFT_CARDS = {
giftCardToBeEdited: {
Expand Down Expand Up @@ -123,6 +136,22 @@ export const WAREHOUSES = {
warehouseToBeDeleted: {
name: "warehouseto be deleted",
},
warehouseEurope: {
id: "V2FyZWhvdXNlOjlkYjY4NWQxLWViMTktNDU2ZS05ODMyLTMxODA3ZWM0NDdhOQ==",
name: "Europe",
},
warehouseAmericas: {
id: "V2FyZWhvdXNlOjdmZDA0OGI0LWYwNzItNDZmMi1iMDMyLTc3ZWU3MDNiMzM3Yg==",
name: "Americas",
},
warehouseOceania: {
id: "V2FyZWhvdXNlOjc4OGUyMGRlLTlmYTAtNDI5My1iZDk2LWUwM2RjY2RhMzc0ZQ==",
name: "Oceania",
},
warehouseAfrica: {
id: "V2FyZWhvdXNlOjk1NWY0ZDk2LWRmNTAtNGY0Zi1hOTM4LWM5MTYzYTA4YTViNg==",
name: "Africa",
},
};

export const PRODUCTS = {
Expand Down Expand Up @@ -224,6 +253,26 @@ export const SHIPPING_METHODS = {
id: "U2hpcHBpbmdab25lOjIzOTA%3D",
info: "Shipping method that is used to add rates",
},
shippingMethodToBeUpdated: {
id: "U2hpcHBpbmdab25lOjIzOTI=",
info: "Shipping zone to be updated",
name: "e2e-test-shippingZone-to-be-updated",
},
shippingMethodToBeBulkDeleted1: {
id: "U2hpcHBpbmdab25lOjIzOTM=",
info: "First shipping zone to be bulk deleted",
name: "e2e-test-shippingZone-to-be-bulk-deleted-1",
},
shippingMethodToBeBulkDeleted2: {
id: "U2hpcHBpbmdab25lOjIzOTQ=",
info: "Second shipping zone to be bulk deleted",
name: "e2e-test-shippingZone-to-be-bulk-deleted-2",
},
shippingMethodToBeBulkDeleted3: {
id: "U2hpcHBpbmdab25lOjIzOTU=",
info: "Third shipping zone to be bulk deleted",
name: "e2e-test-shippingZone-to-be-bulk-deleted-3",
},
shippingMethodWithRatesToBeDeleted: {
id: "U2hpcHBpbmdab25lOjIzODk%3D",
info: "Shipping zone with methods to be deleted",
Expand Down
28 changes: 17 additions & 11 deletions playwright/pages/pageElements/rightSideDetailsSection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChannelSelectDialog } from "@pages/dialogs/channelSelectDialog";
import { expect, Page } from "@playwright/test";
import { expect, Locator, Page } from "@playwright/test";

export class RightSideDetailsPage {
readonly channelSelectDialog: ChannelSelectDialog;
Expand All @@ -11,12 +11,13 @@ export class RightSideDetailsPage {
"select-warehouse-for-shipping-method",
),
readonly stockSettingsSection = page.getByTestId("stock-settings-section"),
readonly channelSection = page.getByTestId("channel-section"),
readonly warehouseSection = page.getByTestId("warehouse-section"),
readonly selectChannelShippingPageButton = page.getByTestId(
"select-channel-for-shipping-method",
),
readonly pickupDisabledButton = page.getByTestId("DISABLED"),
readonly pickupAllWarehousesButton = page.getByTestId("ALL"),

readonly categorySelectOption = page.locator(
"[data-test-id*='select-option']",
),
Expand All @@ -31,7 +32,6 @@ export class RightSideDetailsPage {
),
readonly collectionInput = page.getByTestId("collections"),
readonly autocompleteDropdown = page.getByTestId("autocomplete-dropdown"),

readonly manageChannelsButton = page.getByTestId(
"channels-availability-manage-button",
),
Expand Down Expand Up @@ -93,11 +93,14 @@ export class RightSideDetailsPage {
async clickEditShippingAddressButton() {
await this.editShippingAddressButton.click();
}

async clickWarehouseSelectShippingPage() {
await this.selectWarehouseShippingMethodButton.click();
}

async expectOptionsSelected(section: Locator, names: string[]) {
for (const name of names) {
await expect(section.getByText(name)).toBeVisible({timeout: 30000});
}
}
async typeAndSelectSingleWarehouseShippingPage(warehouse = "Europe") {
await this.selectWarehouseShippingMethodButton
.locator("input")
Expand All @@ -107,7 +110,16 @@ export class RightSideDetailsPage {
// below click hides prompted options
this.clickWarehouseSelectShippingPage();
}
async typeAndSelectMultipleWarehousesShippingPage(warehouses: string[]) {
for (const warehouse of warehouses) {
await this.selectWarehouseShippingMethodButton
.locator("input")
.fill(warehouse);

await this.selectOption.filter({ hasText: warehouse }).first().click();
}
this.clickWarehouseSelectShippingPage();
}
async clickChannelsSelectShippingPage() {
await this.selectChannelShippingPageButton.click();
}
Expand All @@ -116,11 +128,9 @@ export class RightSideDetailsPage {
// below click hides prompted options
this.clickChannelsSelectShippingPage();
}

async openChannelsDialog() {
await this.manageChannelsButton.click();
}

async selectFirstCategory() {
await this.categoryInput.click();
await this.categorySelectOption.first().click();
Expand All @@ -138,7 +148,6 @@ export class RightSideDetailsPage {
await this.collectionInput.click();
await this.selectOption.first().click();
}

async clickEditCustomerButton() {
await this.editCustomerButton.click();
}
Expand All @@ -148,7 +157,6 @@ export class RightSideDetailsPage {
async expandWarehousesSection() {
await this.warehousesSection.locator(this.expandButton).click();
}

async clickSearchCustomerInput() {
await this.searchCustomerInput.click();
}
Expand Down Expand Up @@ -178,11 +186,9 @@ export class RightSideDetailsPage {
await this.warehouseSelect.click();
await this.page.getByRole("option", { name: warehouseName });
}

async selectCustomer(customer = "[email protected]") {
await this.selectCustomerOption.locator(`text=${customer}`).click();
}

async selectOneChannelAsAvailableWhenMoreSelected(channel: string) {
await this.manageChannelsButton.click();
await this.channelSelectDialog.clickAllChannelsCheckbox();
Expand Down
13 changes: 5 additions & 8 deletions playwright/pages/shippingMethodsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { AssignCountriesDialog } from "@pages/dialogs/assignCountriesDialog";
import { RightSideDetailsPage } from "@pages/pageElements/rightSideDetailsSection";
import type { Page } from "@playwright/test";

export class ShippingMethodsPage {
readonly page: Page;
readonly basePage: BasePage;
readonly rightSideDetailsPage: RightSideDetailsPage;
readonly assignCountriesDialog: AssignCountriesDialog;
readonly deleteShippingMethodDialog: DeleteShippingMethodDialog;
export class ShippingMethodsPage extends BasePage {
rightSideDetailsPage: RightSideDetailsPage;
assignCountriesDialog: AssignCountriesDialog;
deleteShippingMethodDialog: DeleteShippingMethodDialog;


constructor(
Expand All @@ -31,8 +29,7 @@ export class ShippingMethodsPage {
readonly priceBasedRatesSection = page.getByTestId("price-based-rates"),
readonly weightBasedRatesSection = page.getByTestId("weight-based-rates"),
) {
this.page = page;
this.basePage = new BasePage(page);
super(page);
this.rightSideDetailsPage = new RightSideDetailsPage(page);
this.assignCountriesDialog = new AssignCountriesDialog(page);
this.deleteShippingMethodDialog = new DeleteShippingMethodDialog(page);
Expand Down
88 changes: 59 additions & 29 deletions playwright/tests/shippingMethods.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { SHIPPING_METHODS } from "@data/e2eTestData";
import { CHANNELS, SHIPPING_METHODS, WAREHOUSES } from "@data/e2eTestData";
import { ShippingMethodsPage } from "@pages/shippingMethodsPage";
import { ShippingRatesPage } from "@pages/shippingRatesPage";
import { expect, test } from "@playwright/test";

test.use({ storageState: "playwright/.auth/admin.json" });
let shippingMethodsPage: ShippingMethodsPage;
let shippingRatesPage: ShippingRatesPage;

test("TC: SALEOR_31 Create basic shipping method @shipping-method @e2e", async ({
page,
}) => {
const shippingMethodsPage = new ShippingMethodsPage(page);

test.beforeEach(({ page }) => {
shippingMethodsPage = new ShippingMethodsPage(page);
shippingRatesPage = new ShippingRatesPage(page);
});

test("TC: SALEOR_31 Create basic shipping method @shipping-method @e2e", async () => {

await shippingMethodsPage.gotoListView();
await shippingMethodsPage.clickCreateShippingZoneButton();
Expand All @@ -17,21 +22,16 @@ test("TC: SALEOR_31 Create basic shipping method @shipping-method @e2e", async (
await shippingMethodsPage.clickAssignCountryButton();
await shippingMethodsPage.assignCountriesDialog.checkAndSaveSingleCountry();
await shippingMethodsPage.saveShippingZone();
await shippingMethodsPage.basePage.expectSuccessBanner();
await shippingMethodsPage.expectSuccessBanner();

await shippingMethodsPage.rightSideDetailsPage.clickChannelsSelectShippingPage();
await shippingMethodsPage.rightSideDetailsPage.selectSingleChannelShippingPage();
await shippingMethodsPage.rightSideDetailsPage.clickWarehouseSelectShippingPage();
await shippingMethodsPage.rightSideDetailsPage.typeAndSelectSingleWarehouseShippingPage();
await shippingMethodsPage.saveShippingZone();
await shippingMethodsPage.basePage.expectSuccessBanner();
await shippingMethodsPage.expectSuccessBanner();
});
test("TC: SALEOR_32 Add price rate to shipping method - with excluded zip codes and excluded product @shipping-method @e2e", async ({
page,
}) => {
const shippingMethodsPage = new ShippingMethodsPage(page);
const shippingRatesPage = new ShippingRatesPage(page);

test("TC: SALEOR_32 Add price rate to shipping method - with excluded zip codes and excluded product @shipping-method @e2e", async () => {
await shippingMethodsPage.gotoExistingShippingMethod(
SHIPPING_METHODS.shippingMethodWithoutRates.id,
);
Expand All @@ -55,11 +55,7 @@ test("TC: SALEOR_32 Add price rate to shipping method - with excluded zip codes
1,
);
});
test("TC: SALEOR_33 Add weight rate to shipping method - with included zip codes and excluded product @shipping-method @e2e", async ({
page,
}) => {
const shippingMethodsPage = new ShippingMethodsPage(page);
const shippingRatesPage = new ShippingRatesPage(page);
test("TC: SALEOR_33 Add weight rate to shipping method - with included zip codes and excluded product @shipping-method @e2e", async () => {

await shippingMethodsPage.gotoExistingShippingMethod(
SHIPPING_METHODS.shippingMethodWithoutRates.id,
Expand All @@ -86,35 +82,69 @@ test("TC: SALEOR_33 Add weight rate to shipping method - with included zip codes
);
});

test("TC: SALEOR_34 Delete a single shipping rate from the shipping zone details page @shipping-method @e2e", async ({
page,
}) => {
const shippingMethodsPage = new ShippingMethodsPage(page);
test("TC: SALEOR_34 Delete a single shipping rate from the shipping zone details page @shipping-method @e2e", async () => {

await shippingMethodsPage.gotoExistingShippingMethod(
SHIPPING_METHODS.shippingMethodWithRatesToBeDeleted.id,
);
await expect(shippingMethodsPage.basePage.pageHeader).toBeVisible();
await expect(shippingMethodsPage.pageHeader).toBeVisible();
const priceBasedRate = SHIPPING_METHODS.shippingMethodWithRatesToBeDeleted.rates.priceBasedRateToBeDeleted.name;
await expect(shippingMethodsPage.priceBasedRatesSection).toContainText(priceBasedRate);
await shippingMethodsPage.clickDeletePriceBasedShippingMethod();
await shippingMethodsPage.deleteShippingMethodDialog.clickDeleteButton();
await shippingMethodsPage.basePage.expectSuccessBanner();
await shippingMethodsPage.expectSuccessBanner();
await expect(shippingMethodsPage.priceBasedRatesSection).toContainText("No shipping rates found");
await expect(shippingMethodsPage.priceBasedRatesSection).not.toContainText(priceBasedRate);
});

test("TC: SALEOR_35 Delete a single shipping rate from its details page @shipping-method @e2e", async ({
page,
}) => {
const shippingMethodsPage = new ShippingMethodsPage(page);
test("TC: SALEOR_35 Delete a single shipping rate from its details page @shipping-method @e2e", async () => {

const shippingMethodId = SHIPPING_METHODS.shippingMethodWithRatesToBeDeleted.id;
const shippingRateId = SHIPPING_METHODS.shippingMethodWithRatesToBeDeleted.rates.weightBasedRateToBeDeleted.id;
const weightBasedRate = SHIPPING_METHODS.shippingMethodWithRatesToBeDeleted.rates.weightBasedRateToBeDeleted.name;

await shippingMethodsPage.gotoExistingShippingRate(shippingMethodId, shippingRateId);
await shippingMethodsPage.clickDeleteShippingRateButton();
await shippingMethodsPage.deleteShippingMethodDialog.clickDeleteButton();
await shippingMethodsPage.basePage.expectSuccessBanner();
await shippingMethodsPage.expectSuccessBanner();
await expect(shippingMethodsPage.weightBasedRatesSection).toContainText("No shipping rates found");
await expect(shippingMethodsPage.weightBasedRatesSection).not.toContainText(weightBasedRate);
});

test("TC: SALEOR_36 Delete shipping zones in bulk @shipping-method @e2e", async ({

}) => {

const shippingZone1 = SHIPPING_METHODS.shippingMethodToBeBulkDeleted1.name;
const shippingZone2 = SHIPPING_METHODS.shippingMethodToBeBulkDeleted2.name;
const shippingZone3 = SHIPPING_METHODS.shippingMethodToBeBulkDeleted3.name;

await shippingMethodsPage.gotoListView();
await shippingMethodsPage.checkListRowsBasedOnContainingText([shippingZone1, shippingZone2, shippingZone3]);
await shippingMethodsPage.clickBulkDeleteGridRowsButton();
await shippingMethodsPage.deleteShippingMethodDialog.clickDeleteButton();
await shippingMethodsPage.expectSuccessBanner();
});

test("TC: SALEOR_37 Update a shipping method @shipping-method @e2e", async () => {
const channelSection = shippingMethodsPage.rightSideDetailsPage.channelSection
const warehouseSection = shippingMethodsPage.rightSideDetailsPage.warehouseSection
const alreadyAssignedChannels = [CHANNELS.channelUSD.name];
const channelsToBeAssigned = [CHANNELS.channelPLN.name];
const alreadyAssignedWarehouses = [WAREHOUSES.warehouseOceania.name, WAREHOUSES.warehouseAfrica.name];
const warehousesToBeAssigned = [WAREHOUSES.warehouseAmericas.name, WAREHOUSES.warehouseEurope.name];
await shippingMethodsPage.gotoExistingShippingMethod(
SHIPPING_METHODS.shippingMethodToBeUpdated.id,
);
await shippingMethodsPage.rightSideDetailsPage.clickChannelsSelectShippingPage();
await shippingMethodsPage.rightSideDetailsPage.selectSingleChannelShippingPage()
await shippingMethodsPage.rightSideDetailsPage.clickWarehouseSelectShippingPage();
await shippingMethodsPage.rightSideDetailsPage.typeAndSelectMultipleWarehousesShippingPage(warehousesToBeAssigned);
await shippingMethodsPage.saveShippingZone();
await shippingMethodsPage.expectSuccessBanner();
const updatedChannelsList = alreadyAssignedChannels.concat(channelsToBeAssigned);
await shippingMethodsPage.rightSideDetailsPage.expectOptionsSelected(channelSection,updatedChannelsList);
const updatedWarehousesList = alreadyAssignedWarehouses.concat(warehousesToBeAssigned);
await shippingMethodsPage.rightSideDetailsPage.expectOptionsSelected(warehouseSection,updatedWarehousesList);
});

Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const MultiAutocompleteSelectFieldComponent: React.FC<
</Downshift>
)}
</DebounceAutocomplete>
<div className={classes.chipContainer}>
<div className={classes.chipContainer} data-test-id="selected-options">
{displayValues.map(value => (
<div
className={classes.chip}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const ShippingZoneSettingsCard: React.FC<
return (
<Card>
<CardTitle title={intl.formatMessage(messages.title)} />
<CardContent>
<CardContent data-test-id="channel-section">
<ChannelsSection
channelsDisplayValues={channelsDisplayValues}
onChange={onChannelChange}
Expand All @@ -63,7 +63,7 @@ export const ShippingZoneSettingsCard: React.FC<
/>
</CardContent>
<Divider />
<CardContent>
<CardContent data-test-id="warehouse-section">
<WarehousesSection
onAdd={onWarehouseAdd}
onSearchChange={onWarehousesSearchChange}
Expand Down

0 comments on commit 465aa7b

Please sign in to comment.