Skip to content

Commit 15b79c6

Browse files
committed
test: unit tests for KubernetesProviderCard
Signed-off-by: Philippe Martin <[email protected]>
1 parent e715263 commit 15b79c6

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

packages/channels/src/channels.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,27 @@ export const POD_LOGS = createRpcChannel<PodLogsChunk>('PodLogs');
6666

6767
export const API_POD_TERMINALS = createRpcChannel<PodTerminalsApi>('PodTerminalsApi');
6868
export const POD_TERMINAL_DATA = createRpcChannel<PodTerminalChunk>('PodTerminalData');
69+
70+
export {
71+
ContextsApi,
72+
NavigationApi,
73+
PodLogsApi,
74+
PodTerminalsApi,
75+
PortForwardApi,
76+
SubscribeApi,
77+
SystemApi,
78+
ActiveResourcesCountInfo,
79+
AvailableContextsInfo,
80+
ContextsHealthsInfo,
81+
ContextsPermissionsInfo,
82+
CurrentContextInfo,
83+
EndpointsInfo,
84+
KubernetesProvidersInfo,
85+
PodLogsChunk,
86+
PodTerminalChunk,
87+
PortForwardsInfo,
88+
ResourceDetailsInfo,
89+
ResourceEventsInfo,
90+
ResourcesCountInfo,
91+
UpdateResourceInfo,
92+
};
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
19+
import '@testing-library/jest-dom/vitest';
20+
21+
import { render, screen } from '@testing-library/svelte';
22+
import { beforeEach, expect, test, vi } from 'vitest';
23+
import KubernetesProviderCard from '/@/component/dashboard/KubernetesProviderCard.svelte';
24+
import { RemoteMocks } from '/@/tests/remote-mocks';
25+
import { API_NAVIGATION } from '@kubernetes-dashboard/channels';
26+
import type { NavigationApi } from '@kubernetes-dashboard/channels';
27+
import userEvent from '@testing-library/user-event';
28+
29+
const remoteMocks = new RemoteMocks();
30+
31+
beforeEach(() => {
32+
vi.resetAllMocks();
33+
remoteMocks.reset();
34+
35+
remoteMocks.mock(API_NAVIGATION, {
36+
navigateToProviderNewConnection: vi.fn(),
37+
} as unknown as NavigationApi);
38+
});
39+
40+
test('should render with all values passed', async () => {
41+
render(KubernetesProviderCard, {
42+
provider: {
43+
id: 'k8s-provider',
44+
creationDisplayName: 'Kubernetes Provider',
45+
creationButtonTitle: 'Create Kubernetes Provider',
46+
emptyConnectionMarkdownDescription: 'Create a new Kubernetes Provider',
47+
},
48+
});
49+
screen.getByText('Kubernetes Provider');
50+
screen.getByText('Create Kubernetes Provider');
51+
const btn = screen.getByRole('button', { name: 'Create Kubernetes Provider' });
52+
expect(btn).toBeEnabled();
53+
await userEvent.click(btn);
54+
expect(remoteMocks.get(API_NAVIGATION).navigateToProviderNewConnection).toHaveBeenCalledWith('k8s-provider');
55+
});
56+
57+
test('should render with minimal values passed', async () => {
58+
render(KubernetesProviderCard, {
59+
provider: {
60+
id: 'k8s-provider',
61+
},
62+
});
63+
screen.getByText('Create');
64+
screen.getByText('Create new');
65+
const btn = screen.getByRole('button', { name: 'Create new' });
66+
expect(btn).toBeEnabled();
67+
await userEvent.click(btn);
68+
expect(remoteMocks.get(API_NAVIGATION).navigateToProviderNewConnection).toHaveBeenCalledWith('k8s-provider');
69+
});

0 commit comments

Comments
 (0)