Skip to content

Commit

Permalink
fix: undo/redo tests should hopefully be less flakey (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajotg authored Jun 19, 2024
1 parent 2efab48 commit 96db9fd
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions tests/undo_redo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { expect, test } from "@playwright/test";
import { type Page, expect, test } from "@playwright/test";
import { goToHomePage, openExample } from "./utils";

test.beforeEach(goToHomePage);

async function undo(page: Page) {
await page.locator("div:nth-child(2) > button").first().click(); // Click undo button
}
async function redo(page: Page) {
await page.locator("div:nth-child(2) > button:nth-child(2)").click(); // Click redo button
}

test("Undo redo - Deletion", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();
Expand All @@ -14,14 +21,15 @@ test("Undo redo - Deletion", async ({ page }) => {
await page.locator("svg").filter({ hasText: "Leaphy" }).press("Delete");
await expect(page.getByText("repeat forever")).toBeHidden();

await page.locator("div:nth-child(2) > button").first().click(); // Click undo button
await expect(page.getByText("repeat forever")).toBeVisible();
await page.locator("div:nth-child(2) > button:nth-child(2)").click(); // Click redo button
await expect(page.getByText("repeat forever")).toBeHidden();
// Test shortcuts once, but the rest of the time use undo/redo buttons to hopefully be less flakey
await page.keyboard.press("Control+z");
await expect(page.getByText("repeat forever")).toBeVisible();
await page.keyboard.press("Control+y");
await expect(page.getByText("repeat forever")).toBeHidden();
await undo(page);
await expect(page.getByText("repeat forever")).toBeVisible();
await redo(page);
await expect(page.getByText("repeat forever")).toBeHidden();
});

test("Undo redo - Variable change", async ({ page }) => {
Expand All @@ -34,9 +42,9 @@ test("Undo redo - Variable change", async ({ page }) => {
await page.getByText("true").click();
await page.locator("#blockly-1").getByText("false").click();
await expect(page.getByText("false")).toHaveCount(2);
await page.keyboard.press("Control+z");
await undo(page);
await expect(page.getByText("false")).toHaveCount(1);
await page.keyboard.press("Control+y");
await redo(page);
await expect(page.getByText("false")).toHaveCount(2);

// Change one of the delays
Expand All @@ -47,12 +55,12 @@ test("Undo redo - Variable change", async ({ page }) => {
await expect(page.getByText("123", { exact: true })).toBeHidden();
await page.keyboard.press("Control+y");
await expect(page.getByText("123", { exact: true })).toBeVisible();

await page.getByRole("textbox").press("Enter");

await expect(page.getByText("123", { exact: true })).toBeVisible();
await page.keyboard.press("Control+z");
await undo(page);
await expect(page.getByText("123", { exact: true })).toBeHidden();
await page.keyboard.press("Control+y");
await redo(page);
await expect(page.getByText("123", { exact: true })).toBeVisible();
});

Expand All @@ -77,9 +85,9 @@ test("Undo redo - Dragging", async ({ page }) => {

await expect(page.locator(".view-lines")).not.toContainText("delay");

await page.keyboard.press("Control+z");
await undo(page);
await expect(page.locator(".view-lines")).toContainText("delay");
await page.keyboard.press("Control+y");
await redo(page);
await expect(page.locator(".view-lines")).not.toContainText("delay");

// Move it back to its original location, connecting it again
Expand All @@ -94,12 +102,12 @@ test("Undo redo - Dragging", async ({ page }) => {
});

await expect(page.locator(".view-lines")).toContainText("delay");
await page.keyboard.press("Control+z");
await undo(page);
await expect(page.locator(".view-lines")).not.toContainText("delay");
await page.keyboard.press("Control+y");
await redo(page);
await expect(page.locator(".view-lines")).toContainText("delay");
await page.keyboard.press("Control+z");
await undo(page);
await expect(page.locator(".view-lines")).not.toContainText("delay");
await page.keyboard.press("Control+z");
await undo(page);
await expect(page.locator(".view-lines")).toContainText("delay");
});

0 comments on commit 96db9fd

Please sign in to comment.