Skip to content

Commit

Permalink
test(playwright): Convert Cypress tests to Playwright - 3
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire committed Dec 20, 2023
1 parent 53b09cc commit 5d03e45
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 152 deletions.
25 changes: 0 additions & 25 deletions cypress/e2e/slices/01-duplicates.cy.js

This file was deleted.

45 changes: 0 additions & 45 deletions cypress/e2e/updates/changelog.cy.js

This file was deleted.

74 changes: 0 additions & 74 deletions cypress/e2e/updates/simulator-tooltip.cy.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const CustomTypeBuilder: FC<CustomTypeBuilderProps> = (props) => {
onAddNewTab={() => {
setDialog({ type: "CREATE_CUSTOM_TYPE" });
}}
iconButtonTestId={{ "data-cy": "add-tab-button" }}
>
{customType.tabs.map((tab) => (
<WindowTabsTrigger
Expand Down
8 changes: 6 additions & 2 deletions packages/slice-machine/src/components/Window/Window.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ export const WindowTabs: FC<WindowTabsProps> = (props) => (
<Tabs.Root {...props} activationMode="manual" className={styles.tabs} />
);

type WindowTabsListProps = PropsWithChildren<{ onAddNewTab?: () => void }>;
type WindowTabsListProps = PropsWithChildren<{
onAddNewTab?: () => void;
iconButtonTestId?: { [name: string]: string };
}>;

export const WindowTabsList: FC<WindowTabsListProps> = ({
children,
onAddNewTab,
iconButtonTestId,
...otherProps
}) => (
<Tabs.List {...otherProps} className={styles.tabsList}>
{children}
<div className={styles.newTabButton}>
<IconButton icon="add" onClick={onAddNewTab} />
<IconButton icon="add" onClick={onAddNewTab} {...iconButtonTestId} />
</div>
</Tabs.List>
);
Expand Down
23 changes: 20 additions & 3 deletions playwright/pages/ChangelogPage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Locator, Page } from "@playwright/test";
import { Locator, Page, expect } from "@playwright/test";

import { SliceMachinePage } from "./SliceMachinePage";

export class ChangelogPage extends SliceMachinePage {
readonly path: string;
readonly breadcrumbLabel: Locator;
readonly breakingChangesWarning: Locator;

constructor(page: Page) {
super(page);
Expand All @@ -16,7 +18,12 @@ export class ChangelogPage extends SliceMachinePage {
/**
* Static locators
*/
this.path = "/changelog";
this.breadcrumbLabel = this.body.getByText("Changelog", { exact: true });
this.breakingChangesWarning = this.body.getByText(
"This update includes breaking changes. To update correctly, follow the steps below.",
{ exact: true },
);
}

/**
Expand All @@ -27,10 +34,20 @@ export class ChangelogPage extends SliceMachinePage {
/**
* Actions
*/
// Handle actions here
async goto() {
await this.page.goto(this.path);
}

async selectVersion(version: string) {
await this.body.getByText(version, { exact: true }).click();
}

/**
* Assertions
*/
// Handle assertions here
async checkReleaseNotes(releaseNotes: string) {
await expect(
this.body.getByText(releaseNotes, { exact: true }),
).toBeVisible();
}
}
4 changes: 4 additions & 0 deletions playwright/pages/SliceBuilderPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class SliceBuilderPage extends BuilderPage {
readonly renameVariationDialog: RenameVariationDialog;
readonly deleteVariationDialog: DeleteVariationDialog;
readonly savedMessage: Locator;
readonly simulateTooltipTitle: Locator;
readonly simulateTooltipCloseButton: Locator;
readonly variationCards: Locator;
readonly addVariationButton: Locator;
readonly staticZone: Locator;
Expand Down Expand Up @@ -39,6 +41,8 @@ export class SliceBuilderPage extends BuilderPage {
this.savedMessage = page.getByText("Slice saved successfully", {
exact: false,
});
this.simulateTooltipTitle = page.getByText("Simulate your slices");
this.simulateTooltipCloseButton = page.getByText("Got it");
// Variations
this.variationCards = page.getByRole("link", {
name: "slice card",
Expand Down
47 changes: 47 additions & 0 deletions playwright/pages/components/AddTabDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { expect, Locator, Page } from "@playwright/test";

import { Dialog } from "./Dialog";

export class AddTabDialog extends Dialog {
readonly idInput: Locator;

constructor(page: Page) {
super(page, {
title: "Add Tab",
submitName: "Save",
});

/**
* Components
*/
// Handle components here

/**
* Static locators
*/
this.idInput = this.dialog.getByPlaceholder(
"A label for selecting the tab (i.e. not used in the API)",
{ exact: true },
);
}

/**
* Dynamic locators
*/
// Handle dynamic locators here

/**
* Actions
*/
async createTab(name: string) {
await expect(this.title).toBeVisible();
await this.idInput.fill(name);
await this.submitButton.click();
await expect(this.title).not.toBeVisible();
}

/**
* Assertions
*/
// Handle assertions here
}
5 changes: 5 additions & 0 deletions playwright/pages/components/CreateSliceDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Dialog } from "./Dialog";
export class CreateSliceDialog extends Dialog {
readonly createdMessage: Locator;
readonly nameInput: Locator;
readonly sliceAlreadyExistMessage: Locator;

constructor(page: Page) {
super(page, {
Expand All @@ -24,6 +25,10 @@ export class CreateSliceDialog extends Dialog {
exact: false,
});
this.nameInput = this.dialog.getByTestId("slice-name-input");
this.sliceAlreadyExistMessage = this.dialog.getByText(
"Slice name is already taken.",
{ exact: true },
);
}

/**
Expand Down
49 changes: 49 additions & 0 deletions playwright/pages/components/SelectExistingSlicesDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect, Locator, Page } from "@playwright/test";

import { Dialog } from "./Dialog";

export class SelectExistingSlicesDialog extends Dialog {
readonly sharedSliceCard: Locator;
readonly addedMessage: Locator;

constructor(page: Page) {
super(page, {
title: `Select existing slices`,
submitName: "Add",
});

/**
* Static locators
*/
this.sharedSliceCard = this.dialog.getByTestId("shared-slice-card");
this.addedMessage = page.getByText("Slice(s) added to slice zone", {
exact: true,
});
}

/**
* Dynamic locators
*/
// Handle dynamic locators here

/**
* Actions
*/
async selectExistingSlices(names: string[]) {
await expect(this.title).toBeVisible();
for (const name of names) {
await this.sharedSliceCard.getByText(name, { exact: true }).click();
}
await this.submitButton.click();
await this.checkCreatedMessage();
await expect(this.title).not.toBeVisible();
}

/**
* Assertions
*/
async checkCreatedMessage() {
await expect(this.addedMessage).toBeVisible();
await expect(this.addedMessage).not.toBeVisible();
}
}
Loading

0 comments on commit 5d03e45

Please sign in to comment.