Skip to content

Commit

Permalink
[E2E] Tests for page types (#4765)
Browse files Browse the repository at this point in the history
* add changeset

* add test data

* add tests and  update data-test-id

* code review fixes

* spaces
  • Loading branch information
szczecha authored Apr 3, 2024
1 parent a246798 commit ec21ae3
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-kids-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Add playwright tests for page types
143 changes: 86 additions & 57 deletions playwright/data/e2eTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ export const ATTRIBUTES = {
],
},
attributesToBeUpdated:
[ {name:
"e2e product attribute to be updated 1",
[{
name:
"e2e product attribute to be updated 1",
id: "QXR0cmlidXRlOjc0MA=="
},
{ name: "e2e content attribute to be updated 2", id: "QXR0cmlidXRlOjczOQ==" }
},
{ name: "e2e content attribute to be updated 2", id: "QXR0cmlidXRlOjczOQ==" }
],
attributeTypesWithAbilityToAddValues:{names:
["DROPDOWN","MULTISELECT","SWATCH",]
attributeTypesWithAbilityToAddValues: {
names:
["DROPDOWN", "MULTISELECT", "SWATCH",]
},
attributeTypesWithoutAbilityToAddValues: {
names:
Expand All @@ -46,8 +48,9 @@ export const ATTRIBUTES = {
"DATE",
"DATE_TIME",]
},
attributeReferencesEntities: {names: ["PAGE", "PRODUCT", "PRODUCT_VARIANT"]},
}
attributeReferencesEntities: { names: ["PAGE", "PRODUCT", "PRODUCT_VARIANT"] },
attributeToBeAssignedToPageType: { name: "Attribute to be assigned to page type" },
}
export const VOUCHERS = {
vouchers: {
voucherToBeEditedWithFreeShipping: {
Expand Down Expand Up @@ -77,49 +80,55 @@ 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"
},
},
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: "UHJvbW90aW9uUnVsZTozMTEyMTE0Yy1hYjFkLTQ3OTktODY0My1jZDhlODMwYzllZmE=",
name: "rule 2"
},

{
id: "UHJvbW90aW9uUnVsZTozOWE3Zjc1Zi1jYTdmLTQ4ODgtOGE4NC02NzdjMTVhOGQ4Yjc=",
name: "rule 3"
}
{
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"},
],
},
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: "UHJvbW90aW9uUnVsZTo1MzQwNjEyYy0wOWJhLTQxYzUtYmY2Yy1lYmUzZTQ3MjY0MjY=",
name: "rule #2"
},

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

],
],
},
orderPromotionWithRulesToBeUpdated: {
id: "UHJvbW90aW9uOjI0Njg3NmM5LWM1ZWMtNDBiYi1iMzExLWE3YWQ2YzBiZDc4NQ==",
Expand All @@ -138,7 +147,7 @@ name: "rule #3"}
name: "rule 2",
channel: "Channel-PLN",
channelCurrency: "PLN",
giftRewardToBeDeleted:"UHJvZHVjdFZhcmlhbnQ6MjE0"
giftRewardToBeDeleted: "UHJvZHVjdFZhcmlhbnQ6MjE0"
},
],
},
Expand All @@ -162,17 +171,17 @@ name: "rule #3"}
},
],
},
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==",
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 @@ -526,3 +535,23 @@ export const TRANSLATIONS = {
info: "Translation used in clear translation test",
}
}

export const PAGE_TYPES = {
pageTypeToBeEdited: {
id: "UGFnZVR5cGU6MzQ=",
name: "A page type to be edited",
info: "Page type used in edit page type test",
},
pageTypeToBeRemoved: {
id: "UGFnZVR5cGU6MzU=",
name: "A page type to be removed",
info: "Page type used in delete page type test",
},
pageTypesToBeBulkDeleted: {
names: [
"a page type to be bulk deleted 1/2",
"a page type to be bulk deleted 2/2",
],
ids: ["UGFnZVR5cGU6MzY=", "UGFnZVR5cGU6Mzc="]
},
}
37 changes: 37 additions & 0 deletions playwright/pages/dialogs/assignAttributeDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Page, expect } from "@playwright/test";

