Skip to content

Commit f68d28e

Browse files
authored
only show decl diff when list is collapsed (#829) rdar://127126248
only show decl diff when list is collapsed (#829) rdar://127126248
1 parent 7e0940f commit f68d28e

File tree

6 files changed

+55
-50
lines changed

6 files changed

+55
-50
lines changed

src/components/DocumentationTopic/PrimaryContent/Declaration.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
<template>
1212
<section class="declaration">
13-
<template v-if="hasModifiedChanges">
13+
<template v-if="hasModifiedChanges && !isExpanded">
1414
<DeclarationDiff
1515
:class="[changeClasses, multipleLinesClass]"
1616
:changes="declarationChanges"
1717
:changeType="changeType"
1818
/>
1919
</template>
2020
<template v-else>
21-
<DeclarationGroup
21+
<DeclarationList
2222
v-for="(declaration, i) in declarations"
2323
:class="changeClasses"
2424
:key="i"
@@ -45,8 +45,8 @@
4545
import ConditionalConstraints
4646
from 'docc-render/components/DocumentationTopic/ConditionalConstraints.vue';
4747

48-
import DeclarationGroup
49-
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationGroup.vue';
48+
import DeclarationList
49+
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationList.vue';
5050
import DeclarationDiff
5151
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationDiff.vue';
5252
import DeclarationSourceLink
@@ -59,7 +59,7 @@ export default {
5959
name: 'Declaration',
6060
components: {
6161
DeclarationDiff,
62-
DeclarationGroup,
62+
DeclarationList,
6363
DeclarationSourceLink,
6464
ConditionalConstraints,
6565
},

src/components/DocumentationTopic/PrimaryContent/DeclarationDiff.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div class="declaration-diff">
1313
<div class="declaration-diff-current">
1414
<div class="declaration-diff-version">Current</div>
15-
<DeclarationGroup
15+
<DeclarationList
1616
v-for="(declaration, i) in currentDeclarations"
1717
:key="i"
1818
:declaration="declaration"
@@ -22,7 +22,7 @@
2222
</div>
2323
<div class="declaration-diff-previous">
2424
<div class="declaration-diff-version">Previous</div>
25-
<DeclarationGroup
25+
<DeclarationList
2626
v-for="(declaration, i) in previousDeclarations"
2727
:key="i"
2828
:declaration="declaration"
@@ -34,14 +34,14 @@
3434
</template>
3535

3636
<script>
37-
import DeclarationGroup from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationGroup.vue';
37+
import DeclarationList from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationList.vue';
3838

3939
/**
4040
* Renders a diff container around two DeclarationGroup components.
4141
*/
4242
export default {
4343
name: 'DeclarationDiff',
44-
components: { DeclarationGroup },
44+
components: { DeclarationList },
4545
props: {
4646
/**
4747
* The apiChanges object from the store.

tests/unit/components/DocumentationTopic/PrimaryContent/Declaration.spec.js

+31-26
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import DeclarationSourceLink
1919

2020
const {
2121
ConditionalConstraints,
22-
DeclarationGroup,
22+
DeclarationList,
2323
} = Declaration.components;
2424

2525
const { ChangeTypes } = Declaration.constants;
@@ -72,14 +72,14 @@ describe('Declaration', () => {
7272
expect(wrapper.is('section.declaration')).toBe(true);
7373
});
7474

75-
it('renders 1 `DeclarationGroup` and 0 labels without multiple declarations', () => {
76-
const declarationGroups = wrapper.findAll(DeclarationGroup);
77-
expect(declarationGroups).toHaveLength(1);
78-
expect(declarationGroups.at(0).props('shouldCaption')).toEqual(false);
75+
it('renders 1 `DeclarationList` and 0 labels without multiple declarations', () => {
76+
const declarationLists = wrapper.findAll(DeclarationList);
77+
expect(declarationLists).toHaveLength(1);
78+
expect(declarationLists.at(0).props('shouldCaption')).toEqual(false);
7979
});
8080

81-
it('renders a `DeclarationGroup`', () => {
82-
const group = wrapper.find(DeclarationGroup);
81+
it('renders a `DeclarationList`', () => {
82+
const group = wrapper.find(DeclarationList);
8383
expect(group.exists()).toBe(true);
8484
expect(group.props('declaration')).toEqual(propsData.declarations[0]);
8585
expect(group.props()).toHaveProperty('declListExpanded', false);
@@ -155,13 +155,13 @@ describe('Declaration', () => {
155155

156156
wrapper.setProps({ declarations });
157157

158-
const labels = wrapper.findAll(DeclarationGroup);
158+
const labels = wrapper.findAll(DeclarationList);
159159
expect(labels.length).toBe(declarations.length);
160160
expect(labels.at(0).props('shouldCaption')).toBe(true);
161161
expect(labels.at(1).props('shouldCaption')).toBe(true);
162162
});
163163

164-
it('renders a `DeclarationDiff` when there are API changes for current and previous', () => {
164+
it('renders a `DeclarationDiff` when there are API changes for current and previous and collapsed other declaration list', () => {
165165
// no DeclarationDiff if no changes
166166
expect(wrapper.find(DeclarationDiff).exists()).toBe(false);
167167
// there is no `.changed` class applied by default
@@ -191,9 +191,14 @@ describe('Declaration', () => {
191191
});
192192
expect(declarationDiff.classes()).toContain('changed');
193193
expect(declarationDiff.classes()).toContain('changed-modified');
194+
195+
wrapper.setProps({
196+
declListExpanded: true,
197+
});
198+
expect(wrapper.find(DeclarationDiff).exists()).toBe(false);
194199
});
195200

196-
it('renders a `DeclarationGroup` for `added` change type', () => {
201+
it('renders a `DeclarationList` for `added` change type', () => {
197202
const provide = provideFactory({
198203
[identifier]: {
199204
change: ChangeTypes.added,
@@ -210,14 +215,14 @@ describe('Declaration', () => {
210215

211216
expect(wrapper.find(DeclarationDiff).exists()).toBe(false);
212217

213-
const declarationGroup = wrapper.find(DeclarationGroup);
214-
expect(declarationGroup.props('changeType')).toBe(ChangeTypes.added);
215-
expect(declarationGroup.props('declaration')).toBe(propsData.declarations[0]);
216-
expect(declarationGroup.classes()).toContain('changed');
217-
expect(declarationGroup.classes()).toContain('changed-added');
218+
const declarationList = wrapper.find(DeclarationList);
219+
expect(declarationList.props('changeType')).toBe(ChangeTypes.added);
220+
expect(declarationList.props('declaration')).toBe(propsData.declarations[0]);
221+
expect(declarationList.classes()).toContain('changed');
222+
expect(declarationList.classes()).toContain('changed-added');
218223
});
219224

220-
it('renders a `DeclarationGroup` for `deprecated` change type', () => {
225+
it('renders a `DeclarationList` for `deprecated` change type', () => {
221226
const provide = provideFactory({
222227
[identifier]: {
223228
change: ChangeTypes.deprecated,
@@ -234,11 +239,11 @@ describe('Declaration', () => {
234239

235240
expect(wrapper.find(DeclarationDiff).exists()).toBe(false);
236241

237-
const declarationGroup = wrapper.find(DeclarationGroup);
238-
expect(declarationGroup.props('changeType')).toBe(ChangeTypes.deprecated);
239-
expect(declarationGroup.props('declaration')).toBe(propsData.declarations[0]);
240-
expect(declarationGroup.classes()).toContain('changed');
241-
expect(declarationGroup.classes()).toContain('changed-deprecated');
242+
const declarationList = wrapper.find(DeclarationList);
243+
expect(declarationList.props('changeType')).toBe(ChangeTypes.deprecated);
244+
expect(declarationList.props('declaration')).toBe(propsData.declarations[0]);
245+
expect(declarationList.classes()).toContain('changed');
246+
expect(declarationList.classes()).toContain('changed-deprecated');
242247
});
243248

244249
it('applies only `added` type change class if no declarations are present in the diff ', () => {
@@ -255,10 +260,10 @@ describe('Declaration', () => {
255260

256261
expect(wrapper.find(DeclarationDiff).exists()).toBe(false);
257262

258-
const declarationGroup = wrapper.find(DeclarationGroup);
259-
expect(declarationGroup.props('changeType')).toBe(ChangeTypes.added);
260-
expect(declarationGroup.props('declaration')).toBe(propsData.declarations[0]);
261-
expect(declarationGroup.classes()).toContain('changed');
262-
expect(declarationGroup.classes()).toContain('changed-added');
263+
const declarationList = wrapper.find(DeclarationList);
264+
expect(declarationList.props('changeType')).toBe(ChangeTypes.added);
265+
expect(declarationList.props('declaration')).toBe(propsData.declarations[0]);
266+
expect(declarationList.classes()).toContain('changed');
267+
expect(declarationList.classes()).toContain('changed-added');
263268
});
264269
});

tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationDiff.spec.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import DeclarationDiff from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationDiff.vue';
1212
import { shallowMount } from '@vue/test-utils';
13-
import DeclarationGroup from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationGroup.vue';
13+
import DeclarationList from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationList.vue';
1414

1515
const propsData = {
1616
changeType: 'modified',
@@ -24,7 +24,7 @@ const propsData = {
2424
};
2525

2626
describe('DeclarationDiff', () => {
27-
it('renders a current and previous DeclarationGroup components', () => {
27+
it('renders a current and previous DeclarationList components', () => {
2828
const wrapper = shallowMount(DeclarationDiff, {
2929
propsData,
3030
});
@@ -33,26 +33,26 @@ describe('DeclarationDiff', () => {
3333
expect(labels.at(0).text()).toEqual('Current');
3434
expect(labels.at(1).text()).toEqual('Previous');
3535

36-
const currentGroups = wrapper.find('.declaration-diff-current').findAll(DeclarationGroup);
36+
const currentLists = wrapper.find('.declaration-diff-current').findAll(DeclarationList);
3737

38-
expect(currentGroups).toHaveLength(2);
39-
expect(currentGroups.at(0).props()).toEqual({
38+
expect(currentLists).toHaveLength(2);
39+
expect(currentLists.at(0).props()).toEqual({
4040
declaration: propsData.changes.declaration.new[0],
4141
shouldCaption: true,
4242
changeType: 'modified',
4343
declListExpanded: false,
4444
});
45-
expect(currentGroups.at(1).props()).toEqual({
45+
expect(currentLists.at(1).props()).toEqual({
4646
declaration: propsData.changes.declaration.new[1],
4747
shouldCaption: true,
4848
changeType: 'modified',
4949
declListExpanded: false,
5050
});
5151

52-
const previousGroups = wrapper.find('.declaration-diff-previous').findAll(DeclarationGroup);
52+
const previousLists = wrapper.find('.declaration-diff-previous').findAll(DeclarationList);
5353

54-
expect(previousGroups).toHaveLength(1);
55-
expect(previousGroups.at(0).props()).toEqual({
54+
expect(previousLists).toHaveLength(1);
55+
expect(previousLists.at(0).props()).toEqual({
5656
declaration: propsData.changes.declaration.previous[0],
5757
shouldCaption: false, // false because we only have one declaration in the group
5858
changeType: 'modified',

tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationGroup.spec.js renamed to tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationList.spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import DeclarationGroup from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationGroup.vue';
11+
import DeclarationList from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationList.vue';
1212
import { shallowMount } from '@vue/test-utils';
1313
import DeclarationSource
1414
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationSource.vue';
@@ -79,13 +79,13 @@ const provide = {
7979
store,
8080
};
8181

82-
const createWrapper = options => shallowMount(DeclarationGroup, {
82+
const createWrapper = options => shallowMount(DeclarationList, {
8383
propsData,
8484
provide,
8585
...options,
8686
});
8787

88-
describe('DeclarationGroup', () => {
88+
describe('DeclarationList', () => {
8989
it('renders a platforms label for each variant', () => {
9090
const wrapper = createWrapper();
9191

@@ -131,9 +131,9 @@ describe('DeclarationGroup', () => {
131131

132132
it('applies the `multipleLinesClass` class if `displaysMultipleLinesAfterAPIChanges` is true', () => {
133133
const wrapper = shallowMount({
134-
...DeclarationGroup,
134+
...DeclarationList,
135135
computed: {
136-
...DeclarationGroup.computed,
136+
...DeclarationList.computed,
137137
displaysMultipleLinesAfterAPIChanges: () => true,
138138
},
139139
},
@@ -146,7 +146,7 @@ describe('DeclarationGroup', () => {
146146
});
147147
});
148148

149-
describe('DeclarationGroup with otherDeclarations', () => {
149+
describe('DeclarationList with otherDeclarations', () => {
150150
let wrapper;
151151

152152
beforeEach(() => {

0 commit comments

Comments
 (0)