Skip to content

Commit

Permalink
Gift cards tests (#4617)
Browse files Browse the repository at this point in the history
* 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 <vox3r69@gmail.com>
  • Loading branch information
wojteknowacki and andrzejewsky committed Jan 10, 2024
1 parent d43a3c9 commit 0f05642
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .changeset/wicked-clocks-yawn.md
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions playwright/data/e2eTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions playwright/pages/basePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion playwright/pages/dialogs/deleteDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ 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;
}

async clickDeleteButton() {
await this.deleteButton.first().click();
await this.deleteButton.waitFor({ state: "hidden" });
}
async clickConfirmDeletionCheckbox() {
await this.confirmDeletionCheckbox.click();
}
}
73 changes: 73 additions & 0 deletions playwright/pages/dialogs/issueGiftCardDialog.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
14 changes: 14 additions & 0 deletions playwright/pages/dialogs/resendGiftCardCodeDialog.ts
Original file line number Diff line number Diff line change
@@ -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" });
}
}
62 changes: 62 additions & 0 deletions playwright/pages/giftCardsPage.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
102 changes: 102 additions & 0 deletions playwright/tests/girftCards.spec.ts
Original file line number Diff line number Diff line change
@@ -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([]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const GiftCardCreateDialogCodeContent: React.FC<
<VerticalSpacer spacing={2} />
</DialogContent>
<DialogActions>
<Button onClick={onCopyCode}>
<Button onClick={onCopyCode} data-test-id="copy-code-button">
{intl.formatMessage(messages.copyCodeLabel)}
</Button>
<HorizontalSpacer spacing={2} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ const GiftCardCreateDialogForm: React.FC<GiftCardCreateDialogFormProps> = ({

return (
<>
<DialogContent className={classes.dialogContent}>
<DialogContent
className={classes.dialogContent}
data-test-id="gift-card-dialog"
>
<GiftCardCreateMoneyInput {...commonFormProps} set={set} />
<CardSpacer />
<GiftCardTagInput
Expand All @@ -171,6 +174,7 @@ const GiftCardCreateDialogForm: React.FC<GiftCardCreateDialogFormProps> = ({
<GiftCardCreateExpirySelect {...commonFormProps} />
<VerticalSpacer />
<TextField
data-test-id="note-field"
name="note"
onChange={change}
multiline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const GiftCardCreateExpirySelect: React.FC<GiftCardCreateExpirySelectProps> = ({
return (
<>
<ControlledCheckbox
data-test-id="expiry-section"
name={"expirySelected"}
label={intl.formatMessage(messages.expirySelectedLabel)}
checked={expirySelected}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const GiftCardCreateRequiresActivationSection: React.FC<
GiftCardCreateRequiresActivationSectionProps
> = ({ checked, onChange }) => (
<ControlledCheckbox
data-test-id="requires-activation-section"
name="requiresActivation"
label={
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ const GiftCardUpdatePageHeader: React.FC = () => {
<GiftCardEnableDisableSection />
<HorizontalSpacer />
{!isExpired && (
<Button variant="primary" onClick={openResendCodeDialog}>
<Button
variant="primary"
onClick={openResendCodeDialog}
data-test-id="resend-code"
>
{intl.formatMessage(messages.resendButtonLabel)}
</Button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const GiftCardSendToCustomer: React.FC<GiftCardSendToCustomerProps> = ({
<>
<VerticalSpacer />
<ControlledCheckbox
data-test-id="send-to-customer-section"
name={"sendToCustomerSelected"}
label={intl.formatMessage(messages.sendToCustomerSelectedLabel)}
checked={sendToCustomerSelected}
Expand Down

0 comments on commit 0f05642

Please sign in to comment.