|
| 1 | +import { render, waitFor } from "@/utils/test-utils" |
| 2 | +import React from "react" |
| 3 | + |
| 4 | +vi.mock("@src/utils/vscode", () => ({ |
| 5 | + vscode: { |
| 6 | + postMessage: vi.fn(), |
| 7 | + }, |
| 8 | +})) |
| 9 | + |
| 10 | +import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext" |
| 11 | +import { vscode } from "@src/utils/vscode" |
| 12 | + |
| 13 | +describe("ExtensionStateContext Roo auth gate", () => { |
| 14 | + beforeEach(() => { |
| 15 | + vi.clearAllMocks() |
| 16 | + }) |
| 17 | + |
| 18 | + function postStateMessage(state: any) { |
| 19 | + window.dispatchEvent( |
| 20 | + new MessageEvent("message", { |
| 21 | + data: { |
| 22 | + type: "state", |
| 23 | + state, |
| 24 | + }, |
| 25 | + }), |
| 26 | + ) |
| 27 | + } |
| 28 | + |
| 29 | + it("does not post requestRooModels when auth flips and provider !== 'roo'", async () => { |
| 30 | + render( |
| 31 | + <ExtensionStateContextProvider> |
| 32 | + <div /> |
| 33 | + </ExtensionStateContextProvider>, |
| 34 | + ) |
| 35 | + |
| 36 | + // Flip auth to true with a non-roo provider (anthropic) |
| 37 | + postStateMessage({ |
| 38 | + cloudIsAuthenticated: true, |
| 39 | + apiConfiguration: { apiProvider: "anthropic" }, |
| 40 | + }) |
| 41 | + |
| 42 | + // Should NOT fire auth-driven Roo refresh |
| 43 | + await waitFor(() => { |
| 44 | + const calls = (vscode.postMessage as any).mock.calls as any[][] |
| 45 | + const hasRequest = calls.some((c) => c[0]?.type === "requestRooModels") |
| 46 | + expect(hasRequest).toBe(false) |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + it("posts requestRooModels when auth flips and provider === 'roo'", async () => { |
| 51 | + render( |
| 52 | + <ExtensionStateContextProvider> |
| 53 | + <div /> |
| 54 | + </ExtensionStateContextProvider>, |
| 55 | + ) |
| 56 | + |
| 57 | + // Ensure prev false (explicit) |
| 58 | + postStateMessage({ |
| 59 | + cloudIsAuthenticated: false, |
| 60 | + apiConfiguration: { apiProvider: "roo" }, |
| 61 | + }) |
| 62 | + |
| 63 | + vi.clearAllMocks() |
| 64 | + |
| 65 | + // Flip to true with provider roo - should trigger |
| 66 | + postStateMessage({ |
| 67 | + cloudIsAuthenticated: true, |
| 68 | + apiConfiguration: { apiProvider: "roo" }, |
| 69 | + }) |
| 70 | + |
| 71 | + await waitFor(() => { |
| 72 | + expect(vscode.postMessage).toHaveBeenCalledWith({ type: "requestRooModels" }) |
| 73 | + }) |
| 74 | + }) |
| 75 | +}) |
0 commit comments