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 26, 2023
1 parent 94e6306 commit ca8a52d
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 151 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.

2 changes: 1 addition & 1 deletion packages/slice-machine/src/components/Window/Window.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const WindowTabsList: FC<WindowTabsListProps> = ({
<Tabs.List {...otherProps} className={styles.tabsList}>
{children}
<div className={styles.newTabButton}>
<IconButton icon="add" onClick={onAddNewTab} />
<IconButton icon="add" onClick={onAddNewTab} data-cy="add-tab-button" />
</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 ca8a52d

Please sign in to comment.