-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tests for creating promotions (#4683)
- Loading branch information
Showing
20 changed files
with
252 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": minor | ||
--- | ||
|
||
Adding e2e tests for promotion CRUD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
export const LOCATORS = { | ||
saveButton: "[data-test-id=\"button-bar-confirm\"]", | ||
successBanner: "[data-test-type=\"success\"]", | ||
errorBanner: "[data-test-type=\"error\"]", | ||
infoBanner: "[data-test-type=\"info\"]", | ||
dataGridTable: "[data-testid=\"data-grid-canvas\"]", | ||
deleteButton: "[data-test-id=\"button-bar-delete\"]", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Page } from "@playwright/test"; | ||
|
||
export class DeleteDiscountDialog { | ||
readonly page: Page; | ||
|
||
constructor( | ||
page: Page, | ||
readonly deleteButton = page.getByTestId( | ||
"delete-confirmation-button", | ||
), | ||
) { | ||
this.page = page; | ||
} | ||
|
||
async clickConfirmDeleteButton() { | ||
await this.deleteButton.click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,106 @@ | ||
import type { Page } from "@playwright/test"; | ||
import { URL_LIST } from "@data/url"; | ||
import { DeleteDiscountDialog } from "@dialogs/deleteDiscountDialog"; | ||
|
||
import { BasePage } from "@pages/basePage"; | ||
import { date } from "faker"; | ||
|
||
export class DiscountsPage extends BasePage { | ||
deleteDialog: DeleteDiscountDialog; | ||
|
||
export class DiscountsPage { | ||
readonly page: Page; | ||
|
||
constructor( | ||
page: Page, | ||
readonly createDiscountButton = page.getByTestId("create-sale"), | ||
readonly discountForm = page.getByTestId("discount-form"), | ||
readonly discountNameInput = page.getByTestId("discount-name-input"), | ||
readonly discountTypeSelect = page.getByTestId("discount-type-select"), | ||
readonly activeDatesSection = page.getByTestId("active-dates-section"), | ||
readonly startDateInput = page.getByTestId("start-date-input"), | ||
readonly startHourInput = page.getByTestId("start-hour-input"), | ||
readonly endDateCheckbox = page.getByTestId("has-end-date"), | ||
readonly endDateInput = page.getByTestId("end-date-input"), | ||
readonly endHourInput = page.getByTestId("end-hour-input"), | ||
readonly discountDescriptionInput = page.getByTestId("rich-text-editor-description"), | ||
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"), | ||
) { | ||
this.page = page; | ||
super(page) | ||
this.deleteDialog = new DeleteDiscountDialog(page); | ||
} | ||
async clickCreateDiscountButton() { | ||
await this.createDiscountButton.click(); | ||
} | ||
|
||
async typeDiscountName(name: string) { await this.discountNameInput.fill(name) } | ||
|
||
async selectDiscountType(type: string) { | ||
await this.discountTypeSelect.click() | ||
await this.page.getByRole("listbox").waitFor({ | ||
state: "visible", | ||
timeout: 10000, | ||
}); | ||
await this.page.getByTestId("select-option").filter({ hasText: type }).click(); | ||
} | ||
|
||
async typePromotionDescription(description: string) { | ||
await this.discountDescriptionInput.locator('[contenteditable="true"]').fill(description); | ||
} | ||
|
||
async typeStartDate() { | ||
await this.startDateInput.fill(date.recent().toISOString().split("T")[0]) | ||
} | ||
|
||
async typeStartHour() { | ||
await this.startHourInput.fill("12:00"); | ||
} | ||
|
||
async clickEndDateCheckbox() { | ||
await this.endDateCheckbox.click(); | ||
} | ||
|
||
async typeEndDate() { | ||
await this.endDateInput.fill(date.future().toISOString().split("T")[0]); | ||
} | ||
async typeEndHour() { | ||
await this.endHourInput.fill("12:00") | ||
} | ||
async gotoListView() { | ||
await this.page.goto(URL_LIST.discounts); | ||
await this.createDiscountButton.waitFor({ | ||
state: "visible", | ||
timeout: 10000, | ||
}); | ||
} | ||
async gotoExistingDiscount(promotionId: string) { | ||
const existingDiscountUrl = `${URL_LIST.discounts}${promotionId}`; | ||
await console.log( | ||
`Navigates to existing discount page: ${existingDiscountUrl}`, | ||
); | ||
await this.page.goto(existingDiscountUrl); | ||
|
||
await this.discountForm.waitFor({ | ||
state: "visible", | ||
timeout: 10000, | ||
}); | ||
} | ||
|
||
async clickEditRuleButton() { | ||
await this.editRuleButton.click(); | ||
} | ||
async clickDeleteRuleButton() { | ||
await this.deleteRuleButton.click() } | ||
|
||
async openExistingPromotionRuleModal(promotionId: string) { | ||
await this.gotoExistingDiscount(promotionId); | ||
await this.editRuleButton.click(); | ||
await this.addRuleDialog.waitFor({ | ||
state: "visible", | ||
timeout: 10000, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { DISCOUNTS } from "@data/e2eTestData"; | ||
import { DiscountsPage } from "@pages/discountsPage"; | ||
import { expect, test } from "@playwright/test"; | ||
import faker from "faker"; | ||
|
||
test.use({ storageState: "playwright/.auth/admin.json" }); | ||
let discounts: DiscountsPage; | ||
|
||
|
||
test.beforeEach(({ page }) => { | ||
discounts = new DiscountsPage(page); | ||
}); | ||
|
||
const discountType = ['Order', 'Catalog']; | ||
for (const type of discountType) { | ||
test(`TC: SALEOR_97 Create promotion with ${type} predicate @discounts @e2e`, async () => { | ||
const discountName = `${faker.lorem.word()}+${type}`; | ||
await discounts.gotoListView(); | ||
await discounts.clickCreateDiscountButton(); | ||
await discounts.typeDiscountName(discountName); | ||
await discounts.selectDiscountType(type); | ||
await discounts.typePromotionDescription(faker.lorem.sentence()); | ||
await discounts.typeStartDate(); | ||
await discounts.typeStartHour(); | ||
await discounts.clickEndDateCheckbox(); | ||
await discounts.typeEndDate(); | ||
await discounts.typeEndHour(); | ||
await discounts.clickSaveButton(); | ||
await expect(discounts.successBanner).toBeVisible({ timeout: 10000 }); | ||
await expect(discounts.pageHeader).toHaveText(discountName); | ||
await expect(discounts.discountTypeSelect).toHaveText(type); | ||
await expect(discounts.ruleSection).toHaveText("Add your first rule to set up a promotion"); | ||
})}; | ||
|
||
|
||
test(`TC: SALEOR_98 Update existing promotion @discounts @e2e`, async () => { | ||
const newDiscountName = `${faker.lorem.word()}`; | ||
await discounts.gotoExistingDiscount(DISCOUNTS.promotionToBeEdited.id); | ||
await discounts.ruleSection.waitFor({ | ||
state: "visible", | ||
timeout: 10000, | ||
}); | ||
await expect(discounts.discountNameInput).toHaveValue(DISCOUNTS.promotionToBeEdited.name, {timeout: 30000}); | ||
await discounts.discountNameInput.clear(); | ||
await discounts.typeDiscountName(newDiscountName); | ||
await discounts.typePromotionDescription(faker.lorem.sentence()); | ||
await discounts.typeStartDate(); | ||
await discounts.typeStartHour(); | ||
await discounts.clickEndDateCheckbox(); | ||
await expect(discounts.endDateInput).not.toBeAttached(); | ||
await expect(discounts.endHourInput).not.toBeAttached(); | ||
await discounts.clickSaveButton(); | ||
await expect(discounts.successBanner).toBeVisible({ timeout: 10000 }); | ||
await expect(discounts.pageHeader).toHaveText(newDiscountName); | ||
await expect(discounts.discountTypeSelect).toHaveText(DISCOUNTS.promotionToBeEdited.type); | ||
}) | ||
|
||
const promotions = [DISCOUNTS.promotionWithoutRulesToBeDeleted, DISCOUNTS.promotionWithRulesToBeDeleted]; | ||
for (const promotion of promotions) { | ||
test(`TC: SALEOR_99 Delete existing ${promotion.name} @discounts @e2e`, async () => { | ||
await discounts.gotoExistingDiscount(promotion.id); | ||
await discounts.ruleSection.waitFor({ | ||
state: "visible", | ||
timeout: 10000, | ||
}); | ||
await expect(discounts.discountNameInput).toHaveValue(promotion.name, {timeout: 30000}); | ||
await discounts.clickDeleteButton(); | ||
await discounts.deleteDialog.clickConfirmDeleteButton(); | ||
await expect(discounts.successBanner).toBeVisible({ timeout: 10000 }); | ||
})}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.