Skip to content

Commit

Permalink
adding tests for promotion rules (#4722)
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowee authored Mar 21, 2024
1 parent fd8368f commit 66f565d
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-gifts-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Adding tests for promotion rules CRUD
106 changes: 92 additions & 14 deletions playwright/data/e2eTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,102 @@ export const DISCOUNTS = {
name: "e2e promotion to be edited",
type: "Catalog",
id: "UHJvbW90aW9uOjI0MGVkZGVkLWYzMTAtNGUzZi1iNTlmLTFlMGFkYWE2ZWFkYg=="
},
promotionWithoutRulesToBeDeleted: {
id: "UHJvbW90aW9uOjRmNTQwMDc1LTZlZGMtNDI1NC1hY2U2LTQ2MzdlMGYxZWJhOA==",
name: "e2e Order predicate promotion without rules",
type: "Order",
},
catalogPromotionWithRulesToBeDeleted: {
id: "UHJvbW90aW9uOmYyY2VjMDhkLTVkYmUtNGVjNC05NTNjLWMzMmQ5ZGQ2MTExYw==",
name: "e2e Catalog promo with rules to be deleted",
type: "Catalog",
rules: [
{
id: "UHJvbW90aW9uUnVsZTo3NDk4MGVhNS0zNDA2LTQxZGYtOTc3Mi1jMzg3MjNhMWEwOWM=",
name: "rule 1"
},

{
id: "UHJvbW90aW9uUnVsZTozMTEyMTE0Yy1hYjFkLTQ3OTktODY0My1jZDhlODMwYzllZmE=",
name: "rule 2"
},

{
id: "UHJvbW90aW9uUnVsZTozOWE3Zjc1Zi1jYTdmLTQ4ODgtOGE4NC02NzdjMTVhOGQ4Yjc=",
name: "rule 3"
}

],
},
orderPromotionWithRulesToBeDeleted: {
id: "UHJvbW90aW9uOjA1MDllZjhjLTc0ZTEtNGMyMC1iZDk5LWRhYWU1YWJlZDM1Nw==",
name: "e2e Order promo with rules to be deleted",
type: "Order",
rules: [
{id: "UHJvbW90aW9uUnVsZTo2ZTdlODNkOS1kNjJlLTQ2YmQtOGE2ZS03OTdlYTZiODk2NmQ=",
name: "rule #1"},

{id: "UHJvbW90aW9uUnVsZTo1MzQwNjEyYy0wOWJhLTQxYzUtYmY2Yy1lYmUzZTQ3MjY0MjY=",
name: "rule #2"},

{id: "UHJvbW90aW9uUnVsZTpjMzk5ZTM1Ni04OWFhLTQ0MTUtYWE0Zi01NThlZDQ2M2IwNTM=",
name: "rule #3"}

],
},
promotionWithoutRulesToBeDeleted: {
id: "UHJvbW90aW9uOjRmNTQwMDc1LTZlZGMtNDI1NC1hY2U2LTQ2MzdlMGYxZWJhOA==",
name: "e2e Order predicate promotion without rules",
orderPromotionWithRulesToBeUpdated: {
id: "UHJvbW90aW9uOjI0Njg3NmM5LWM1ZWMtNDBiYi1iMzExLWE3YWQ2YzBiZDc4NQ==",
name: "e2e Order promo with rules to be updated",
type: "Order",
rules: [
{
id: "UHJvbW90aW9uUnVsZTo3NmEwOGYzZi0xMzZhLTRmNTUtYTc0NS1kZmIxNDZkOWI4ZGQ=",
name: "rule 1",
channel: "Channel-PLN",
channelCurrency: "PLN",
},

{
id: "UHJvbW90aW9uUnVsZTpjODIxMWJhNS05ZGRmLTRhYzQtOTdlMS04YmM0MzNhZjRlOTM=",
name: "rule 2",
channel: "Channel-PLN",
channelCurrency: "PLN",
giftRewardToBeDeleted:"UHJvZHVjdFZhcmlhbnQ6MjE0"
},
],
},
promotionWithRulesToBeDeleted: {
name: "e2e Catalog predicate promotion with rules",
id: "UHJvbW90aW9uOjY0N2M2MzdhLTZjNTEtNDYxZC05MjQ2LTc0YTY0OGM0ZjAxNA==",
},
cataloguePromotion: {
name: "e2e Catalog promotion for adding rules",
id: "UHJvbW90aW9uOjNmODZjZDAwLTUwNWEtNGVkNC04ZTliLTJmOGI4NGM3NGNlOQ==",
catalogPromotionWithRulesToBeUpdated: {
id: "UHJvbW90aW9uOmJkZTgyNGQ4LTk4ZTktNDM1NC04ODE4LTE1YzVjNmI2MWU2NQ==",
name: "e2e Catalog promo with rules to be updated",
type: "Catalog",
rules: [
{
id: "UHJvbW90aW9uUnVsZTplOWZjNjc2NS1kNzM2LTRhMzMtYjBiMy1hZWMxY2FmNGVkMDE=",
name: "rule #1",
channel: "Channel-USD",
channelCurrency: "USD",
},

{
id: "UHJvbW90aW9uUnVsZToyZjM3ZjRhOS01NjY0LTQzMDEtOWU4Zi0zZTliZGFjNmUyYjE=",
name: "rule 2",
channel: "Channel-USD",
channelCurrency: "USD",
},
],
},
orderPromotion: {
name: "e2e Order promotion for adding rules",
id: "UHJvbW90aW9uOjJlM2VhNDkyLTRhMTAtNDYzOS05MWVmLTc1YzQ1OTUxNGQyMQ==",
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==",
},
}

Expand Down Expand Up @@ -397,4 +475,4 @@ export const TRANSLATIONS = {
name: "Summer collection",
info: "Translation used in clear translation test",
}
}
}
7 changes: 3 additions & 4 deletions playwright/pages/dialogs/deleteDiscountDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ export class DeleteDiscountDialog {

constructor(
page: Page,
readonly deleteButton = page.getByTestId(
"delete-confirmation-button",
),
) {
readonly deleteButton = page.getByTestId("delete-confirmation-button")

) {
this.page = page;
}

Expand Down
20 changes: 20 additions & 0 deletions playwright/pages/dialogs/deleteRuleDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Page } from "@playwright/test";

