-
Notifications
You must be signed in to change notification settings - Fork 268
/
KubePlayYAML.spec.ts
142 lines (132 loc) · 4.41 KB
/
KubePlayYAML.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**********************************************************************
* Copyright (C) 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/
import '@testing-library/jest-dom';
import { test, expect, vi } from 'vitest';
import { providerInfos } from '../../stores/providers';
import { render, screen } from '@testing-library/svelte';
import KubePlayYAML from './KubePlayYAML.svelte';
import type { ProviderStatus } from '@podman-desktop/api';
import type { ProviderContainerConnectionInfo } from '../../../../main/src/plugin/api/provider-info';
import userEvent from '@testing-library/user-event';
import type { PlayKubeInfo } from '../../../../main/src/plugin/dockerode/libpod-dockerode';
const mockedErroredPlayKubeInfo: PlayKubeInfo = {
Pods: [
{
ContainerErrors: ['error 1', 'error 2'],
Containers: ['container 1', 'container 2'],
Id: 'pod-id',
InitContainers: ['init-container 1', 'init-container 2'],
Logs: ['log 1', 'log 2'],
},
],
RmReport: [
{
Err: 'rm error',
Id: 'rm-id',
},
],
Secrets: [
{
CreateReport: {
ID: 'secret-id',
},
},
],
StopReport: [
{
Err: 'stop error',
Id: 'stop-id',
},
],
Volumes: [
{
Name: 'volume 1',
},
{
Name: 'volume 2',
},
],
};
// fake the window.events object
beforeAll(() => {
(window.events as unknown) = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
receive: (_channel: string, func: any) => {
func();
},
};
(window as any).getConfigurationValue = vi.fn();
(window as any).matchMedia = vi.fn().mockReturnValue({
addListener: vi.fn(),
});
(window as any).openFileDialog = vi.fn().mockResolvedValue({ canceled: false, filePaths: ['Containerfile'] });
(window as any).telemetryPage = vi.fn();
(window as any).kubernetesGetCurrentContextName = vi.fn();
(window as any).kubernetesGetCurrentNamespace = vi.fn();
(window as any).kubernetesListNamespaces = vi.fn();
});
function setup() {
const pStatus: ProviderStatus = 'started';
const pInfo: ProviderContainerConnectionInfo = {
name: 'test',
status: 'started',
endpoint: {
socketPath: '',
},
type: 'podman',
};
const providerInfo = {
id: 'test',
internalId: 'id',
name: '',
containerConnections: [pInfo],
kubernetesConnections: undefined,
status: pStatus,
containerProviderConnectionCreation: false,
containerProviderConnectionInitialization: false,
kubernetesProviderConnectionCreation: false,
kubernetesProviderConnectionInitialization: false,
links: undefined,
detectionChecks: undefined,
warnings: undefined,
images: undefined,
installationSupport: undefined,
};
providerInfos.set([providerInfo]);
}
test('error: When pressing the Play button, expect us to show the errors to the user', async () => {
(window as any).playKube = vi.fn().mockResolvedValue(mockedErroredPlayKubeInfo);
// Render the component
setup();
render(KubePlayYAML, {});
// Simulate selecting a file
const fileInput = screen.getByRole('textbox', { name: 'Kubernetes YAML file' });
expect(fileInput).toBeInTheDocument();
await userEvent.click(fileInput);
// Simulate selecting a runtime
const runtimeOption = screen.getByText('Using a Podman container engine');
expect(runtimeOption).toBeInTheDocument();
// Simulate clicking the "Play" button
const playButton = screen.getByRole('button', { name: 'Play' });
expect(playButton).toBeInTheDocument();
await userEvent.click(playButton);
// Since we error out with the mocked kubePlay function (see very top of tests)
// Expect the following error to be in in the document.
const error = screen.getByText('The following pods were created but failed to start: error 1, error 2');
expect(error).toBeInTheDocument();
});