|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | + |
| 3 | +test.describe("Group Selection", () => { |
| 4 | + test.beforeEach(async ({ page }) => { |
| 5 | + await page.goto("/"); |
| 6 | + await page.waitForSelector("canvas", { timeout: 15_000 }); |
| 7 | + }); |
| 8 | + |
| 9 | + test("legend shows Groups section with group names", async ({ page }) => { |
| 10 | + await expect(page.getByText("Groups", { exact: false })).toBeVisible(); |
| 11 | + |
| 12 | + // Fixture has 5 groups: services, models, utils, src, types |
| 13 | + const groupButtons = page.locator("button[data-group]"); |
| 14 | + await expect(groupButtons).toHaveCount(5); |
| 15 | + |
| 16 | + const names = await groupButtons.locator("span.truncate").allTextContents(); |
| 17 | + expect(names).toContain("services"); |
| 18 | + expect(names).toContain("models"); |
| 19 | + expect(names).toContain("utils"); |
| 20 | + }); |
| 21 | + |
| 22 | + test("clicking a group selects it and shows selection count", async ({ page }) => { |
| 23 | + const servicesBtn = page.locator("button[data-group='services']"); |
| 24 | + await expect(servicesBtn).toBeVisible(); |
| 25 | + |
| 26 | + await servicesBtn.click(); |
| 27 | + |
| 28 | + // Header should show "(1 selected)" |
| 29 | + await expect(page.getByText("1 selected")).toBeVisible(); |
| 30 | + |
| 31 | + // The clicked button should have highlighted background |
| 32 | + await expect(servicesBtn).not.toHaveClass(/opacity-40/); |
| 33 | + |
| 34 | + // Other groups should be dimmed |
| 35 | + const modelsBtn = page.locator("button[data-group='models']"); |
| 36 | + await expect(modelsBtn).toHaveClass(/opacity-40/); |
| 37 | + }); |
| 38 | + |
| 39 | + test("clicking a selected group deselects it", async ({ page }) => { |
| 40 | + const servicesBtn = page.locator("button[data-group='services']"); |
| 41 | + |
| 42 | + // Select |
| 43 | + await servicesBtn.click(); |
| 44 | + await expect(page.getByText("1 selected")).toBeVisible(); |
| 45 | + |
| 46 | + // Deselect |
| 47 | + await servicesBtn.click(); |
| 48 | + |
| 49 | + // "selected" text should be gone |
| 50 | + await expect(page.getByText("selected")).not.toBeVisible(); |
| 51 | + |
| 52 | + // No group should be dimmed |
| 53 | + const allButtons = page.locator("button[data-group]"); |
| 54 | + const count = await allButtons.count(); |
| 55 | + for (let i = 0; i < count; i++) { |
| 56 | + await expect(allButtons.nth(i)).not.toHaveClass(/opacity-40/); |
| 57 | + } |
| 58 | + }); |
| 59 | + |
| 60 | + test("multi-select: clicking two groups selects both", async ({ page }) => { |
| 61 | + const servicesBtn = page.locator("button[data-group='services']"); |
| 62 | + const modelsBtn = page.locator("button[data-group='models']"); |
| 63 | + |
| 64 | + await servicesBtn.click(); |
| 65 | + await modelsBtn.click(); |
| 66 | + |
| 67 | + await expect(page.getByText("2 selected")).toBeVisible(); |
| 68 | + |
| 69 | + // Both should not be dimmed |
| 70 | + await expect(servicesBtn).not.toHaveClass(/opacity-40/); |
| 71 | + await expect(modelsBtn).not.toHaveClass(/opacity-40/); |
| 72 | + |
| 73 | + // Others should be dimmed |
| 74 | + const utilsBtn = page.locator("button[data-group='utils']"); |
| 75 | + await expect(utilsBtn).toHaveClass(/opacity-40/); |
| 76 | + }); |
| 77 | + |
| 78 | + test("deselecting one of two selected groups keeps the other", async ({ page }) => { |
| 79 | + const servicesBtn = page.locator("button[data-group='services']"); |
| 80 | + const modelsBtn = page.locator("button[data-group='models']"); |
| 81 | + |
| 82 | + await servicesBtn.click(); |
| 83 | + await modelsBtn.click(); |
| 84 | + await expect(page.getByText("2 selected")).toBeVisible(); |
| 85 | + |
| 86 | + // Deselect services |
| 87 | + await servicesBtn.click(); |
| 88 | + await expect(page.getByText("1 selected")).toBeVisible(); |
| 89 | + |
| 90 | + // Services should now be dimmed, models still selected |
| 91 | + await expect(servicesBtn).toHaveClass(/opacity-40/); |
| 92 | + await expect(modelsBtn).not.toHaveClass(/opacity-40/); |
| 93 | + }); |
| 94 | + |
| 95 | + test("group buttons have correct data-group attributes", async ({ page }) => { |
| 96 | + const groupButtons = page.locator("button[data-group]"); |
| 97 | + const attrs = await groupButtons.evaluateAll( |
| 98 | + (els) => els.map((el) => el.getAttribute("data-group")), |
| 99 | + ); |
| 100 | + expect(attrs.length).toBe(5); |
| 101 | + expect(attrs).toEqual(expect.arrayContaining(["services", "models", "utils", "src", "types"])); |
| 102 | + }); |
| 103 | + |
| 104 | + test("groups only visible when Module Clouds checkbox is checked", async ({ page }) => { |
| 105 | + // Groups should be visible initially (checkbox is checked by default) |
| 106 | + await expect(page.getByText("Groups", { exact: false })).toBeVisible(); |
| 107 | + |
| 108 | + // Uncheck Module Clouds |
| 109 | + const checkbox = page.locator("input[type='checkbox']"); |
| 110 | + await checkbox.uncheck(); |
| 111 | + |
| 112 | + // Groups section should disappear |
| 113 | + await expect(page.locator("button[data-group]").first()).not.toBeVisible(); |
| 114 | + }); |
| 115 | +}); |
0 commit comments