forked from containers/podman-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OnboardingItem.spec.ts
225 lines (215 loc) · 7.95 KB
/
OnboardingItem.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**********************************************************************
* 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/vitest';
import { test, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/svelte';
import OnboardingItem from './OnboardingItem.svelte';
import type { OnboardingStepItem } from '../../../../main/src/plugin/api/onboarding';
import { context } from '/@/stores/context';
import { configurationProperties } from '/@/stores/configurationProperties';
import { CONFIGURATION_ONBOARDING_SCOPE } from '../../../../main/src/plugin/configuration-registry-constants';
import { ContextUI } from '../context/context';
test('Expect button html when passing a button tag in markdown', async () => {
const textComponent: OnboardingStepItem = {
value: ':button[label]{command=command}',
};
render(OnboardingItem, {
extension: 'extension',
item: textComponent,
inProgressCommandExecution: vi.fn(),
});
const button = screen.getByRole('button', { name: 'label' });
expect(button).toBeInTheDocument();
expect(button.dataset.command).toBe('command');
});
test('Expect markdown html when passing a text component', async () => {
const textComponent: OnboardingStepItem = {
value: 'html content here',
};
render(OnboardingItem, {
extension: 'extension',
item: textComponent,
inProgressCommandExecution: vi.fn(),
});
const markdownSection = screen.getByLabelText('markdown-content');
expect(markdownSection).toBeInTheDocument();
expect(markdownSection.innerHTML.includes('html content here')).toBe(true);
});
test('Expect placeholders are replaced when passing a text component with placeholders', async () => {
const textComponent: OnboardingStepItem = {
value: '${onboardingContext:text}',
};
const globalContext = new ContextUI();
globalContext.setValue('extension.onboarding.text', 'placeholder content');
context.set(globalContext);
render(OnboardingItem, {
extension: 'extension',
item: textComponent,
inProgressCommandExecution: vi.fn(),
});
const markdownSection = screen.getByLabelText('markdown-content');
expect(markdownSection).toBeInTheDocument();
expect(markdownSection.innerHTML.includes('placeholder content')).toBe(true);
});
test('Expect boolean configuration placeholder to be replaced with a checkbox', async () => {
const textComponent: OnboardingStepItem = {
value: '${configuration:extension.boolean.prop}',
};
configurationProperties.set([
{
parentId: '',
title: 'record',
description: 'record-description',
extension: {
id: 'extension',
},
hidden: false,
id: 'extension.boolean.prop',
type: 'boolean',
default: false,
scope: CONFIGURATION_ONBOARDING_SCOPE,
},
]);
render(OnboardingItem, {
extension: 'extension',
item: textComponent,
inProgressCommandExecution: vi.fn(),
});
const input = screen.getByLabelText('record-description');
expect(input).toBeInTheDocument();
expect(input instanceof HTMLInputElement).toBe(true);
expect((input as HTMLInputElement).type).toBe('checkbox');
expect((input as HTMLInputElement).name).toBe('extension.boolean.prop');
});
test('Expect when configuration placeholder is type string and format file to be replaced with an input button with Browse', async () => {
const textComponent: OnboardingStepItem = {
value: '${configuration:extension.format.prop}',
};
configurationProperties.set([
{
parentId: '',
title: 'record',
placeholder: 'Example: text',
description: 'record-description',
extension: {
id: 'extension',
},
hidden: false,
id: 'extension.format.prop',
type: 'string',
format: 'file',
scope: CONFIGURATION_ONBOARDING_SCOPE,
},
]);
render(OnboardingItem, {
extension: 'extension',
item: textComponent,
inProgressCommandExecution: vi.fn(),
});
const readOnlyInput = screen.getByLabelText('record-description');
expect(readOnlyInput).toBeInTheDocument();
expect(readOnlyInput instanceof HTMLInputElement).toBe(true);
expect((readOnlyInput as HTMLInputElement).placeholder).toBe('Example: text');
const input = screen.getByLabelText('button-record-description');
expect(input).toBeInTheDocument();
expect(input.textContent).toBe('Browse ...');
});
test('Expect a type text configuration placeholder to be replaced by a text input', async () => {
const textComponent: OnboardingStepItem = {
value: '${configuration:extension.text.prop}',
};
configurationProperties.set([
{
parentId: '',
title: 'record',
placeholder: 'Example: text',
description: 'record-description',
extension: {
id: 'extension',
},
hidden: false,
id: 'extension.text.prop',
type: 'string',
scope: CONFIGURATION_ONBOARDING_SCOPE,
},
]);
render(OnboardingItem, {
extension: 'extension',
item: textComponent,
inProgressCommandExecution: vi.fn(),
});
const input = screen.getByLabelText('record-description');
expect(input).toBeInTheDocument();
expect(input instanceof HTMLInputElement).toBe(true);
expect((input as HTMLInputElement).type).toBe('text');
expect((input as HTMLSelectElement).name).toBe('extension.text.prop');
expect((input as HTMLInputElement).placeholder).toBe('Example: text');
});
test('Expect a configuration to be visible in the onboarding even if hidden property is set to true', async () => {
const textComponent: OnboardingStepItem = {
value: '${configuration:extension.text.prop}',
};
configurationProperties.set([
{
parentId: '',
title: 'record',
placeholder: 'Example: text',
description: 'record-description',
extension: {
id: 'extension',
},
hidden: true,
id: 'extension.text.prop',
type: 'string',
scope: CONFIGURATION_ONBOARDING_SCOPE,
},
]);
render(OnboardingItem, {
extension: 'extension',
item: textComponent,
inProgressCommandExecution: vi.fn(),
});
const input = screen.getByLabelText('record-description');
expect(input).toBeInTheDocument();
expect(input instanceof HTMLInputElement).toBe(true);
expect((input as HTMLInputElement).type).toBe('text');
expect((input as HTMLSelectElement).name).toBe('extension.text.prop');
expect((input as HTMLInputElement).placeholder).toBe('Example: text');
});
test('Expect value rendered is updated if context value is updated', async () => {
const textComponent: OnboardingStepItem = {
value: '${onboardingContext:text}',
};
const globalContext = new ContextUI();
globalContext.setValue('extension.onboarding.text', 'first value');
context.set(globalContext);
render(OnboardingItem, {
extension: 'extension',
item: textComponent,
inProgressCommandExecution: vi.fn(),
});
const markdownSection = screen.getByLabelText('markdown-content');
expect(markdownSection).toBeInTheDocument();
expect(markdownSection.innerHTML.includes('first value')).toBe(true);
// simulate the value in context is updated
globalContext.setValue('extension.onboarding.text', 'second value');
context.set(globalContext);
await new Promise(resolve => setTimeout(resolve, 100));
const markdownSection2 = screen.getByLabelText('markdown-content');
expect(markdownSection2.innerHTML.includes('second value')).toBe(true);
});