export class AssignAttributeDialog {
readonly page: Page;

constructor(
page: Page,
readonly assignAttributesSearchInput =
page.getByTestId("attribute-search-input").locator("input"),
readonly attributesList = page.getByTestId("attributes-list"),
readonly assignAndSaveButton = page.getByTestId("assign-and-save-button"),
) {
this.page = page;
}

async searchAttribute(attributeName: string) {
await this.assignAttributesSearchInput.fill(attributeName);
await expect(this.attributesList).toContainText(attributeName);
}

async clickAssignAndSaveButton() {
await this.assignAndSaveButton.click();
await this.assignAndSaveButton.waitFor({ state: "hidden" });
}

async assignSpecificAttributeByNameAndSave(attributeName: string) {
const specificAttributeCheckbox = await this.page
.getByRole("row", { name: attributeName })
.getByRole("checkbox");
await this.attributesList.waitFor({ state: "visible" });
await this.searchAttribute(attributeName);
await specificAttributeCheckbox.click();
await this.clickAssignAndSaveButton();
await this.assignAndSaveButton.waitFor({ state: "hidden" });
}

}
6 changes: 6 additions & 0 deletions playwright/pages/dialogs/deleteDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class DeleteDialog {
readonly confirmDeletionCheckbox = page.locator(
"[name='delete-assigned-items-consent']",
),
readonly confirmDeleteButton = page.getByTestId("confirm-delete")
) {
this.page = page;
}
Expand All @@ -20,4 +21,9 @@ export class DeleteDialog {
async clickConfirmDeletionCheckbox() {
await this.confirmDeletionCheckbox.click();
}

async clickConfirmDeleteButton() {
await this.confirmDeleteButton.click();
await this.confirmDeleteButton.waitFor({ state: "hidden" });
}
}
64 changes: 63 additions & 1 deletion playwright/pages/pageTypesPage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,74 @@
import type { Page } from "@playwright/test";
import { URL_LIST } from "@data/url";
import { BasePage } from "@pages/basePage";
import { DeleteDialog } from "@pages/dialogs/deleteDialog";
import { AssignAttributeDialog } from "@pages/dialogs/assignAttributeDialog";

export class PageTypesPage {
export class PageTypesPage extends BasePage {
readonly page: Page;
readonly basePage: BasePage;
readonly deletePageTypeDialog: DeleteDialog;
readonly attributeDialog: AssignAttributeDialog;

constructor(
page: Page,
readonly createPageTypeButton = page.getByTestId("create-page-type"),
readonly nameInput = page.getByTestId("page-type-name").locator("input"),
readonly saveButton = page.getByTestId("button-bar-confirm"),
readonly bulkDeleteButton = page.getByTestId("bulk-delete-page-types"),
readonly pageTypeList = page.getByTestId("page-types-list"),
readonly rowCheckbox = page.getByTestId("checkbox"),
readonly assignAttributesButton = page.getByTestId("assign-attributes"),
readonly pageAttributes = page.getByTestId("page-attributes"),
) {
super(page);
this.page = page;
this.basePage = new BasePage(page);
this.deletePageTypeDialog = new DeleteDialog(page);
this.attributeDialog = new AssignAttributeDialog(page);
}
async assignAttributes(attributeName: string) {
await this.assignAttributesButton.click();
await this.attributeDialog.assignSpecificAttributeByNameAndSave(attributeName)
}

async gotoPageTypeListPage() {
await this.page.goto(URL_LIST.pageTypes);
}

async clickCreatePageTypeButton() {
await this.createPageTypeButton.click();
}

async typePageTypeName(name: string) {
await this.nameInput.fill(name);
}

async updatePageTypeName(name: string) {
await this.nameInput.clear();
await this.nameInput.fill(name);
}

async clickSaveButton() {
await this.saveButton.click();
}

async gotoExistingPageTypePage(pageTypeId: string) {
const existingPageTypeUrl = URL_LIST.pageTypes + pageTypeId;
await console.log(
"Navigating to page type details: " + existingPageTypeUrl,
);
await this.page.goto(existingPageTypeUrl);
}

async clickBulkDeleteButton() {
await this.bulkDeleteButton.click();
}

async checkPageTypesOnList(listRows: string[]) {
for (const row of listRows) {
const rowLocator = this.page.getByTestId(`id-${row}`);
await rowLocator.locator("input").click();
}
}
}
Loading

0 comments on commit ec21ae3

Please sign in to comment.