Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test bulk delete on product list #4512

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading