Skip to content

Commit

Permalink
Test bulk delete on product list (#4512)
Browse files Browse the repository at this point in the history
* test bulk delete on product list

* exclude rows eval from loop
  • Loading branch information
wojteknowacki committed Dec 5, 2023
1 parent 3086f43 commit 976b34c
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/moody-islands-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

test bulk delete on product list
7 changes: 7 additions & 0 deletions playwright/data/e2eTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ export const PRODUCTS = {
id: "UHJvZHVjdDo3NTc%3D",
info: "Product that contains single variant - to be deleted from details view",
},
productsToBeBulkDeleted: {
names: [
"a product to be deleted via bulk 1/3",
"a product to be deleted via bulk 2/3",
"a product to be deleted via bulk 3/3",
],
},
};

export const SHIPPING_METHODS = {
Expand Down
42 changes: 41 additions & 1 deletion playwright/pages/basePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class BasePage {
.waitFor({ state: "attached", timeout: 10000 });
}

async findGridCellBounds(col: number, row: number) {
private async findGridCellBounds(col: number, row: number) {
return this.gridCanvas.evaluate(
(node, { col, row }) => {
const fiberKey = Object.keys(node).find(
Expand Down Expand Up @@ -114,4 +114,44 @@ export class BasePage {
await this.gridInput.waitFor({ state: "attached" });
await this.gridInput.fill(content);
}
async clickGridCell(col: number, row: number) {
const bounds = await this.findGridCellBounds(col, row);

if (!bounds)
throw new Error(`Unable to find cell, col: ${col}, row: ${row}`);

await this.page.mouse.click(bounds.center.x, bounds.center.y);
}

async findRowIndexBasedOnText(searchTextArray: string[]) {
await this.waitForGrid();
let rowIndexes: number[] = [];

const rows = await this.page.$$eval("table tr", rows =>
rows.map(row => row.textContent),
);

for (const searchedText of searchTextArray) {
const rowIndex = rows.findIndex(rowText =>
rowText!.includes(searchedText),
);

if (rowIndex !== -1) {
console.log("Index of row containing text:", rowIndex - 1);
// since row index starts with 1 and selecting cells in grid starts with zero there is -1 on rowIndex
rowIndexes.push(rowIndex - 1);
}
}
return rowIndexes;
}

// check row on grid list view
async checkListRowsBasedOnContainingText(searchText: string[]) {
const rowIndexes = await this.findRowIndexBasedOnText(searchText);
for (const rowIndex of rowIndexes) {
await this.clickGridCell(0, rowIndex);
}
// make sure all searched texts were found and checked
await expect(searchText.length).toEqual(rowIndexes.length);
}
}
4 changes: 4 additions & 0 deletions playwright/pages/productPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class ProductPage {
page: Page,
readonly productsNames = page.getByTestId("name"),
readonly createProductButton = page.getByTestId("add-product"),
readonly bulkDeleteButton = page.getByTestId("bulk-delete-button"),
readonly deleteProductButton = page.getByTestId("button-bar-delete"),
readonly searchProducts = page.locator(
"[placeholder='Search Products...']",
Expand Down Expand Up @@ -82,6 +83,9 @@ export class ProductPage {
async clickDeleteProductButton() {
await this.deleteProductButton.click();
}
async clickBulkDeleteButton() {
await this.bulkDeleteButton.click();
}

async addSeo() {
await this.metadataSeoPage.fillSeoSection();
Expand Down
23 changes: 23 additions & 0 deletions playwright/tests/product.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PRODUCTS } from "@data/e2eTestData";
import { URL_LIST } from "@data/url";
import { BasePage } from "@pages/basePage";
import { ProductCreateDialog } from "@pages/dialogs/productCreateDialog";
import { ProductPage } from "@pages/productPage";
Expand Down Expand Up @@ -104,6 +105,28 @@ test("TC: SALEOR_27 Create full info variant - via edit variant page @e2e @produ
await variantsPage.clickSaveVariantButton();
await variantsPage.expectSuccessBanner();
});

test("TC: SALEOR_44 As an admin I should be able to delete a several products with variants @basic-regression @product @e2e", async ({
page,
}) => {
const basePage = new BasePage(page);
const productPage = new ProductPage(page);
await page.goto(URL_LIST.products);

await basePage.checkListRowsBasedOnContainingText(
PRODUCTS.productsToBeBulkDeleted.names,
);
await productPage.clickBulkDeleteButton();
await productPage.deleteProductDialog.clickDeleteButton();
await basePage.expectSuccessBanner();
await basePage.waitForGrid();
await expect(
await basePage.findRowIndexBasedOnText(
PRODUCTS.productsToBeBulkDeleted.names,
),
).toEqual([]);
});

test("TC: SALEOR_45 As an admin I should be able to delete a single product with variants @basic-regression @product @e2e", async ({
page,
}) => {
Expand Down

0 comments on commit 976b34c

Please sign in to comment.