|
2 | 2 | EnvironmentId, |
3 | 3 | ProviderDriverKind, |
4 | 4 | ProviderInstanceId, |
| 5 | + UsageLimitSourceId, |
5 | 6 | type ServerProvider, |
6 | 7 | } from "@t3tools/contracts"; |
7 | 8 | import type { LimitPresentations } from "@t3tools/shared/usageLimits"; |
@@ -164,3 +165,122 @@ it("omits an empty reset plate but keeps countdowns and banked credits visible", |
164 | 165 | await expect.element(plate()).toBeVisible(); |
165 | 166 | expect(plate()?.textContent).toBe("1"); |
166 | 167 | }); |
| 168 | + |
| 169 | +it("moves the one limit popover between windows on hover", async () => { |
| 170 | + const [environmentId, presentation] = [...presentations("2026-09-03T14:00:00Z", 1)][0]!; |
| 171 | + const serverConfig = presentation.serverConfig!; |
| 172 | + const provider = serverConfig.providers[0]!; |
| 173 | + const twoWindows: LimitPresentations = new Map([ |
| 174 | + [ |
| 175 | + environmentId, |
| 176 | + { |
| 177 | + ...presentation, |
| 178 | + serverConfig: { |
| 179 | + ...serverConfig, |
| 180 | + providers: [ |
| 181 | + { |
| 182 | + ...provider, |
| 183 | + usageLimits: { |
| 184 | + ...provider.usageLimits!, |
| 185 | + windows: [ |
| 186 | + ...provider.usageLimits!.windows, |
| 187 | + { id: "weekly", kind: "weekly", label: "Weekly", usedPercent: 32 }, |
| 188 | + ], |
| 189 | + }, |
| 190 | + }, |
| 191 | + ], |
| 192 | + }, |
| 193 | + }, |
| 194 | + ], |
| 195 | + ]); |
| 196 | + // Room above the bars so the popover opens there instead of flipping over the next card. |
| 197 | + container.style.paddingTop = "20rem"; |
| 198 | + await act(() => root.render(<UsageLimitsPooled presentations={twoWindows} now={0} />)); |
| 199 | + const segment = (label: string) => |
| 200 | + Array.from(document.querySelectorAll("button")).find((node) => |
| 201 | + node.getAttribute("aria-label")?.startsWith(label), |
| 202 | + )!; |
| 203 | + // Popup contents, once the previous segment's details have animated away. |
| 204 | + const popups = () => |
| 205 | + document.querySelector("[data-previous]") |
| 206 | + ? null |
| 207 | + : Array.from( |
| 208 | + document.querySelectorAll('[data-slot="popover-popup"]'), |
| 209 | + (node) => node.textContent, |
| 210 | + ); |
| 211 | + const session = segment("Alpha: 60%"); |
| 212 | + const weekly = segment("Alpha: 68%"); |
| 213 | + |
| 214 | + await act(() => userEvent.click(session)); |
| 215 | + await expect.poll(popups).toEqual([expect.stringContaining("Left60%")]); |
| 216 | + |
| 217 | + await act(() => userEvent.hover(weekly)); |
| 218 | + await expect.poll(popups).toEqual([expect.stringContaining("Left68%")]); |
| 219 | + |
| 220 | + // Weekly's popover now sits over the middle of the Session bar; come back in at its edge. |
| 221 | + await act(() => userEvent.hover(session, { position: { x: 4, y: 4 } })); |
| 222 | + await expect.poll(popups).toEqual([expect.stringContaining("Left60%")]); |
| 223 | + |
| 224 | + await act(() => root.render(<UsageLimitsPooled presentations={new Map()} now={0} />)); |
| 225 | + await expect.poll(popups).toEqual([]); |
| 226 | + await act(() => userEvent.hover(container, { position: { x: 4, y: 4 } })); |
| 227 | + |
| 228 | + await act(() => root.render(<UsageLimitsPooled presentations={twoWindows} now={0} />)); |
| 229 | + await expect.poll(popups).toEqual([]); |
| 230 | + await act(() => userEvent.click(segment("Alpha: 60%"))); |
| 231 | + await expect.poll(popups).toEqual([expect.stringContaining("Left60%")]); |
| 232 | +}); |
| 233 | + |
| 234 | +it("closes an open source-account popover when reset availability replaces its trigger", async () => { |
| 235 | + const [environmentId, presentation] = [...presentations("2026-09-03T14:00:00Z", 1)][0]!; |
| 236 | + const provider = presentation.serverConfig!.providers[0]!; |
| 237 | + const source = (nextCreditId?: string): LimitPresentations => |
| 238 | + new Map([ |
| 239 | + [ |
| 240 | + environmentId, |
| 241 | + { |
| 242 | + ...presentation, |
| 243 | + serverConfig: { |
| 244 | + providers: [], |
| 245 | + usageLimitSources: [ |
| 246 | + { |
| 247 | + id: UsageLimitSourceId.make("hub"), |
| 248 | + kind: "cliproxy", |
| 249 | + label: "Hub", |
| 250 | + checkedAt: "2026-09-03T11:00:00Z", |
| 251 | + accounts: [ |
| 252 | + { |
| 253 | + id: "Alpha", |
| 254 | + driver: provider.driver, |
| 255 | + usageLimits: { |
| 256 | + ...provider.usageLimits!, |
| 257 | + resetCredits: { |
| 258 | + availableCount: 1, |
| 259 | + ...(nextCreditId ? { nextCreditId } : {}), |
| 260 | + }, |
| 261 | + }, |
| 262 | + }, |
| 263 | + ], |
| 264 | + }, |
| 265 | + ], |
| 266 | + }, |
| 267 | + }, |
| 268 | + ], |
| 269 | + ]); |
| 270 | + const popup = () => document.querySelector('[data-slot="popover-popup"]'); |
| 271 | + await act(() => root.render(<UsageLimitsPooled presentations={source("credit-1")} now={0} />)); |
| 272 | + await click("Alpha: 60%"); |
| 273 | + await expect.poll(() => popup()?.textContent).toContain("Use reset"); |
| 274 | + |
| 275 | + await act(() => root.render(<UsageLimitsPooled presentations={source()} now={0} />)); |
| 276 | + await expect.poll(popup).toBeNull(); |
| 277 | + await click("Alpha: 60%"); |
| 278 | + await expect.poll(() => popup()?.textContent).toContain("Left60%"); |
| 279 | + |
| 280 | + await act(() => root.render(<UsageLimitsPooled presentations={source("credit-2")} now={0} />)); |
| 281 | + await expect.poll(popup).toBeNull(); |
| 282 | + await click("Alpha: 60%"); |
| 283 | + await expect.poll(() => popup()?.textContent).toContain("Use reset"); |
| 284 | + await click("Use reset"); |
| 285 | + await expect.poll(() => document.querySelector('[role="alertdialog"]')).not.toBeNull(); |
| 286 | +}); |
0 commit comments