Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions src/view/e2e/undo-redo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { expect, test } from "@playwright/test";

import { clearAllCommands, createTestCommands } from "./helpers/test-helpers";

const TOAST_TIMEOUT = 5000;

const TEST_COMMAND = {
command: "npm test",
name: "Test",
};

test.describe("Undo/Redo Keyboard Shortcuts", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/");
await clearAllCommands(page);
});

test("should undo with Ctrl+Z keyboard shortcut", async ({ page }) => {
// Given: Add a command
const commandCards = page.locator('[data-testid="command-card"]');
await createTestCommands(page, [TEST_COMMAND]);
expect(await commandCards.count()).toBe(1);

// When: Press Ctrl+Z
await page.keyboard.press("Control+z");

// Then: Command should be removed
expect(await commandCards.count()).toBe(0);
});

test("should redo with Ctrl+Shift+Z keyboard shortcut", async ({ page }) => {
// Given: Add and undo a command
const commandCards = page.locator('[data-testid="command-card"]');
await createTestCommands(page, [TEST_COMMAND]);
await page.keyboard.press("Control+z");
expect(await commandCards.count()).toBe(0);

// When: Press Ctrl+Shift+Z
await page.keyboard.press("Control+Shift+z");

// Then: Command should be restored
expect(await commandCards.count()).toBe(1);
});

test("should redo with Ctrl+Y keyboard shortcut", async ({ page }) => {
// Given: Add and undo a command
const commandCards = page.locator('[data-testid="command-card"]');
await createTestCommands(page, [TEST_COMMAND]);
await page.keyboard.press("Control+z");
expect(await commandCards.count()).toBe(0);

// When: Press Ctrl+Y
await page.keyboard.press("Control+y");

// Then: Command should be restored
expect(await commandCards.count()).toBe(1);
});

test("should undo command deletion", async ({ page }) => {
// Given: Add a command
const commandCards = page.locator('[data-testid="command-card"]');
await createTestCommands(page, [TEST_COMMAND]);
expect(await commandCards.count()).toBe(1);

// When: Delete the command
const deleteButton = commandCards.first().getByRole("button", { name: /delete/i });
await deleteButton.click();
await page.getByRole("button", { name: /delete/i }).click();

// Wait for deletion to complete
const toast = page.locator("[data-sonner-toast]");
await toast.waitFor({ state: "hidden", timeout: TOAST_TIMEOUT });
expect(await commandCards.count()).toBe(0);

// And: Undo with keyboard shortcut
await page.keyboard.press("Control+z");

// Then: Command should be restored
expect(await commandCards.count()).toBe(1);
});

test("should undo command modification", async ({ page }) => {
// Given: Add a command
const commandCards = page.locator('[data-testid="command-card"]');
await createTestCommands(page, [TEST_COMMAND]);

// When: Edit the command
const editButton = commandCards.first().getByRole("button", { name: /edit/i });
await editButton.click();

const newName = "Modified Test";
await page.getByLabel(/command name/i).fill(newName);
await page.getByRole("button", { name: /save/i }).click();

// Verify modification
await expect(commandCards.first().getByText(newName)).toBeVisible();

// And: Undo with keyboard shortcut
await page.keyboard.press("Control+z");

// Then: Original name should be restored
await expect(commandCards.first().getByText(TEST_COMMAND.name)).toBeVisible();
});
});
4 changes: 3 additions & 1 deletion src/view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"react-hook-form": "7.66.1",
"react-i18next": "15.4.1",
"sonner": "2.0.7",
"zod": "4.1.12"
"zod": "4.1.12",
"zundo": "2.3.0",
"zustand": "5.0.8"
}
}
Loading
Loading