|
| 1 | +/********************************************************************** |
| 2 | + * Copyright (C) 2025 Red Hat, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + ***********************************************************************/ |
| 18 | +import { expect, test, beforeEach, describe, vi } from 'vitest'; |
| 19 | +import '@testing-library/jest-dom/vitest'; |
| 20 | +import { fireEvent, render, within } from '@testing-library/svelte'; |
| 21 | +import type { McpServer } from '@shared/models/McpSettings'; |
| 22 | +import ToolSelectionModal from '/@/lib/conversation/ToolSelectionModal.svelte'; |
| 23 | + |
| 24 | +let container: HTMLElement; |
| 25 | + |
| 26 | +beforeEach(() => { |
| 27 | + vi.resetAllMocks(); |
| 28 | +}); |
| 29 | + |
| 30 | +describe('with servers', () => { |
| 31 | + beforeEach(() => { |
| 32 | + container = render(ToolSelectionModal, { |
| 33 | + mcpServers: [{ name: 'server-1' } as unknown as McpServer, { name: 'server-2' } as unknown as McpServer], |
| 34 | + }).container; |
| 35 | + }); |
| 36 | + describe('closed', () => { |
| 37 | + test('has button', () => { |
| 38 | + const button = within(container).getByTitle('MCP Servers'); |
| 39 | + expect(button).toBeVisible(); |
| 40 | + expect(button).toHaveTextContent('MCP Servers'); |
| 41 | + }); |
| 42 | + test('does not have modal', () => { |
| 43 | + const modal = within(container).queryByTestId('tool-selection-modal-tool-container'); |
| 44 | + expect(modal).toBeNull(); |
| 45 | + }); |
| 46 | + }); |
| 47 | + describe('open', () => { |
| 48 | + let button: HTMLElement; |
| 49 | + let modal: HTMLElement; |
| 50 | + beforeEach(async () => { |
| 51 | + button = within(container).getByTitle('MCP Servers'); |
| 52 | + await fireEvent.click(button); |
| 53 | + modal = within(container).getByTestId('tool-selection-modal-tool-container'); |
| 54 | + }); |
| 55 | + test('has modal', () => { |
| 56 | + expect(modal).toBeVisible(); |
| 57 | + }); |
| 58 | + test('contains defined server entries', () => { |
| 59 | + const toolEntries = within(modal).getAllByTestId('tool-selection-modal-tool-item'); |
| 60 | + expect(toolEntries).toHaveLength(2); |
| 61 | + }); |
| 62 | + test.each(['server-1', 'server-2'])('has %s entry', name => { |
| 63 | + const serverEntry = within(modal).getByText(name); |
| 64 | + expect(serverEntry).toBeVisible(); |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments