forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArticle.spec.js
220 lines (190 loc) · 5.38 KB
/
Article.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**
* 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 { shallowMount } from '@vue/test-utils';
import Article from 'docc-render/components/Article.vue';
import Assessments from 'docc-render/components/Tutorial/Assessments.vue';
import Body from 'docc-render/components/Article/Body.vue';
import CallToAction from 'docc-render/components/Article/CallToAction.vue';
import Hero from 'docc-render/components/Article/Hero.vue';
import NavigationBar from 'docc-render/components/Tutorial/NavigationBar.vue';
import TopicStore from 'docc-render/stores/TopicStore';
import { PortalTarget } from 'portal-vue';
const { SectionKind } = Article;
const heroSection = {
kind: SectionKind.hero,
backgroundImage: 'bg.jpg',
chapter: 'Learning Swift',
content: [
{
type: 'paragraph',
inlineContent: [
{
type: 'text',
text: 'Property wrappers...',
},
],
},
],
estimatedTimeInMinutes: 42,
title: 'Swift Property Wrappers',
};
const bodySection = {
kind: SectionKind.articleBody,
content: [
{
kind: 'fullWidth',
content: [
{
type: 'paragraph',
inlineContent: [
{
type: 'text',
text: 'foobar',
},
],
},
],
},
],
};
const assessmentsSection = {
kind: SectionKind.assessments,
anchor: 'Check-your-understanding',
assessments: [],
};
const ctaSection = {
kind: SectionKind.callToAction,
abstract: [
{
type: 'text',
text: 'foobar',
},
],
action: {
type: 'reference',
identifier: 'topic://foo.bar',
isActive: true,
overridingTitle: 'Get started',
},
media: 'foo.bar',
title: 'Foo Bar',
};
const hierarchy = {
modules: [],
reference: 'foo',
technologyNavigation: ['overview', 'tutorials', 'resources'],
};
const propsData = {
hierarchy,
metadata: {
category: 'Building iOS Apps',
},
references: {},
sections: [
heroSection,
bodySection,
assessmentsSection,
ctaSection,
],
identifierUrl: 'foo',
};
describe('Article', () => {
let wrapper;
const provide = {
store: TopicStore,
};
beforeEach(() => {
wrapper = shallowMount(Article, { propsData, provide });
});
it('renders a div.article', () => {
expect(wrapper.is('div.article')).toBe(true);
});
it('provides a page title using the hero section title', () => {
const titleText = `${heroSection.title} — ${propsData.metadata.category} Tutorials | Documentation`;
expect(document.title).toBe(titleText);
});
it('provides a page description based on the hero content text', () => {
const { text: heroContentText } = heroSection.content[0].inlineContent[0];
expect(document.querySelector('meta[name="description"]').content).toBe(heroContentText);
});
it('renders a `NavigationBar`', () => {
const navBar = wrapper.find(NavigationBar);
expect(navBar.exists()).toBe(true);
expect(navBar.props()).toEqual({
chapters: propsData.hierarchy.modules,
technology: propsData.metadata.category,
topic: heroSection.title,
rootReference: hierarchy.reference,
identifierUrl: propsData.identifierUrl,
});
});
it('renders an article `Hero`', () => {
const { kind, ...heroProps } = heroSection;
const hero = wrapper.find(Hero);
expect(hero.exists()).toBe(true);
expect(hero.props()).toEqual(heroProps);
});
describe('without hero section', () => {
beforeEach(() => {
wrapper.setProps({ sections: [] });
});
it('does not provide a page title', () => {
expect(wrapper.vm.pageTitle).toBe(undefined);
});
});
it('renders an article `Body`', () => {
const { kind, ...bodyProps } = bodySection;
const body = wrapper.find(Body);
expect(body.exists()).toBe(true);
expect(body.props()).toEqual(bodyProps);
});
it('renders an assessments section', () => {
const { kind, ...assessmentsProps } = assessmentsSection;
const assessments = wrapper.find(Assessments);
expect(assessments.exists()).toBe(true);
expect(assessments.props()).toEqual(assessmentsProps);
});
it('renders an article `CallToAction`', () => {
const { kind, ...ctaProps } = ctaSection;
const cta = wrapper.find(CallToAction);
expect(cta.exists()).toBe(true);
expect(cta.props()).toEqual(ctaProps);
});
it('renders a `PortalTarget`', () => {
const target = wrapper.find(PortalTarget);
expect(target.exists()).toBe(true);
expect(target.props()).toHaveProperty('name', 'modal-destination');
});
it('renders content in the `above-hero` slot', () => {
wrapper = shallowMount(Article, {
propsData,
provide,
slots: {
'above-hero': 'Above Hero Text',
},
});
expect(wrapper.text()).toContain('Above Hero Text');
});
});
describe('with `isTargetIDE`', () => {
let wrapper;
beforeEach(() => {
wrapper = shallowMount(Article, {
propsData,
provide: {
isTargetIDE: true,
},
});
});
it('does not render a `NavigationBar', () => {
const nav = wrapper.find(NavigationBar);
expect(nav.exists()).toBe(false);
});
});