Skip to content

Commit f3b9e44

Browse files
author
Dobromir Hristov
committed
refactor: use slot to provide content
1 parent e8f69a5 commit f3b9e44

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/components/DocumentationTopic/TopicsLinkCardGridItem.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
:url="item.url"
1515
:image="imageReferences.card"
1616
:title="item.title"
17-
:content="compact ? []: item.abstract"
1817
floating-style
1918
:size="compact ? undefined: 'large'"
2019
:link-text="compact? '': linkText"
@@ -28,6 +27,7 @@
2827
/>
2928
</div>
3029
</template>
30+
<ContentNode v-if="!compact" :content="item.abstract" />
3131
</Card>
3232
</template>
3333

@@ -46,7 +46,11 @@ export const ROLE_LINK_TEXT = {
4646

4747
export default {
4848
name: 'TopicsLinkCardGridItem',
49-
components: { TopicTypeIcon, Card },
49+
components: {
50+
TopicTypeIcon,
51+
Card,
52+
ContentNode: () => import('docc-render/components/ContentNode.vue'),
53+
},
5054
inject: ['references'],
5155
props: {
5256
item: {

tests/unit/components/DocumentationTopic/TopicsLinkCardGridItem.spec.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* See https://swift.org/LICENSE.txt for license information
88
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9-
*/
9+
*/
1010

1111
import { mount } from '@vue/test-utils';
1212
import Card from '@/components/Card.vue';
@@ -15,6 +15,7 @@ import TopicTypeIcon from '@/components/TopicTypeIcon.vue';
1515
import TopicsLinkCardGridItem, {
1616
ROLE_LINK_TEXT,
1717
} from '@/components/DocumentationTopic/TopicsLinkCardGridItem.vue';
18+
import ContentNode from 'docc-render/components/ContentNode.vue';
1819

1920
const defaultProps = {
2021
item: {
@@ -54,12 +55,12 @@ describe('TopicsLinkCardGridItem', () => {
5455
url: defaultProps.item.url,
5556
image: defaultProps.item.images[0].reference,
5657
title: defaultProps.item.title,
57-
content: [], // compact items do not have content
5858
floatingStyle: true,
5959
size: undefined,
6060
linkText: '',
6161
});
6262
expect(wrapper.find('.reference-card-grid-item__image').exists()).toBe(false);
63+
expect(wrapper.find(ContentNode).exists()).toBe(false);
6364
});
6465

6566
it('renders a TopicsLinkCardGridItem, with an icon as a fallback', () => {
@@ -76,11 +77,11 @@ describe('TopicsLinkCardGridItem', () => {
7677
url: defaultProps.item.url,
7778
image: null,
7879
title: defaultProps.item.title,
79-
content: [], // compact items do not have content
8080
floatingStyle: true,
8181
size: undefined,
8282
linkText: '',
8383
});
84+
expect(wrapper.find(ContentNode).exists()).toBe(false);
8485
const imageWrapper = wrapper.find('.reference-card-grid-item__image');
8586
expect(imageWrapper.exists()).toBe(true);
8687
const icon = imageWrapper.find(TopicTypeIcon);
@@ -106,22 +107,24 @@ describe('TopicsLinkCardGridItem', () => {
106107
expect(wrapper.find(TopicTypeIcon).props('imageOverride')).toEqual(iconRef);
107108
});
108109

109-
it('renders a TopicsLinkCardGridItem, in a none compact variant', () => {
110+
it('renders a TopicsLinkCardGridItem, in a none compact variant', async () => {
110111
const wrapper = createWrapper({
111112
propsData: {
112113
...defaultProps,
113114
compact: false,
114115
},
115116
});
116-
expect(wrapper.find(Card).props()).toMatchObject({
117+
await wrapper.vm.$nextTick();
118+
const card = wrapper.find(Card);
119+
expect(card.props()).toMatchObject({
117120
url: defaultProps.item.url,
118121
image: defaultProps.item.images[0].reference,
119122
title: defaultProps.item.title,
120-
content: defaultProps.item.abstract,
121123
floatingStyle: true,
122124
size: 'large',
123125
linkText: ROLE_LINK_TEXT[TopicRole.article],
124126
});
127+
expect(wrapper.find(ContentNode).props('content')).toBe(defaultProps.item.abstract);
125128
});
126129

127130
it('renders different text for diff roles', () => {

0 commit comments

Comments
 (0)