diff --git a/tests/storybook-visual/dashboard-proposals.spec.ts b/tests/storybook-visual/dashboard-proposals.spec.ts new file mode 100644 index 00000000000..2c80b0863cb --- /dev/null +++ b/tests/storybook-visual/dashboard-proposals.spec.ts @@ -0,0 +1,59 @@ +import { expect, test } from "@playwright/test"; + +for (const theme of ["light", "dark"]) { + for (const width of [390, 960]) { + for (const story of ["proposal-hierarchy", "proposal-hierarchy-mobile", "proposal-create", "proposal-new-and-existing-areas", "proposal-edit", "proposal-in-conversation"]) { + test(`${story} ${theme} ${width}`, async ({ page }, testInfo) => { + await page.setViewportSize({ width, height: 1100 }); + const errors: string[] = []; + page.on("pageerror", (error) => errors.push(error.message)); + await page.goto(`/iframe.html?id=feature-responsibility-dashboard--${story}&viewMode=story&globals=theme:${theme}`); + const finished = () => page.evaluate(() => (window as unknown as { + __STORYBOOK_ADDONS_CHANNEL__?: { data: Record> }; + }).__STORYBOOK_ADDONS_CHANNEL__?.data.storyFinished?.[0]?.status); + await expect.poll(finished, { timeout: 30_000 }).not.toBeUndefined(); + expect(await finished()).toBe("success"); + expect(errors).toEqual([]); + expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true); + + if (story === "proposal-hierarchy") { + const area = page.getByRole("region", { name: "Fundraising" }); + const heading = area.getByRole("heading", { name: "Fundraising" }); + const responsibilities = area.getByRole("list", { name: "Responsibilities in Fundraising" }); + await expect(responsibilities.getByText("New responsibility", { exact: true })).toHaveCount(2); + expect((await responsibilities.getByRole("listitem").first().boundingBox())!.x).toBeGreaterThan((await heading.boundingBox())!.x); + await expect(responsibilities.getByRole("button", { name: "Drop this change" })).toHaveCount(2); + await area.getByRole("button", { name: "Drop this change" }).first().click(); + await expect(area.locator("[data-dropped]")).toHaveCount(3); + await expect(area.getByText("Goes with Fundraising")).toHaveCount(2); + expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true); + await responsibilities.getByRole("button", { name: "Keep", exact: true }).last().click(); + await expect(area.locator("[data-dropped]")).toHaveCount(1); + await area.getByRole("button", { name: "Keep", exact: true }).click(); + } + await page.evaluate(() => document.fonts.ready); + await page.getByTestId("dashboard-changes").screenshot({ path: testInfo.outputPath(`${story}-${theme}-${width}.png`) }); + }); + } + } +} + +test("nested selections retain the existing apply payload", async ({ page }) => { + await page.goto("/iframe.html?id=feature-responsibility-dashboard--proposal-hierarchy&viewMode=story"); + const area = page.getByRole("region", { name: "Portfolio", exact: true }); + await area.getByRole("button", { name: "Drop this change" }).first().click(); + await area.getByRole("button", { name: "Keep", exact: true }).last().click(); + await page.evaluate(() => { + const original = window.fetch; + (window as unknown as { appliedBody: unknown }).appliedBody = undefined; + window.fetch = (input, init) => { + if (String(input).endsWith("/accept")) { + (window as unknown as { appliedBody: unknown }).appliedBody = JSON.parse(String(init?.body)); + } + return original(input, init); + }; + }); + await page.getByRole("button", { name: "Apply changes" }).click(); + await expect.poll(() => page.evaluate(() => (window as unknown as { appliedBody: unknown }).appliedBody)) + .toEqual({ keep: [0, 1, 2, 3, 5, 6, 7, 8, 9] }); +}); diff --git a/ui/src/components/responsibilities/DashboardChangesCard.test.tsx b/ui/src/components/responsibilities/DashboardChangesCard.test.tsx index cb94f593235..220655118d6 100644 --- a/ui/src/components/responsibilities/DashboardChangesCard.test.tsx +++ b/ui/src/components/responsibilities/DashboardChangesCard.test.tsx @@ -59,14 +59,27 @@ describe("DashboardChangesCard", () => { return match; }; const group = (name: string) => container.querySelector(`section[aria-label="${name}"]`)!; - const rows = (name: string) => [...group(name).querySelectorAll("li")]; + const rows = (name: string) => [...group(name).querySelectorAll("[data-dashboard-change]")]; + + it("identifies new areas in their headings and nests explicitly named new responsibilities", async () => { + await render(); + const fundraising = group("Fundraising"); + const area = fundraising.querySelector('[data-dashboard-change="add_area"]')!; + expect(area.querySelector("h3")?.textContent).toBe("Fundraising"); + expect(area.textContent).toContain("New area"); + const responsibilities = fundraising.querySelector('ul[aria-label="Responsibilities in Fundraising"]')!; + expect(responsibilities).not.toBeNull(); + expect(responsibilities.contains(area)).toBe(false); + expect([...responsibilities.querySelectorAll("li")].map((row) => row.querySelector('[data-change-label]')?.textContent)) + .toEqual(["New responsibility", "New responsibility"]); + }); it("shows a first dashboard grouped by area, in plain words, with the agent's reasons", async () => { await render(); const text = container.textContent ?? ""; expect(text).toContain("Chief proposes"); expect(text).toContain("A first dashboard from your answers and your calendar."); - expect([...container.querySelectorAll("h4")].map((heading) => heading.textContent)).toEqual(["Fundraising", "Portfolio", "Team", "Board"]); + expect([...container.querySelectorAll("h3")].map((heading) => heading.textContent)).toEqual(["Fundraising", "Portfolio", "Team", "Board"]); expect(rows("Fundraising").map((row) => row.getAttribute("data-dashboard-change"))).toEqual(["add_area", "add_responsibility", "add_responsibility"]); expect(rows("Fundraising")[1]!.textContent).toContain("You run the weekly fundraising sync"); expect(text).not.toMatch(/\b(issue|interaction|op|areaRef)\b/i); @@ -83,8 +96,21 @@ describe("DashboardChangesCard", () => { expect(rows("Portfolio")[0]!.textContent).toContain("Moved from Fundraising"); const team = rows("Team"); // Area changes first: the rename, seen by others too, then the responsibility let go with its reason. - expect(team[0]!.textContent).toContain("TeamPeopleAlso renamed for 2 other people"); - expect(team[1]!.textContent).toContain("Hire a second designer.Let goThat is a task that finishes"); + expect(team[0]!.querySelector("h3")?.textContent).toBe("Team People"); + expect(team[0]!.textContent).toContain("Rename areaAlso renamed for 2 other people"); + expect(team[1]!.textContent).toContain("Let go of responsibilityHire a second designer.Let goThat is a task that finishes"); + }); + + it("names the existing parent area when only a responsibility is added, and identifies area removal", async () => { + const interaction = dashboardChangesFixture("create"); + await render(); + expect(group("Fundraising").textContent).toContain("FundraisingExisting areaNew responsibility"); + expect(group("Portfolio").querySelector("h3")?.textContent?.trim()).toBe("Portfolio"); + expect(group("Portfolio").textContent).toContain("Remove area"); + expect(group("Portfolio").querySelector("ul")).toBeNull(); }); it("drops a new area together with what is filed under it, and keeps the area when one of them is kept", async () => { @@ -101,6 +127,16 @@ describe("DashboardChangesCard", () => { expect(acceptMock).toHaveBeenCalledExactlyOnceWith("issue-dashboard-conversation", "dashboard-changes-create", [0, 1, 2, 3, 5, 6, 7, 8, 9]); }); + it("does not label an unfiled responsibility as an existing area", async () => { + const interaction = dashboardChangesFixture("edit"); + await render(); + expect(group("No area").textContent).not.toContain("Existing area"); + expect(group("No area").querySelector("h3")?.textContent).toBe("No area"); + expect(rows("No area")[0]!.textContent).toContain("Every prospective LP hears from us at least every two weeks."); + }); + it("applies everything when nothing is dropped, and cannot apply nothing", async () => { await render(); for (const name of ["Fundraising", "Portfolio", "Team"]) { diff --git a/ui/src/components/responsibilities/DashboardChangesCard.tsx b/ui/src/components/responsibilities/DashboardChangesCard.tsx index dfcc5712c04..5de134172a8 100644 --- a/ui/src/components/responsibilities/DashboardChangesCard.tsx +++ b/ui/src/components/responsibilities/DashboardChangesCard.tsx @@ -12,6 +12,7 @@ import { dashboardChangeGroups, dashboardChangeWords, droppedWithArea, + isDashboardAreaChange, keptDashboardChanges, lettingGoWith, toggleDashboardChange, @@ -58,6 +59,16 @@ export function useDashboardChangesActions(interaction: Pick = { + add_area: "New area", + rename_area: "Rename area", + remove_area: "Remove area", + add_responsibility: "New responsibility", + reword_responsibility: "Reword responsibility", + move_responsibility: "Move responsibility", + remove_responsibility: "Let go of responsibility", +}; + function ChangeRow({ change, changes, @@ -73,25 +84,40 @@ function ChangeRow({ }) { const isDropped = dropped.has(change.index); const words = dashboardChangeWords(change); + const areaChange = isDashboardAreaChange(change); + const Row = areaChange ? "div" : "li"; const withArea = isDropped ? droppedWithArea(changes, dropped, change) : null; const lettingGo = change.op === "remove_area" && !isDropped ? lettingGoWith(changes, dropped, change) : []; return ( -
  • -
    - {words.before ?

    {words.before}

    : null} - {words.after ?

    {words.after}

    : null} +
    + {areaChange ? ( +
    +

    + {words.before ? {words.before}{" "} : null} + {words.after} +

    + {CHANGE_LABELS[change.op]} +
    + ) : ( + <> + {CHANGE_LABELS[change.op]} + {words.before ?

    {words.before}

    : null} + {words.after ?

    {words.after}

    : null} + + )} {words.note ?

    {words.note}

    : null} {lettingGo.length > 0 ? (

    Also lets go of: {lettingGo.join("; ")}

    ) : null} - {change.reason ?

    {change.reason}

    : null} + {change.reason ?

    {change.reason}

    : null}
    {isDropped ? ( -
    +
    {withArea ? Goes with {withArea} : null}
    @@ -110,7 +136,7 @@ function ChangeRow({
  • + ); } @@ -179,24 +205,35 @@ export function DashboardChangesCard({

    {agentName} proposes

    {payload.message ?

    {payload.message}

    : null} -
    - {groups.map((group) => ( -
    -

    {group.name}

    -
      - {group.changes.map((change) => ( - setDropped((current) => toggleDashboardChange(changes, current, change.index))} - /> - ))} -
    -
    - ))} +
    + {groups.map((group) => { + const { areaChanges, responsibilityChanges } = group; + const row = (change: ResponsibilityDashboardChange) => ( + setDropped((current) => toggleDashboardChange(changes, current, change.index))} + /> + ); + return ( +
    + {areaChanges.length > 0 ? areaChanges.map(row) : ( +
    +

    {group.name}

    + {group.hasExistingArea ? Existing area : null} +
    + )} + {responsibilityChanges.length > 0 ? ( +
      + {responsibilityChanges.map(row)} +
    + ) : null} +
    + ); + })}
    {error ?

    {describeError(error).body}

    : null} {notRight ? ( @@ -209,15 +246,17 @@ export function DashboardChangesCard({ placeholder="e.g. Keep Hiring, and fewer responsibilities under Fundraising" /> ) : ( -
    - {showConversationLink ? ( - + ) : null} + - ) : null} - +