Skip to content

Commit 0b8b113

Browse files
committed
Fix tests
1 parent 4e38d96 commit 0b8b113

File tree

2 files changed

+34
-90
lines changed

2 files changed

+34
-90
lines changed

src/services/marketplace/__tests__/marketplace-setting-check.spec.ts

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ import { webviewMessageHandler } from "../../../core/webview/webviewMessageHandl
66
const mockProvider = {
77
getState: vi.fn(),
88
postStateToWebview: vi.fn(),
9+
postMessageToWebview: vi.fn(),
910
} as any
1011

1112
const mockMarketplaceManager = {
1213
updateWithFilteredItems: vi.fn(),
1314
} as any
1415

15-
describe("Marketplace Setting Check", () => {
16+
describe("Marketplace General Availability", () => {
1617
beforeEach(() => {
1718
vi.clearAllMocks()
1819
})
1920

20-
it("should skip API calls when marketplace is disabled", async () => {
21-
// Mock experiments with marketplace disabled
21+
it("should allow marketplace API calls (marketplace is generally available)", async () => {
22+
// Mock state without marketplace experiment (since it's now generally available)
2223
mockProvider.getState.mockResolvedValue({
23-
experiments: { marketplace: false },
24+
experiments: {},
2425
})
2526

2627
const message = {
@@ -30,25 +31,7 @@ describe("Marketplace Setting Check", () => {
3031

3132
await webviewMessageHandler(mockProvider, message, mockMarketplaceManager)
3233

33-
// Should not call marketplace manager methods
34-
expect(mockMarketplaceManager.updateWithFilteredItems).not.toHaveBeenCalled()
35-
expect(mockProvider.postStateToWebview).not.toHaveBeenCalled()
36-
})
37-
38-
it("should allow API calls when marketplace is enabled", async () => {
39-
// Mock experiments with marketplace enabled
40-
mockProvider.getState.mockResolvedValue({
41-
experiments: { marketplace: true },
42-
})
43-
44-
const message = {
45-
type: "filterMarketplaceItems" as const,
46-
filters: { type: "mcp", search: "", tags: [] },
47-
}
48-
49-
await webviewMessageHandler(mockProvider, message, mockMarketplaceManager)
50-
51-
// Should call marketplace manager methods
34+
// Should call marketplace manager methods since marketplace is generally available
5235
expect(mockMarketplaceManager.updateWithFilteredItems).toHaveBeenCalledWith({
5336
type: "mcp",
5437
search: "",
@@ -57,13 +40,13 @@ describe("Marketplace Setting Check", () => {
5740
expect(mockProvider.postStateToWebview).toHaveBeenCalled()
5841
})
5942

60-
it("should skip installation when marketplace is disabled", async () => {
61-
// Mock experiments with marketplace disabled
43+
it("should allow marketplace installation (marketplace is generally available)", async () => {
44+
// Mock state without marketplace experiment (since it's now generally available)
6245
mockProvider.getState.mockResolvedValue({
63-
experiments: { marketplace: false },
46+
experiments: {},
6447
})
6548

66-
const mockInstallMarketplaceItem = vi.fn()
49+
const mockInstallMarketplaceItem = vi.fn().mockResolvedValue(undefined)
6750
const mockMarketplaceManagerWithInstall = {
6851
installMarketplaceItem: mockInstallMarketplaceItem,
6952
}
@@ -83,7 +66,7 @@ describe("Marketplace Setting Check", () => {
8366

8467
await webviewMessageHandler(mockProvider, message, mockMarketplaceManagerWithInstall as any)
8568

86-
// Should not call install method
87-
expect(mockInstallMarketplaceItem).not.toHaveBeenCalled()
69+
// Should call install method since marketplace is generally available
70+
expect(mockInstallMarketplaceItem).toHaveBeenCalledWith(message.mpItem, message.mpInstallOptions)
8871
})
8972
})

webview-ui/src/__tests__/App.test.tsx

Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe("App", () => {
104104
didHydrateState: true,
105105
showWelcome: false,
106106
shouldShowAnnouncement: false,
107-
experiments: { marketplace: false },
107+
experiments: {},
108108
language: "en",
109109
})
110110
})
@@ -224,74 +224,35 @@ describe("App", () => {
224224
expect(screen.queryByTestId(`${view}-view`)).not.toBeInTheDocument()
225225
})
226226

227-
describe("marketplace experiment", () => {
228-
it("does not switch to marketplace tab when experiment is disabled", async () => {
229-
mockUseExtensionState.mockReturnValue({
230-
didHydrateState: true,
231-
showWelcome: false,
232-
shouldShowAnnouncement: false,
233-
experiments: { marketplace: false },
234-
language: "en",
235-
})
236-
237-
render(<AppWithProviders />)
238-
239-
act(() => {
240-
triggerMessage("marketplaceButtonClicked")
241-
})
242-
243-
// Should remain on chat view
244-
const chatView = screen.getByTestId("chat-view")
245-
expect(chatView.getAttribute("data-hidden")).toBe("false")
246-
expect(screen.queryByTestId("marketplace-view")).not.toBeInTheDocument()
247-
})
248-
249-
it("switches to marketplace tab when experiment is enabled", async () => {
250-
mockUseExtensionState.mockReturnValue({
251-
didHydrateState: true,
252-
showWelcome: false,
253-
shouldShowAnnouncement: false,
254-
experiments: { marketplace: true },
255-
language: "en",
256-
})
257-
258-
render(<AppWithProviders />)
259-
260-
act(() => {
261-
triggerMessage("marketplaceButtonClicked")
262-
})
263-
264-
const marketplaceView = await screen.findByTestId("marketplace-view")
265-
expect(marketplaceView).toBeInTheDocument()
227+
it("switches to marketplace view when receiving marketplaceButtonClicked action", async () => {
228+
render(<AppWithProviders />)
266229

267-
const chatView = screen.getByTestId("chat-view")
268-
expect(chatView.getAttribute("data-hidden")).toBe("true")
230+
act(() => {
231+
triggerMessage("marketplaceButtonClicked")
269232
})
270233

271-
it("returns to chat view when clicking done in marketplace view", async () => {
272-
mockUseExtensionState.mockReturnValue({
273-
didHydrateState: true,
274-
showWelcome: false,
275-
shouldShowAnnouncement: false,
276-
experiments: { marketplace: true },
277-
language: "en",
278-
})
234+
const marketplaceView = await screen.findByTestId("marketplace-view")
235+
expect(marketplaceView).toBeInTheDocument()
279236

280-
render(<AppWithProviders />)
237+
const chatView = screen.getByTestId("chat-view")
238+
expect(chatView.getAttribute("data-hidden")).toBe("true")
239+
})
281240

282-
act(() => {
283-
triggerMessage("marketplaceButtonClicked")
284-
})
241+
it("returns to chat view when clicking done in marketplace view", async () => {
242+
render(<AppWithProviders />)
285243

286-
const marketplaceView = await screen.findByTestId("marketplace-view")
244+
act(() => {
245+
triggerMessage("marketplaceButtonClicked")
246+
})
287247

288-
act(() => {
289-
marketplaceView.click()
290-
})
248+
const marketplaceView = await screen.findByTestId("marketplace-view")
291249

292-
const chatView = screen.getByTestId("chat-view")
293-
expect(chatView.getAttribute("data-hidden")).toBe("false")
294-
expect(screen.queryByTestId("marketplace-view")).not.toBeInTheDocument()
250+
act(() => {
251+
marketplaceView.click()
295252
})
253+
254+
const chatView = screen.getByTestId("chat-view")
255+
expect(chatView.getAttribute("data-hidden")).toBe("false")
256+
expect(screen.queryByTestId("marketplace-view")).not.toBeInTheDocument()
296257
})
297258
})

0 commit comments

Comments
 (0)