From 0f056427bf004d64eb6de74906db287360c657f2 Mon Sep 17 00:00:00 2001 From: wojteknowacki <124166231+wojteknowacki@users.noreply.github.com> Date: Wed, 10 Jan 2024 13:11:17 +0100 Subject: [PATCH] Gift cards tests (#4617) * Migrated warehouses tests: Edit warehouse; Delete warehouse * Migrated categories tests: Create basic category; Edit category;Bulk delete categories * Migrated warehouses tests: Edit warehouse; Delete warehouse (#4593) * Migrated warehouses tests: Edit warehouse; Delete warehouse * Update nervous-flowers-hear.md * Update nervous-flowers-hear.md * Use composites in pr automation workflow (#4597) * Use composites * Use composites * Use composites * Use composites * Use composites * changed shipping metod id in shippings tests * maintenance * add console log to goto details page actions * Trigger Build * gift cards tests * Create wicked-clocks-yawn.md * review fixes --------- Co-authored-by: Patryk Andrzejewski --- .changeset/wicked-clocks-yawn.md | 12 +++ playwright/data/e2eTestData.ts | 21 ++++ playwright/pages/basePage.ts | 4 + playwright/pages/dialogs/deleteDialog.ts | 11 +- .../pages/dialogs/issueGiftCardDialog.ts | 73 +++++++++++++ .../pages/dialogs/resendGiftCardCodeDialog.ts | 14 +++ playwright/pages/giftCardsPage.ts | 62 +++++++++++ playwright/tests/girftCards.spec.ts | 102 ++++++++++++++++++ .../GiftCardCreateDialogCodeContent.tsx | 2 +- .../GiftCardCreateDialogForm.tsx | 6 +- .../GiftCardCreateExpirySelect.tsx | 1 + ...iftCardCreateRequiresActivationSection.tsx | 1 + .../GiftCardUpdatePageHeader.tsx | 6 +- .../GiftCardSendToCustomer.tsx | 1 + 14 files changed, 312 insertions(+), 4 deletions(-) create mode 100644 .changeset/wicked-clocks-yawn.md create mode 100644 playwright/pages/dialogs/issueGiftCardDialog.ts create mode 100644 playwright/pages/dialogs/resendGiftCardCodeDialog.ts create mode 100644 playwright/pages/giftCardsPage.ts create mode 100644 playwright/tests/girftCards.spec.ts diff --git a/.changeset/wicked-clocks-yawn.md b/.changeset/wicked-clocks-yawn.md new file mode 100644 index 00000000000..2048e98d5b4 --- /dev/null +++ b/.changeset/wicked-clocks-yawn.md @@ -0,0 +1,12 @@ +--- +"saleor-dashboard": minor +--- + +Migrated gift cards tests: +- Issue gift card +- Issue gift card with specific customer and expiry date +- Resend code +- Deactivate gift card +- Activate gift card +- Edit gift card +- Bulk delete gift cards diff --git a/playwright/data/e2eTestData.ts b/playwright/data/e2eTestData.ts index 959e99f0792..3c0ccdb1345 100644 --- a/playwright/data/e2eTestData.ts +++ b/playwright/data/e2eTestData.ts @@ -66,6 +66,27 @@ export const CHANNELS = { name: "z - channel to be deleted", }, }; +export const GIFT_CARDS = { + giftCardToBeEdited: { + id: "R2lmdENhcmQ6NTM%3D", + name: "Code ending with AD47", + }, + giftCardsToBeDeleted: { + names: ["to be deleted 1/2", "to be deleted 2/2"], + }, + giftCardToBeActivated: { + id: "R2lmdENhcmQ6NTQ%3D", + name: "Code ending with 7FF8", + }, + giftCardToBeDeactivated: { + id: "R2lmdENhcmQ6NTU%3D", + name: "Code ending with F2DA", + }, + giftCardToResendCode: { + id: "R2lmdENhcmQ6Ng%3D%3D", + name: "Code ending with d_10", + }, +}; export const WAREHOUSES = { warehouseToBeEdited: { id: "V2FyZWhvdXNlOjgzNGQwYjQwLWMwZGItNGRhZi04N2RjLWQ2ODBiYzY3NGVlMw%3D%3D", diff --git a/playwright/pages/basePage.ts b/playwright/pages/basePage.ts index aa0eca89031..3d7a4892d09 100644 --- a/playwright/pages/basePage.ts +++ b/playwright/pages/basePage.ts @@ -213,6 +213,10 @@ export class BasePage { // make sure all searched texts were found and checked await expect(searchText.length).toEqual(rowIndexes.length); } + async clickListRowBasedOnContainingText(searchText: string) { + const rowIndex = await this.findRowIndexBasedOnText([searchText]); + await this.clickGridCell(1, rowIndex[0]); + } async expectElementContainsTextFromObjectValues( locator: Locator, diff --git a/playwright/pages/dialogs/deleteDialog.ts b/playwright/pages/dialogs/deleteDialog.ts index 5da29f5c34a..fb27bbe706b 100644 --- a/playwright/pages/dialogs/deleteDialog.ts +++ b/playwright/pages/dialogs/deleteDialog.ts @@ -3,7 +3,13 @@ import type { Page } from "@playwright/test"; export class DeleteDialog { readonly page: Page; - constructor(page: Page, readonly deleteButton = page.getByTestId("submit")) { + constructor( + page: Page, + readonly deleteButton = page.getByTestId("submit"), + readonly confirmDeletionCheckbox = page.locator( + "[name='delete-assigned-items-consent']", + ), + ) { this.page = page; } @@ -11,4 +17,7 @@ export class DeleteDialog { await this.deleteButton.first().click(); await this.deleteButton.waitFor({ state: "hidden" }); } + async clickConfirmDeletionCheckbox() { + await this.confirmDeletionCheckbox.click(); + } } diff --git a/playwright/pages/dialogs/issueGiftCardDialog.ts b/playwright/pages/dialogs/issueGiftCardDialog.ts new file mode 100644 index 00000000000..26abe6d2abc --- /dev/null +++ b/playwright/pages/dialogs/issueGiftCardDialog.ts @@ -0,0 +1,73 @@ +import { Page } from "@playwright/test"; + +export class IssueGiftCardDialog { + readonly page: Page; + + constructor( + page: Page, + readonly enterAmountInput = page.locator('[name="balanceAmount"]'), + readonly expiryPeriodAmountInput = page.locator( + '[name="expiryPeriodAmount"]', + ), + readonly tagsInput = page + .getByTestId("gift-card-tag-select-field") + .locator("input"), + readonly cardCode = page.getByTestId("cardCode"), + + readonly sendToCustomerCheckbox = page + .getByTestId("send-to-customer-section") + .locator("input"), + readonly sendExpireDateCheckbox = page + .getByTestId("expiry-section") + .locator("input"), + readonly customerInput = page + .getByTestId("customer-field") + .locator("input"), + readonly noteTextArea = page + .getByTestId("note-field") + .locator('[name="note"]'), + readonly requiresActivationCheckbox = page + .getByTestId("requires-activation-section") + .locator("input"), + readonly issueButton = page.getByTestId("submit"), + readonly okButton = page.getByTestId("submit"), + readonly copyCodeButton = page.getByTestId("copy-code-button"), + ) { + this.page = page; + } + + async clickIssueButton() { + await this.issueButton.click(); + } + async clickOkButton() { + await this.okButton.click(); + } + async clickCopyCodeButton() { + await this.copyCodeButton.click(); + } + async typeAmount(amount: string) { + await this.enterAmountInput.fill(amount); + } + async typeCustomer(customer: string) { + await this.customerInput.fill(customer); + } + async typeExpiryPeriodAmount(expiryPeriodAmount: string) { + await this.expiryPeriodAmountInput.fill(expiryPeriodAmount); + } + async typeTag(tag: string) { + await this.tagsInput.fill(tag); + } + async typeNote(tag: string) { + await this.noteTextArea.fill(tag); + } + + async clickSendToCustomerCheckbox() { + await this.sendToCustomerCheckbox.click(); + } + async clickSendExpireDateCheckbox() { + await this.sendExpireDateCheckbox.click(); + } + async clickRequiresActivationCheckbox() { + await this.requiresActivationCheckbox.click(); + } +} diff --git a/playwright/pages/dialogs/resendGiftCardCodeDialog.ts b/playwright/pages/dialogs/resendGiftCardCodeDialog.ts new file mode 100644 index 00000000000..7ca6dac5607 --- /dev/null +++ b/playwright/pages/dialogs/resendGiftCardCodeDialog.ts @@ -0,0 +1,14 @@ +import { Page } from "@playwright/test"; + +export class ResendGiftCardCodeDialog { + readonly page: Page; + + constructor(page: Page, readonly resendButton = page.getByTestId("submit")) { + this.page = page; + } + + async clickResendButton() { + await this.resendButton.click(); + await this.resendButton.waitFor({ state: "hidden" }); + } +} diff --git a/playwright/pages/giftCardsPage.ts b/playwright/pages/giftCardsPage.ts new file mode 100644 index 00000000000..b0faf3ddbe5 --- /dev/null +++ b/playwright/pages/giftCardsPage.ts @@ -0,0 +1,62 @@ +import { URL_LIST } from "@data/url"; +import { DeleteDialog } from "@dialogs/deleteDialog"; +import { IssueGiftCardDialog } from "@dialogs/issueGiftCardDialog"; +import { ResendGiftCardCodeDialog } from "@dialogs/resendGiftCardCodeDialog"; +import { MetadataSeoPage } from "@pageElements/metadataSeoPage"; +import { BasePage } from "@pages/basePage"; +import type { Page } from "@playwright/test"; + +export class GiftCardsPage extends BasePage { + readonly page: Page; + readonly issueGiftCardDialog: IssueGiftCardDialog; + readonly resendGiftCardCodeDialog: ResendGiftCardCodeDialog; + readonly metadataSeoPage: MetadataSeoPage; + readonly deleteDialog: DeleteDialog; + + constructor( + page: Page, + readonly issueCardButton = page.getByTestId("issue-card-button"), + readonly bulkDeleteButton = page.getByTestId("bulk-delete-button"), + readonly resendCodeButton = page.getByTestId("resend-code"), + readonly deactivateButton = page.getByTestId("enable-button"), + readonly saveButton = page.getByTestId("button-bar-confirm"), + readonly cardExpiresCheckbox = page.locator("[name='cardExpires']"), + ) { + super(page); + this.page = page; + this.issueGiftCardDialog = new IssueGiftCardDialog(page); + this.resendGiftCardCodeDialog = new ResendGiftCardCodeDialog(page); + this.metadataSeoPage = new MetadataSeoPage(page); + this.deleteDialog = new DeleteDialog(page); + } + + async clickIssueCardButton() { + await this.issueCardButton.click(); + } + async clickBulkDeleteButton() { + await this.bulkDeleteButton.click(); + } + async clickSaveButton() { + await this.saveButton.click(); + } + async clickCardExpiresCheckbox() { + await this.cardExpiresCheckbox.click(); + } + async clickDeactivateButton() { + await this.deactivateButton.click(); + } + async clickResendCodeButton() { + await this.resendCodeButton.click(); + } + async gotoGiftCardsListView() { + await this.page.goto(URL_LIST.giftCards); + } + async gotoExistingGiftCardView(giftCardId: string) { + const existingGiftCardUrl = URL_LIST.giftCards + giftCardId; + await console.log( + "Navigating to existing gift card: " + existingGiftCardUrl, + ); + + await this.page.goto(existingGiftCardUrl); + } +} diff --git a/playwright/tests/girftCards.spec.ts b/playwright/tests/girftCards.spec.ts new file mode 100644 index 00000000000..36d2f731f78 --- /dev/null +++ b/playwright/tests/girftCards.spec.ts @@ -0,0 +1,102 @@ +import { GIFT_CARDS } from "@data/e2eTestData"; +import { GiftCardsPage } from "@pages/giftCardsPage"; +import { expect, test } from "@playwright/test"; + +test.use({ storageState: "playwright/.auth/admin.json" }); +let giftCardsPage: GiftCardsPage; +test.beforeEach(({ page }) => { + giftCardsPage = new GiftCardsPage(page); +}); + +test("TC: SALEOR_105 Issue gift card @e2e @gift", async () => { + await giftCardsPage.gotoGiftCardsListView(); + await giftCardsPage.waitForGrid(); + const numberOfGiftCards = await giftCardsPage.getNumberOfGridRows(); + await giftCardsPage.clickIssueCardButton(); + await giftCardsPage.issueGiftCardDialog.typeAmount("50"); + await giftCardsPage.issueGiftCardDialog.typeTag( + "super ultra automation discount", + ); + await giftCardsPage.issueGiftCardDialog.clickRequiresActivationCheckbox(); + await giftCardsPage.issueGiftCardDialog.clickIssueButton(); + await expect(giftCardsPage.issueGiftCardDialog.cardCode).toBeVisible(); + await giftCardsPage.issueGiftCardDialog.clickCopyCodeButton(); + await giftCardsPage.expectSuccessBanner(); + await giftCardsPage.issueGiftCardDialog.clickOkButton(); + await giftCardsPage.waitForGrid(); + const numberOfGiftCardsAfterCreation = + await giftCardsPage.getNumberOfGridRows(); + expect(numberOfGiftCardsAfterCreation - numberOfGiftCards).toEqual(1); +}); +test("TC: SALEOR_106 Issue gift card with specific customer and expiry date @e2e @gift", async () => { + await giftCardsPage.gotoGiftCardsListView(); + await giftCardsPage.waitForGrid(); + const numberOfGiftCards = await giftCardsPage.getNumberOfGridRows(); + await giftCardsPage.clickIssueCardButton(); + await giftCardsPage.issueGiftCardDialog.clickSendToCustomerCheckbox(); + await giftCardsPage.issueGiftCardDialog.typeCustomer("Allison Freeman"); + await giftCardsPage.issueGiftCardDialog.clickSendExpireDateCheckbox(); + await giftCardsPage.issueGiftCardDialog.typeExpiryPeriodAmount("2"); + await giftCardsPage.issueGiftCardDialog.clickIssueButton(); + await expect(giftCardsPage.issueGiftCardDialog.cardCode).toBeVisible(); + await giftCardsPage.issueGiftCardDialog.clickOkButton(); + await giftCardsPage.waitForGrid(); + const numberOfGiftCardsAfterCreation = + await giftCardsPage.getNumberOfGridRows(); + expect(numberOfGiftCardsAfterCreation - numberOfGiftCards).toEqual(1); +}); +test("TC: SALEOR_107 Resend code @e2e @gift", async () => { + await giftCardsPage.gotoGiftCardsListView(); + await giftCardsPage.waitForGrid(); + await giftCardsPage.clickListRowBasedOnContainingText( + GIFT_CARDS.giftCardToResendCode.name, + ); + await giftCardsPage.clickResendCodeButton(); + await giftCardsPage.resendGiftCardCodeDialog.clickResendButton(); + + await giftCardsPage.expectSuccessBanner(); +}); +test("TC: SALEOR_108 Deactivate gift card @e2e @gift", async () => { + await giftCardsPage.gotoExistingGiftCardView( + GIFT_CARDS.giftCardToBeDeactivated.id, + ); + await giftCardsPage.clickDeactivateButton(); + await giftCardsPage.expectSuccessBanner(); + await expect(giftCardsPage.pageHeader).toContainText("Disabled"); +}); +test("TC: SALEOR_109 Activate gift card @e2e @gift", async () => { + await giftCardsPage.gotoExistingGiftCardView( + GIFT_CARDS.giftCardToBeActivated.id, + ); + await giftCardsPage.clickDeactivateButton(); + await giftCardsPage.expectSuccessBanner(); + await expect(giftCardsPage.pageHeader).not.toContainText("Disabled"); +}); +test("TC: SALEOR_110 Edit gift card @e2e @gift", async () => { + await giftCardsPage.gotoExistingGiftCardView( + GIFT_CARDS.giftCardToBeEdited.id, + ); + await giftCardsPage.clickCardExpiresCheckbox(); + await giftCardsPage.metadataSeoPage.expandAndAddAllMetadata(); + await giftCardsPage.clickSaveButton(); + await giftCardsPage.expectSuccessBanner(); +}); +test("TC: SALEOR_111 Bulk delete gift cards @e2e @gift", async () => { + await giftCardsPage.gotoGiftCardsListView(); + await giftCardsPage.waitForGrid(); + const numberOfGiftCards = await giftCardsPage.getNumberOfGridRows(); + + await giftCardsPage.checkListRowsBasedOnContainingText( + GIFT_CARDS.giftCardsToBeDeleted.names, + ); + await giftCardsPage.clickBulkDeleteButton(); + await giftCardsPage.deleteDialog.clickConfirmDeletionCheckbox(); + await giftCardsPage.deleteDialog.clickDeleteButton(); + await giftCardsPage.waitForGrid(); + + expect( + await giftCardsPage.findRowIndexBasedOnText( + GIFT_CARDS.giftCardsToBeDeleted.names, + ), + ).toEqual([]); +}); diff --git a/src/giftCards/GiftCardCreateDialog/GiftCardCreateDialogCodeContent.tsx b/src/giftCards/GiftCardCreateDialog/GiftCardCreateDialogCodeContent.tsx index 5416d32764d..bf97a880f87 100644 --- a/src/giftCards/GiftCardCreateDialog/GiftCardCreateDialogCodeContent.tsx +++ b/src/giftCards/GiftCardCreateDialog/GiftCardCreateDialogCodeContent.tsx @@ -45,7 +45,7 @@ const GiftCardCreateDialogCodeContent: React.FC< - diff --git a/src/giftCards/GiftCardCreateDialog/GiftCardCreateDialogForm.tsx b/src/giftCards/GiftCardCreateDialog/GiftCardCreateDialogForm.tsx index 2b9822d6862..368562d30c3 100644 --- a/src/giftCards/GiftCardCreateDialog/GiftCardCreateDialogForm.tsx +++ b/src/giftCards/GiftCardCreateDialog/GiftCardCreateDialogForm.tsx @@ -147,7 +147,10 @@ const GiftCardCreateDialogForm: React.FC = ({ return ( <> - + = ({ = ({ return ( <> = ({ checked, onChange }) => ( diff --git a/src/giftCards/GiftCardUpdate/GiftCardUpdatePageHeader/GiftCardUpdatePageHeader.tsx b/src/giftCards/GiftCardUpdate/GiftCardUpdatePageHeader/GiftCardUpdatePageHeader.tsx index 74fe680c0f3..43e3d4921a4 100644 --- a/src/giftCards/GiftCardUpdate/GiftCardUpdatePageHeader/GiftCardUpdatePageHeader.tsx +++ b/src/giftCards/GiftCardUpdate/GiftCardUpdatePageHeader/GiftCardUpdatePageHeader.tsx @@ -46,7 +46,11 @@ const GiftCardUpdatePageHeader: React.FC = () => { {!isExpired && ( - )} diff --git a/src/giftCards/components/GiftCardSendToCustomer/GiftCardSendToCustomer.tsx b/src/giftCards/components/GiftCardSendToCustomer/GiftCardSendToCustomer.tsx index 36db6b11e35..d175c168766 100644 --- a/src/giftCards/components/GiftCardSendToCustomer/GiftCardSendToCustomer.tsx +++ b/src/giftCards/components/GiftCardSendToCustomer/GiftCardSendToCustomer.tsx @@ -44,6 +44,7 @@ const GiftCardSendToCustomer: React.FC = ({ <>