forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDestinationDataProvider.spec.js
206 lines (189 loc) · 5.29 KB
/
DestinationDataProvider.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
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
/**
* This source file is part of the Swift.org open source project
*
* Copyright (c) 2021 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 DestinationDataProvider
from 'docc-render/components/DestinationDataProvider.vue';
import { shallowMount } from '@vue/test-utils';
const Destinations = {
link: {
type: 'link',
title: 'LinkTitle',
destination: '/link',
},
reference: {
type: 'reference',
title: 'ReferenceTitle',
identifier: 'foobar',
},
referenceLink: {
type: 'reference',
title: 'ReferenceTitle',
identifier: 'referenceLink',
},
text: {
type: 'text',
text: '/foo',
},
};
const scopedSlotAssertions = {};
const references = {
foobar: {
abstract: [],
title: 'Technologies',
kind: 'article',
type: 'topic',
identifier: 'foo',
url: '/documentation/technologies',
},
referenceLink: {
title: 'External Reference',
kind: 'reference',
type: 'link',
identifier: 'referenceLink',
url: 'http://extenral-url.com',
},
};
const createWrapper = (overrides) => {
const config = {
propsData: {
destination: Destinations.link,
},
provide: {
store: {
state: { references },
},
},
scopedSlots: {
default(params) {
Object.assign(scopedSlotAssertions, params);
return this.$createElement('div');
},
},
...overrides,
};
const wrapper = shallowMount(DestinationDataProvider, config);
return {
config,
wrapper,
};
};
describe('DestinationDataProvider', () => {
it('provides proper attributes for `type:link`', () => {
createWrapper();
expect(scopedSlotAssertions.url).toBe('/link');
expect(scopedSlotAssertions.title).toBe('LinkTitle');
expect(scopedSlotAssertions.isExternal).toBe(true);
});
it('provides title and url for `type: reference`', () => {
createWrapper({
propsData: {
destination: Destinations.reference,
},
});
expect(scopedSlotAssertions.url).toEqual('/documentation/technologies');
expect(scopedSlotAssertions.title).toEqual('Technologies');
expect(scopedSlotAssertions.isExternal).toBe(false);
});
it('sets a `reference` destination with type `link` as external', () => {
createWrapper({
propsData: {
destination: Destinations.referenceLink,
},
});
expect(scopedSlotAssertions.url).toEqual(references.referenceLink.url);
expect(scopedSlotAssertions.title).toEqual(references.referenceLink.title);
expect(scopedSlotAssertions.isExternal).toBe(true);
});
it('provides title and url for `type: text`', () => {
createWrapper({
propsData: {
destination: Destinations.text,
},
});
expect(scopedSlotAssertions.url).toEqual(Destinations.text.text);
expect(scopedSlotAssertions.title).toEqual('');
});
describe('aria-label formatter related', () => {
it('provides proper aria-label if not `external`', () => {
createWrapper({
propsData: {
destination: Destinations.reference,
},
});
expect(scopedSlotAssertions.formatAriaLabel('foo')).toBe('foo');
});
it('provides proper aria-label formatting if `external` but not `IDE`', () => {
createWrapper({
propsData: {
destination: Destinations.referenceLink,
},
provide: {
references,
isTargetIDE: false,
},
});
expect(scopedSlotAssertions.formatAriaLabel('foo')).toBe('foo');
});
it('provides proper aria-label formatting if Reference is `link` and in `IDE`', () => {
createWrapper({
propsData: {
destination: Destinations.referenceLink,
},
provide: {
store: {
state: { references },
},
isTargetIDE: true,
},
});
expect(scopedSlotAssertions.formatAriaLabel('foo')).toBe('foo (opens in browser)');
});
it('provides proper aria-label formatting if Destination `link` and in `IDE`', () => {
createWrapper({
propsData: {
destination: Destinations.link,
},
provide: {
references,
isTargetIDE: true,
},
});
expect(scopedSlotAssertions.formatAriaLabel('foo')).toBe('foo (opens in browser)');
});
});
it('does not error if no reference is found', () => {
createWrapper({
propsData: {
destination: Destinations.reference,
},
provide: {
references: {},
},
});
expect(scopedSlotAssertions.url).toEqual('');
expect(scopedSlotAssertions.title).toEqual('');
});
it('does not error out if no destination is provided at all', () => {
createWrapper({
propsData: {
destination: undefined,
},
});
expect(scopedSlotAssertions.url).toEqual('');
expect(scopedSlotAssertions.title).toEqual('');
});
it('uses the overridingTitle if available', () => {
createWrapper({
propsData: {
destination: { ...Destinations.reference, overridingTitle: 'OverridingTitle' },
},
});
expect(scopedSlotAssertions.title).toEqual('OverridingTitle');
});
});