forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopicLinkBlockIcon.spec.js
71 lines (64 loc) · 2.07 KB
/
TopicLinkBlockIcon.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
/**
* 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 TopicLinkBlockIcon from '@/components/DocumentationTopic/TopicLinkBlockIcon.vue';
import { mount } from '@vue/test-utils';
import { TopicRole } from '@/constants/roles';
import ArticleIcon from '@/components/Icons/ArticleIcon.vue';
import TechnologyIcon from '@/components/Icons/TechnologyIcon.vue';
import OverridableAsset from '@/components/OverridableAsset.vue';
const defaultProps = {
role: TopicRole.article,
};
const createWrapper = ({ propsData, ...others } = {}) => mount(TopicLinkBlockIcon, {
propsData: {
...defaultProps,
...propsData,
},
...others,
});
describe('TopicLinkBlockIcon', () => {
it('renders an icon from a `role`', () => {
const wrapper = createWrapper();
expect(wrapper.find('.topic-icon').is(ArticleIcon)).toBe(true);
});
it('renders an override icon from an image override', () => {
const imageOverride = {
variants: [{
url: '/foo/bar',
svgID: 'foo',
}],
};
const wrapper = createWrapper({
propsData: {
imageOverride,
},
});
const icon = wrapper.find('.topic-icon');
expect(icon.is(ArticleIcon)).toBe(false);
expect(icon.is(OverridableAsset)).toBe(true);
expect(icon.props()).toMatchObject({
imageOverride,
});
});
it('renders nothing if no role or image override', () => {
const wrapper = createWrapper({
propsData: {
imageOverride: null,
role: TopicRole.devLink, // no icon for this
},
});
expect(wrapper.html()).toBeFalsy();
});
it('uses the technology icon for collections', () => {
const propsData = { role: TopicRole.collection };
const wrapper = createWrapper({ propsData });
expect(wrapper.find('.topic-icon').is(TechnologyIcon)).toBe(true);
});
});