|
6 | 6 | fireEvent, |
7 | 7 | render, |
8 | 8 | screen, |
| 9 | + waitFor, |
9 | 10 | } from "@testing-library/react"; |
10 | 11 | import { afterEach, expect, it, vi } from "vitest"; |
11 | 12 | import type { Contribution } from "../plugins/contributions"; |
@@ -105,36 +106,50 @@ it("keeps grouped cards available without a selected community", () => { |
105 | 106 | expect(screen.queryByRole("button", { name: "Personal groups" })).toBeNull(); |
106 | 107 | }); |
107 | 108 |
|
108 | | -it("gives contributed cards their own community sections and retires removed cards", () => { |
| 109 | +it("gives contributed cards their own community sections and retires removed cards", async () => { |
109 | 110 | const { cards, set } = registry([ |
110 | 111 | card("hosted", "Hosted communities", "Communities"), |
111 | 112 | card("groups", "Personal groups"), |
112 | 113 | ]); |
113 | | - render(<Settings {...host} cards={cards} />); |
| 114 | + const complete = vi.fn(() => true); |
| 115 | + const onSection = vi.fn(); |
| 116 | + render( |
| 117 | + <Settings |
| 118 | + {...host} |
| 119 | + cards={cards} |
| 120 | + navigation={ |
| 121 | + { |
| 122 | + target: { |
| 123 | + version: 1, |
| 124 | + kind: "settings", |
| 125 | + section: "example/hosted", |
| 126 | + }, |
| 127 | + complete, |
| 128 | + } as never |
| 129 | + } |
| 130 | + onSection={onSection} |
| 131 | + />, |
| 132 | + ); |
114 | 133 | const nav = screen.getByRole("navigation", { name: "Settings sections" }); |
115 | 134 | expect(nav).toHaveTextContent("Primary"); |
116 | 135 | expect(nav).toHaveTextContent("Communities"); |
117 | | - expect(screen.queryByText("Hosted communities body")).toBeNull(); |
118 | | - |
119 | | - fireEvent.click(screen.getByRole("button", { name: "Hosted communities" })); |
120 | | - expect(screen.getByText("Hosted communities body")).toBeVisible(); |
| 136 | + expect(await screen.findByText("Hosted communities body")).toBeVisible(); |
121 | 137 | expect( |
122 | 138 | screen.getByRole("button", { name: "Hosted communities" }), |
123 | 139 | ).toHaveAttribute("aria-current", "page"); |
124 | 140 | expect(screen.queryByText("Personal groups body")).toBeNull(); |
| 141 | + expect(complete).toHaveBeenLastCalledWith({ status: "opened" }); |
125 | 142 |
|
126 | | - fireEvent.click(screen.getByRole("button", { name: "Personal groups" })); |
127 | | - expect(screen.getByText("Personal groups body")).toBeVisible(); |
128 | | - expect(screen.queryByText("Hosted communities body")).toBeNull(); |
129 | | - |
130 | | - fireEvent.click(screen.getByRole("button", { name: "Hosted communities" })); |
131 | 143 | act(() => set([card("groups", "Personal groups")])); |
| 144 | + await waitFor(() => expect(onSection).toHaveBeenLastCalledWith("profile")); |
132 | 145 | expect(screen.queryByText("Hosted communities body")).toBeNull(); |
| 146 | + expect(screen.queryByRole("alert")).toBeNull(); |
133 | 147 | expect(nav).not.toHaveTextContent("Hosted communities"); |
134 | 148 | expect(screen.getByRole("button", { name: "Profile" })).toHaveAttribute( |
135 | 149 | "aria-current", |
136 | 150 | "page", |
137 | 151 | ); |
| 152 | + expect(nav.querySelectorAll('[aria-current="page"]')).toHaveLength(1); |
138 | 153 | }); |
139 | 154 |
|
140 | 155 | it("keeps same-id community cards from different plugins distinct", () => { |
|
0 commit comments