forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopicTypeIcon.spec.js
79 lines (72 loc) · 2.39 KB
/
TopicTypeIcon.spec.js
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
/**
* This source file is part of the Swift.org open source project
*
* Copyright (c) 2022 Apple Inc. and the Swift project authors
* Licensed under Apache License v2.0 with Runtime Library Exception
*
* See https://swift.org/LICENSE.txt for license information
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
import TopicTypeIcon from 'docc-render/components/TopicTypeIcon.vue';
import { mount } from '@vue/test-utils';
import { TopicTypes, TopicTypeAliases } from '@/constants/TopicTypes';
import { HeroColorsMap } from 'docc-render/constants/HeroColors';
import CollectionIcon from '@/components/Icons/CollectionIcon.vue';
import OverridableAsset from '@/components/OverridableAsset.vue';
const createWrapper = opts => mount(TopicTypeIcon, opts);
const {
TopicTypeIcons,
TopicTypeProps,
} = TopicTypeIcon.constants;
const cases = Object.keys(TopicTypes).map((type) => {
const k = TopicTypeAliases[type] || type;
const icon = TopicTypeIcons[k] || CollectionIcon;
const color = HeroColorsMap[k];
return [type, icon.name, TopicTypeProps[type] || {}, color, icon];
});
describe('TopicTypeIcon', () => {
it.each(cases)('Should render %s as %s, with %O bindings, and a %s color', (type, iconName, bindings, color, icon) => {
const wrapper = createWrapper({
propsData: {
type,
withColors: true,
},
});
const iconComponent = wrapper.find(icon);
expect(iconComponent.props()).toMatchObject(bindings);
if (color) {
// we cannot assert on component, because JSDOM does not work with custom CSS vars
expect(wrapper.vm.styles).toHaveProperty('--icon-color', `var(--color-type-icon-${color})`);
}
});
it('renders an icon, without color class', () => {
const wrapper = createWrapper({
propsData: {
type: TopicTypes.class,
withColors: false,
},
});
expect(wrapper.vm.styles).not.toHaveProperty('--icon-color');
});
it('renders an icon override', () => {
const imageOverride = {
variants: [{
url: 'baz.svg',
svgID: 'foo',
}, {
url: 'bar.svg',
}],
};
const wrapper = createWrapper({
propsData: {
imageOverride,
type: TopicTypes.class,
},
});
const icon = wrapper.find('.icon-inline');
expect(icon.is(OverridableAsset)).toBe(true);
expect(icon.props()).toMatchObject({
imageOverride,
});
});
});