Skip to content

Commit

Permalink
promotion rules tests (#4704)
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowee authored Mar 6, 2024
1 parent 3b8648d commit f845150
Show file tree
Hide file tree
Showing 12 changed files with 351 additions and 43 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-weeks-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

E2E Test for adding promotion rules
40 changes: 39 additions & 1 deletion playwright/data/e2eTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ promotionWithoutRulesToBeDeleted: {
promotionWithRulesToBeDeleted: {
name: "e2e Catalog predicate promotion with rules",
id: "UHJvbW90aW9uOjY0N2M2MzdhLTZjNTEtNDYxZC05MjQ2LTc0YTY0OGM0ZjAxNA==",
}}
},
cataloguePromotion:{
name: "e2e Catalog promotion for adding rules",
id: "UHJvbW90aW9uOjNmODZjZDAwLTUwNWEtNGVkNC04ZTliLTJmOGI4NGM3NGNlOQ==",
},
orderPromotion: {
name: "e2e Order promotion for adding rules",
id: "UHJvbW90aW9uOjJlM2VhNDkyLTRhMTAtNDYzOS05MWVmLTc1YzQ1OTUxNGQyMQ==",
},
}

export const CUSTOMER_ADDRESS = {
changeBillingAddress: {
Expand Down Expand Up @@ -74,6 +83,10 @@ export const CATEGORIES = {
"a cateogry to be bulk deleted 2/2",
],
},
e2eCategory: {
id: "Q2F0ZWdvcnk6NTEx",
name: "e2e category"
}
};
export const COLLECTIONS = {
collectionToBeUpdated: {
Expand All @@ -83,6 +96,10 @@ export const COLLECTIONS = {
collectionsToBeBulkDeleted: {
names: ["Collection to be deleted 1/2", "Collection to be deleted 2/2"],
},
e2eCollection: {
id: "Q29sbGVjdGlvbjoxNjc=",
name: "e2e collection"
}
};
export const COUNTRIES = {
afghanistan: {
Expand Down Expand Up @@ -122,6 +139,7 @@ export const CHANNELS = {
channelPLN: {
id: "Q2hhbm5lbDoyMjQ0",
name: "Channel-PLN",
currency: "PLN",
},
};
export const GIFT_CARDS = {
Expand Down Expand Up @@ -180,6 +198,14 @@ export const PRODUCTS = {
id: "UHJvZHVjdDo3NjE%3D",
info: "Single product type to be updated",
},
e2eProduct1: {
id: "UHJvZHVjdDo3OQ==",
name: "Bean Juice"
},
e2eProduct2:{
id: "UHJvZHVjdDoxMTU=",
name: "Black Hoodie"
},
productAvailableOnlyInPlnChannel: {
id: "UHJvZHVjdDo3NjM%3D",
name: "a beer available only in pln channel",
Expand All @@ -195,6 +221,18 @@ export const PRODUCTS = {
name: "beer with variants",
info: "Product that does not contain any variant yet",
},
e2eProductWithVariant1: {
id: "UHJvZHVjdDo4NQ==",
name: "Colored Parrot Cushion",
variantId: "UHJvZHVjdFZhcmlhbnQ6OTgy",
variantName: "70 / 70",
},
e2eProductWithVariant2: {
id: "UHJvZHVjdDoxMTY=",
name: "Blue Hoodie 2",
variantId: "UHJvZHVjdFZhcmlhbnQ6MzAx",
variantName: "S",
},
productWithOneVariant: {
id: "UHJvZHVjdDo3MzM%3D",
info: "Product that contains single variant",
Expand Down
148 changes: 148 additions & 0 deletions playwright/pages/dialogs/promotionRuleDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import type { Page } from "@playwright/test";

export class PromotionRuleDialog {
readonly page: Page;
constructor(
page: Page,
readonly ruleNameInput = page.getByTestId("rule-name-input"),
readonly ruleChannelDropdown = page.getByText("Channel", { exact: true }),
readonly ruleChannelDropdownOptions = page.getByRole("listbox"),
readonly selectOption = page.getByTestId(
"select-option",
),
readonly ruleDescriptionInput = page.getByTestId("rich-text-editor-rule-description"),
readonly addFirstRuleConditionButton = page.getByTestId("add-first-condition-button"),
readonly addAnotherRuleConditionButton = page.getByTestId("add-another-condition-button"),
readonly addRuleConditionSection = page.getByTestId("conditions-section"),
readonly addRuleConditionPredicateDropdown = page.getByTestId("rule-condition-predicate-dropdown"),
readonly addRuleConditionTypeDropdown = page.getByTestId("rule-condition-type-dropdown"),
readonly addRuleConditionValueDropdown = page.getByTestId("rule-condition-value-dropdown"),
readonly rewardTypeSelect = page.getByTestId("reward-type-select"),
readonly rewardValueInput = page.getByTestId("reward-value-input"),
readonly rewardGiftSelect = page.getByTestId("reward-gifts-select"),
readonly percentageRewardValueTypeOption = page.getByTestId("percentage-reward-value-type"),
readonly fixedRewardValueTypeOption = page.getByTestId("fixed-reward-value-type"),
readonly saveRuleButton = page.getByTestId("saveRuleButton"),
readonly gteConditionValueInput = page.getByTestId("condition-value-0").first(),
readonly lteConditionValueInput = page.getByTestId("condition-value-0").last(),

) {
this.page = page;
}

async typePromotionRuleDescription(description: string) {
await this.ruleDescriptionInput.locator('[contenteditable="true"]').fill(description)
}

async clickChannelsDropdown() {
await this.ruleChannelDropdown.click();
}

async selectSingleChannel(channel:string) {
await this.clickChannelsDropdown();
await this.page.getByTestId("select-option").getByText(channel).click();
}

async typePromotionRuleName(name: string) {
await this.ruleNameInput.fill(name);
}

async clickFirstAddRuleConditionButton() {
await this.addFirstRuleConditionButton.click();
await this.addRuleConditionSection.waitFor({
state: "visible",
timeout: 10000,
});
}

async clickAnotherAddRuleConditionButton() {
await this.addAnotherRuleConditionButton.click();
await this.addRuleConditionSection.waitFor({
state: "visible",
timeout: 10000,
});
}

async selectPercentageRewardValueType() {
await this.percentageRewardValueTypeOption.click();
}

async selectFixedRewardValueType() {
await this.fixedRewardValueTypeOption.click();
}

async selectOrderRewardType(type: string) {
await this.rewardTypeSelect.click();
await this.selectOption.filter({hasText:type}).click()
}

async selectSubtotalDiscountType() {
await this.selectOrderRewardType("Subtotal Discount");
}

async selectGiftRewardDiscountType() {
await this.selectOrderRewardType("Gift");
}

async typeRewardValue(value: string) {
await this.rewardValueInput.fill(value);
}

async selectPredicate(predicate: string, index: number = 0) {
await this.page.getByTestId(`condition-name-${index}`).click();
await this.page.getByRole("listbox").waitFor({
state: "visible",
timeout: 10000,
});
await this.page.getByTestId('select-option').getByText(predicate, { exact: true }).click();
}

async selectRuleConditionType(type: string) {
await this.addRuleConditionTypeDropdown.last().click();
await this.page.getByRole("listbox").waitFor({
state: "visible",
timeout: 10000,
});
await this.page.getByTestId('select-option').getByText(type).click();
}

async typeRuleConditionValue(value: string, index: number = 0) {
await this.addRuleConditionValueDropdown.locator('[contenteditable="true"]')
await this.page.getByTestId(`condition-value-${index}`).click();
await this.page.getByTestId(`condition-value-${index}`).fill(value);
}

async typeRuleConditionBoundaryValues(gte: string, lte: string) {
await this.gteConditionValueInput.fill(gte);
await this.lteConditionValueInput.fill(lte);
}


async clickRuleConditionPredicateDropdown(){
await this.addRuleConditionPredicateDropdown.last().click();
await this.page.getByRole("listbox").waitFor({
state: "visible",
timeout: 10000,
});
}

async selectGiftReward(giftName: string) {
await this.rewardGiftSelect.fill(giftName);
await this.page.getByRole("listbox").waitFor({
state: "visible",
timeout: 10000,
});
await this.page.getByTestId('select-option').getByText(giftName).first().click();
}

async selectRuleConditionValue(name: string) {
await this.addRuleConditionValueDropdown.locator('[contenteditable="true"]')
await this.page.getByTestId('condition-value-0').click();
await this.page.getByTestId('condition-value-0').fill(name);
await this.page.getByTestId('select-option').getByText(name, { exact: false }).first().click();
}

async clickSaveRuleButton() {
await this.saveRuleButton.click();
}
}
20 changes: 13 additions & 7 deletions playwright/pages/discountsPage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { Page } from "@playwright/test";
import { URL_LIST } from "@data/url";
import { DeleteDiscountDialog } from "@dialogs/deleteDiscountDialog";
import { PromotionRuleDialog } from "@pages/dialogs/promotionRuleDialog";

import { BasePage } from "@pages/basePage";
import { date } from "faker";

export class DiscountsPage extends BasePage {
deleteDialog: DeleteDiscountDialog;
promotionRuleDialog: PromotionRuleDialog;


constructor(
Expand All @@ -25,12 +27,14 @@ export class DiscountsPage extends BasePage {
readonly addRuleButton = page.getByTestId("add-rule"),
readonly editRuleButton = page.getByTestId("rule-edit-button"),
readonly deleteRuleButton = page.getByTestId("rule-delete-button"),
readonly existingRule = page.getByTestId("added-rule"),
readonly addRuleDialog = page.getByTestId("add-rule-dialog"),
readonly ruleSection = page.getByTestId("rule-list"),
readonly existingRule = ruleSection.getByTestId("added-rule"),

) {
super(page)
this.deleteDialog = new DeleteDiscountDialog(page);
this.promotionRuleDialog = new PromotionRuleDialog(page);
}
async clickCreateDiscountButton() {
await this.createDiscountButton.click();
Expand Down Expand Up @@ -89,15 +93,17 @@ export class DiscountsPage extends BasePage {
});
}

async clickEditRuleButton() {
await this.editRuleButton.click();
}
async clickAddRuleButton() {
await this.page.getByTestId('add-rule').click();}

async clickEditRuleButton(){
await this.page.getByTestId('rule-edit-button').click();}

async clickDeleteRuleButton() {
await this.deleteRuleButton.click() }

async openExistingPromotionRuleModal(promotionId: string) {
await this.gotoExistingDiscount(promotionId);
await this.editRuleButton.click();
async openPromotionRuleModal() {
await this.addRuleButton.click();
await this.addRuleDialog.waitFor({
state: "visible",
timeout: 10000,
Expand Down
Loading

0 comments on commit f845150

Please sign in to comment.