|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +import { openAddCommandDialog, saveCommandDialog } from "./helpers/test-helpers"; |
| 4 | + |
| 5 | +const SELECTORS = { |
| 6 | + ADD_COMMAND_BUTTON: "Add new command", |
| 7 | + ADD_GROUP_BUTTON: "Add new group", |
| 8 | + COMMAND_NAME_INPUT: "Command Name", |
| 9 | + COMMAND_NAME_PLACEHOLDER: "Command name", |
| 10 | + COMMAND_PLACEHOLDER: "Command (e.g., npm start)", |
| 11 | + GROUP_COMMAND_ITEM: '[data-testid="group-command-item"]', |
| 12 | + GROUP_COMMANDS_RADIO: "Group Commands", |
| 13 | + GROUP_NAME_PLACEHOLDER: "Group name", |
| 14 | + SAVE_BUTTON: "Save", |
| 15 | +} as const; |
| 16 | + |
| 17 | +test.describe("Deep Nested Group Creation (3+ levels)", () => { |
| 18 | + test.beforeEach(async ({ page }) => { |
| 19 | + await page.goto("/"); |
| 20 | + }); |
| 21 | + |
| 22 | + test("should create and manage 3-level nested groups", async ({ page }) => { |
| 23 | + // Step 1: Create a root group command |
| 24 | + await openAddCommandDialog(page); |
| 25 | + |
| 26 | + // Fill group name and switch to Group Commands type |
| 27 | + await page.getByRole("textbox", { name: SELECTORS.COMMAND_NAME_INPUT }).fill("Level 1 Group"); |
| 28 | + await page.getByRole("radio", { name: SELECTORS.GROUP_COMMANDS_RADIO }).click(); |
| 29 | + |
| 30 | + // Get the main dialog |
| 31 | + const mainDialog = page.getByRole("dialog", { name: /Add New Command/i }); |
| 32 | + |
| 33 | + // Add a nested group at level 2 |
| 34 | + await mainDialog.getByRole("button", { name: SELECTORS.ADD_GROUP_BUTTON }).click(); |
| 35 | + |
| 36 | + // Find the newly added group item and fill its name |
| 37 | + const level2GroupItem = mainDialog.locator(SELECTORS.GROUP_COMMAND_ITEM).last(); |
| 38 | + await level2GroupItem.getByPlaceholder(SELECTORS.GROUP_NAME_PLACEHOLDER).fill("Level 2 Group"); |
| 39 | + |
| 40 | + // Click edit button to open Level 2 Group dialog |
| 41 | + const editLevel2Button = level2GroupItem.getByRole("button", { name: /edit/i }); |
| 42 | + await editLevel2Button.click(); |
| 43 | + |
| 44 | + // Get Level 2 dialog |
| 45 | + const level2Dialog = page.getByRole("dialog", { name: /Edit Group: Level 2 Group/i }); |
| 46 | + await expect(level2Dialog).toBeVisible(); |
| 47 | + |
| 48 | + // Add a nested group at level 3 |
| 49 | + await level2Dialog.getByRole("button", { name: SELECTORS.ADD_GROUP_BUTTON }).click(); |
| 50 | + |
| 51 | + // Find the newly added group item and fill its name |
| 52 | + const level3GroupItem = level2Dialog.locator(SELECTORS.GROUP_COMMAND_ITEM).last(); |
| 53 | + await level3GroupItem.getByPlaceholder(SELECTORS.GROUP_NAME_PLACEHOLDER).fill("Level 3 Group"); |
| 54 | + |
| 55 | + // Click edit button to open Level 3 Group dialog |
| 56 | + const editLevel3Button = level3GroupItem.getByRole("button", { name: /edit/i }); |
| 57 | + await editLevel3Button.click(); |
| 58 | + |
| 59 | + // Get Level 3 dialog |
| 60 | + const level3Dialog = page.getByRole("dialog", { name: /Edit Group: Level 3 Group/i }); |
| 61 | + await expect(level3Dialog).toBeVisible(); |
| 62 | + |
| 63 | + // Add a command at level 3 |
| 64 | + await level3Dialog.getByRole("button", { name: SELECTORS.ADD_COMMAND_BUTTON }).click(); |
| 65 | + |
| 66 | + // Fill the command in level 3 |
| 67 | + const level3CommandItem = level3Dialog.locator(SELECTORS.GROUP_COMMAND_ITEM).last(); |
| 68 | + await level3CommandItem.getByPlaceholder(SELECTORS.COMMAND_NAME_PLACEHOLDER).fill("Deep Command"); |
| 69 | + await level3CommandItem |
| 70 | + .getByPlaceholder(SELECTORS.COMMAND_PLACEHOLDER) |
| 71 | + .fill("echo deep nested"); |
| 72 | + |
| 73 | + // Save Level 3 dialog |
| 74 | + await level3Dialog.getByRole("button", { name: SELECTORS.SAVE_BUTTON }).click(); |
| 75 | + await expect(level3Dialog).not.toBeVisible(); |
| 76 | + |
| 77 | + // Save Level 2 dialog |
| 78 | + await level2Dialog.getByRole("button", { name: SELECTORS.SAVE_BUTTON }).click(); |
| 79 | + await expect(level2Dialog).not.toBeVisible(); |
| 80 | + |
| 81 | + // Save main dialog |
| 82 | + await saveCommandDialog(page); |
| 83 | + |
| 84 | + // Verify Level 1 Group was created with proper nested structure |
| 85 | + const level1Card = page.locator('[data-testid="command-card"]', { hasText: "Level 1 Group" }); |
| 86 | + await expect(level1Card).toBeVisible(); |
| 87 | + |
| 88 | + // The card should show it has nested commands (displayed as "X commands") |
| 89 | + await expect(level1Card.getByText(/command/i)).toBeVisible(); |
| 90 | + }); |
| 91 | + |
| 92 | + test("dialog layers correctly stack at 3 levels", async ({ page }) => { |
| 93 | + // Create a root group command |
| 94 | + await openAddCommandDialog(page); |
| 95 | + |
| 96 | + // Fill group name and switch to Group Commands type |
| 97 | + await page.getByRole("textbox", { name: SELECTORS.COMMAND_NAME_INPUT }).fill("Stack Test"); |
| 98 | + await page.getByRole("radio", { name: SELECTORS.GROUP_COMMANDS_RADIO }).click(); |
| 99 | + |
| 100 | + const mainDialog = page.getByRole("dialog", { name: /Add New Command/i }); |
| 101 | + |
| 102 | + // Add level 2 group |
| 103 | + await mainDialog.getByRole("button", { name: SELECTORS.ADD_GROUP_BUTTON }).click(); |
| 104 | + const level2GroupItem = mainDialog.locator(SELECTORS.GROUP_COMMAND_ITEM).last(); |
| 105 | + await level2GroupItem.getByPlaceholder(SELECTORS.GROUP_NAME_PLACEHOLDER).fill("L2"); |
| 106 | + await level2GroupItem.getByRole("button", { name: /edit/i }).click(); |
| 107 | + |
| 108 | + const level2Dialog = page.getByRole("dialog", { name: /Edit Group: L2/i }); |
| 109 | + await expect(level2Dialog).toBeVisible(); |
| 110 | + |
| 111 | + // Add level 3 group |
| 112 | + await level2Dialog.getByRole("button", { name: SELECTORS.ADD_GROUP_BUTTON }).click(); |
| 113 | + const level3GroupItem = level2Dialog.locator(SELECTORS.GROUP_COMMAND_ITEM).last(); |
| 114 | + await level3GroupItem.getByPlaceholder(SELECTORS.GROUP_NAME_PLACEHOLDER).fill("L3"); |
| 115 | + await level3GroupItem.getByRole("button", { name: /edit/i }).click(); |
| 116 | + |
| 117 | + const level3Dialog = page.getByRole("dialog", { name: /Edit Group: L3/i }); |
| 118 | + await expect(level3Dialog).toBeVisible(); |
| 119 | + |
| 120 | + // At this point we have 3 dialogs open |
| 121 | + // Verify all three dialogs exist (some may be overlapped but should be in DOM) |
| 122 | + await expect(mainDialog).toBeAttached(); |
| 123 | + await expect(level2Dialog).toBeAttached(); |
| 124 | + await expect(level3Dialog).toBeVisible(); // Top-most should be visible |
| 125 | + |
| 126 | + // Close level 3 |
| 127 | + await level3Dialog.getByRole("button", { name: /cancel/i }).click(); |
| 128 | + await expect(level3Dialog).not.toBeVisible(); |
| 129 | + |
| 130 | + // Level 2 should now be visible/interactive |
| 131 | + await expect(level2Dialog).toBeVisible(); |
| 132 | + |
| 133 | + // Close level 2 |
| 134 | + await level2Dialog.getByRole("button", { name: /cancel/i }).click(); |
| 135 | + await expect(level2Dialog).not.toBeVisible(); |
| 136 | + |
| 137 | + // Main dialog should now be visible/interactive |
| 138 | + await expect(mainDialog).toBeVisible(); |
| 139 | + |
| 140 | + // Close main dialog |
| 141 | + await page.getByRole("button", { name: /cancel/i }).click(); |
| 142 | + await expect(mainDialog).not.toBeVisible(); |
| 143 | + }); |
| 144 | +}); |
0 commit comments