-
Notifications
You must be signed in to change notification settings - Fork 268
/
IconsStyle.spec.ts
77 lines (66 loc) · 2.51 KB
/
IconsStyle.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
/**********************************************************************
* 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
***********************************************************************/
/* eslint-disable @typescript-eslint/no-explicit-any */
import '@testing-library/jest-dom';
import { beforeAll, test, expect, vi } from 'vitest';
import { render } from '@testing-library/svelte';
import IconsStyle from './IconsStyle.svelte';
import { iconsInfos } from '/@/stores/icons';
import { get } from 'svelte/store';
import type { IconInfo } from '../../../../main/src/plugin/api/icon-info';
const listIconsMock = vi.fn();
// fake the window object
beforeAll(() => {
(window as any).listIcons = listIconsMock;
});
test('Check containers button is available and click on it', async () => {
const file = 'file://my-font.woff';
const icon: IconInfo = {
id: 'my-icon-id',
definition: {
description: 'This is a description',
font: {
fontId: 'my-font-id',
src: [
{
location: 'my-font.woff',
browserURL: `url('${file}')`,
format: 'woff2',
},
],
},
fontCharacter: '\\E01',
},
};
listIconsMock.mockResolvedValue([icon]);
window.dispatchEvent(new CustomEvent('extensions-already-started'));
// wait store is populated
while (get(iconsInfos).length === 0) {
await new Promise(resolve => setTimeout(resolve, 500));
}
render(IconsStyle);
// expect to have the generated style for the icon
const style = document.querySelector('style');
expect(style).toBeInTheDocument();
// should have css type
expect(style).toHaveAttribute('type', 'text/css');
// check content
expect(style).toHaveTextContent(
`.podman-desktop-icon-my-icon-id:before { content: '\\E01'; font-family: '${icon.definition.font.fontId}'; } @font-face { src: url('file://my-font.woff') format('woff2'); font-family: 'my-font-id'; font-display: block; }`,
);
});