export class DeleteRuleDialog {
readonly page: Page;

constructor(
page: Page,
readonly deleteRuleButton = page.getByTestId("delete-rule-button"),
readonly cancelButton = page.getByTestId("cancel-delete-rule-button"),
) {
this.page = page;
}

async clickConfirmDeleteButton() {
await this.deleteRuleButton.click()
}
async cancelDeletion() {
await this.cancelButton.click();
}
}
54 changes: 20 additions & 34 deletions playwright/pages/dialogs/promotionRuleDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export class PromotionRuleDialog {
"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 addRuleConditionButton = page.getByTestId("add-condition-button"),
readonly addRuleConditionSection = page.getByTestId("conditions-section"),
readonly addRuleConditionPredicateDropdown = page.getByTestId("rule-condition-predicate-dropdown"),
readonly addRuleConditionTypeDropdown = page.getByTestId("rule-condition-type-dropdown"),
Expand All @@ -23,8 +22,11 @@ export class PromotionRuleDialog {
readonly percentageRewardValueTypeOption = page.getByTestId("percentage-reward-value-type"),
readonly fixedRewardValueTypeOption = page.getByTestId("fixed-reward-value-type"),
readonly saveRuleButton = page.getByTestId("saveRuleButton"),
readonly ruleConfirmationButton = page.getByTestId("saveRuleButton"),
readonly gteConditionValueInput = page.getByTestId("condition-value-0").first(),
readonly lteConditionValueInput = page.getByTestId("condition-value-0").last(),
readonly ruleConditionRow = page.getByTestId("rule-condition-row"),


) {
this.page = page;
Expand All @@ -47,20 +49,16 @@ export class PromotionRuleDialog {
await this.ruleNameInput.fill(name);
}

async clickFirstAddRuleConditionButton() {
await this.addFirstRuleConditionButton.click();
await this.addRuleConditionSection.waitFor({
async clickAddRuleConditionButton() {
await this.addRuleConditionButton.click({force: true});
await this.ruleConditionRow.last().waitFor({
state: "visible",
timeout: 10000,
});
}

async clickAnotherAddRuleConditionButton() {
await this.addAnotherRuleConditionButton.click();
await this.addRuleConditionSection.waitFor({
state: "visible",
timeout: 10000,
});
async removeExistingGiftReward(giftRewardId: string, index: number = 0) {
await this.page.getByTestId(`selected-option-${giftRewardId}-${index}`).getByText('✕').click();
}

async selectPercentageRewardValueType() {
Expand All @@ -73,7 +71,7 @@ export class PromotionRuleDialog {

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

async selectSubtotalDiscountType() {
Expand All @@ -90,25 +88,15 @@ export class PromotionRuleDialog {

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();
await this.page.getByRole('option', { name: 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();
await this.page.getByTestId("select-option").filter({hasText: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);
}

Expand All @@ -118,7 +106,7 @@ export class PromotionRuleDialog {
}


async clickRuleConditionPredicateDropdown(){
async clickRuleConditionPredicateDropdown() {
await this.addRuleConditionPredicateDropdown.last().click();
await this.page.getByRole("listbox").waitFor({
state: "visible",
Expand All @@ -128,21 +116,19 @@ export class PromotionRuleDialog {

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();
await this.page.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();
await this.page.getByTestId("condition-value-0").click()
await this.page.getByRole('option', { name, }).first().click();
}

async clickSaveRuleButton() {
await this.saveRuleButton.click();
}

async clickSaveEditedRuleButton() {
await this.ruleConfirmationButton.click();
}
}
31 changes: 20 additions & 11 deletions playwright/pages/discountsPage.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { Page } from "@playwright/test";
import { URL_LIST } from "@data/url";
import { DeleteDiscountDialog } from "@dialogs/deleteDiscountDialog";
import { DeleteRuleDialog } from "@dialogs/deleteRuleDialog";
import { PromotionRuleDialog } from "@pages/dialogs/promotionRuleDialog";

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

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

deleteRuleDialog: DeleteRuleDialog;

constructor(
page: Page,
Expand All @@ -27,15 +28,20 @@ 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 ruleName = page.getByTestId("rule-name"),
readonly addRuleDialog = page.getByTestId("add-rule-dialog"),
readonly ruleSection = page.getByTestId("rule-list"),
readonly existingRule = ruleSection.getByTestId("added-rule"),

readonly ruleLabelWithActions = page.getByTestId("rule-label-with-actions"),
readonly ruleSummaryChip = page.getByTestId("rule-summary-chip"),
readonly ruleValueChip = page.getByTestId("rule-value-chip"),
readonly deleteRuleModal = page.getByTestId("delete-rule-dialog"),
) {
super(page)
this.deleteDialog = new DeleteDiscountDialog(page);
this.deleteDiscountDialog = new DeleteDiscountDialog(page);
this.promotionRuleDialog = new PromotionRuleDialog(page);
}
this.deleteRuleDialog = new DeleteRuleDialog(page);
}
async clickCreateDiscountButton() {
await this.createDiscountButton.click();
}
Expand Down Expand Up @@ -89,18 +95,21 @@ export class DiscountsPage extends BasePage {

await this.discountForm.waitFor({
state: "visible",
timeout: 10000,
timeout: 30000,
});
}

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

async clickEditRuleButton(){
await this.page.getByTestId('rule-edit-button').click();}
async clickEditRuleButton(rule: string) {
await this.existingRule.locator(this.ruleLabelWithActions).filter({ hasText: rule }).locator(this.editRuleButton).click();
}

async clickDeleteRuleButton() {
await this.deleteRuleButton.click() }
async clickDeleteRuleButton(rule: string) {
await this.existingRule.locator(this.ruleLabelWithActions).filter({ hasText: rule }).locator(this.deleteRuleButton).click();
}

async openPromotionRuleModal() {
await this.addRuleButton.click();
Expand Down
Loading

0 comments on commit 66f565d

Please sign in to comment.