Skip to content

Commit

Permalink
lazy fixtures with data provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Xotabu4 committed May 21, 2024
1 parent 65878dd commit 097ba55
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
5 changes: 5 additions & 0 deletions app/page/product/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export class Product extends AppPage {
await this.page.goto(productPath);
}

@step()
async changeQuantity(quantity: number) {
await this.page.getByPlaceholder('Product Quantity').fill(quantity.toString());
}

@step()
async addToBag() {
await this.expectLoaded();
Expand Down
9 changes: 6 additions & 3 deletions fixtures/lazy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export const shopTest = test.extend<{
itemsInCart: { slug: string }[];
};
testOptions: {
itemsToAddInCart: { slug: string }[];
itemsToAddInCart: { slug: string; quantity?: number }[];
};
}>({
testOptions: [
{
itemsToAddInCart: [
{
slug: "cherry-tomatoes"
}
slug: "cherry-tomatoes",
},
],
},
{
Expand Down Expand Up @@ -58,6 +58,9 @@ export const shopTest = test.extend<{
// '[{"taxable":false,"isActive":true,"brand":{"isActive":true,"_id":"64bbbc91e9d7a367fcb1d462","name":"Nizhyn cannery","slug":"Nizhyn"},"_id":"64e106888e01260021ea480c","sku":"CHERRY_TOMATOES","name":"CHERRY TOMATOES","description":"cherry tomatoes, salt, sugar, greens, acetic acid, garlic, spices","quantity":1,"price":95,"created":"2023-08-19T18:14:32.255Z","slug":"cherry-tomatoes","__v":0,"inventory":98913,"totalPrice":95}]')
for (const item of testOptions.itemsToAddInCart) {
await app.product.open(`/product/${item.slug}`);
if (item.quantity !== undefined) {
await app.product.changeQuantity(item.quantity);
}
await app.product.addToBag();
}
await use({ itemsInCart: testOptions.itemsToAddInCart });
Expand Down
48 changes: 47 additions & 1 deletion tests/lazy-fixtures/purchase.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { shopTest } from "../../fixtures/lazy";

/**
shopTest(
"lazy-fixt: logged in user can buy a product",
async ({ app, newUser, itemAddedInCart }) => {
Expand All @@ -12,7 +13,10 @@ shopTest(
shopTest.describe(() => {
shopTest.use({
testOptions: {
itemsToAddInCart: [{ slug: "cherry-tomatoes" }, { slug: "MARINATED_CUCUMBERS_NEZHIN_STYLE" }],
itemsToAddInCart: [
{ slug: "cherry-tomatoes" },
{ slug: "MARINATED_CUCUMBERS_NEZHIN_STYLE" },
],
},
});
Expand All @@ -24,3 +28,45 @@ shopTest.describe(() => {
}
);
});
*/

const testData = [
{
testName: "lazy-fixt: logged in user can buy a product",
},
{
testName: "lazy-fixt: logged in user can purchase multiple items",
testOptions: {
itemsToAddInCart: [
{ slug: "cherry-tomatoes" },
{ slug: "MARINATED_CUCUMBERS_NEZHIN_STYLE" },
],
},
},
{
testName: "lazy-fixt: logged in user can purchase item with quantity 2",
testOptions: {
itemsToAddInCart: [
{
slug: "cherry-tomatoes",
quantity: 2
},
{ slug: "MARINATED_CUCUMBERS_NEZHIN_STYLE" },
],
},
},
];

for (const td of testData) {
shopTest.describe(() => {
shopTest.use({
testOptions: td.testOptions,
});

shopTest(td.testName, async ({ app, newUser, itemAddedInCart }) => {
await app.accountDetails.miniCart.placeOrder();
await app.confirmation.expectOrderPlaced();
});
});
}

0 comments on commit 097ba55

Please sign in to comment.