Skip to content

Commit ab03e80

Browse files
author
Dobromir Hristov
committed
refactor: topicLink text
1 parent a66ef9f commit ab03e80

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/components/DocumentationTopic/TopicsLinkCardGridItem.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
:content="compact ? []: item.abstract"
1818
floating-style
1919
:size="compact ? undefined: 'large'"
20-
:link-text="compact? '': 'Visit page'"
20+
:link-text="compact? '': linkText"
2121
>
2222
<template #cover="{ classes }" v-if="!imageReferences.card">
2323
<div :class="classes" class="reference-card-grid-item__image">
@@ -34,6 +34,14 @@
3434
<script>
3535
import Card from 'docc-render/components/Card.vue';
3636
import TopicTypeIcon from 'docc-render/components/TopicTypeIcon.vue';
37+
import { TopicRole } from '@/constants/roles';
38+
39+
export const ROLE_LINK_TEXT = {
40+
[TopicRole.article]: 'Read Article',
41+
[TopicRole.overview]: 'Start Tutorial',
42+
[TopicRole.collection]: 'View API Collection',
43+
[TopicRole.symbol]: 'View Symbol',
44+
};
3745
3846
export default {
3947
name: 'TopicsLinkCardGridItem',
@@ -55,6 +63,7 @@ export default {
5563
all[current.type] = current.reference;
5664
return all;
5765
}, { icon: null, card: null }),
66+
linkText: ({ item }) => ROLE_LINK_TEXT[item.role] || 'Learn more',
5867
},
5968
};
6069
</script>

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
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';
1313
import { TopicRole } from '@/constants/roles';
1414
import TopicTypeIcon from '@/components/TopicTypeIcon.vue';
15-
import TopicsLinkCardGridItem from '@/components/DocumentationTopic/TopicsLinkCardGridItem.vue';
15+
import TopicsLinkCardGridItem, {
16+
ROLE_LINK_TEXT,
17+
} from '@/components/DocumentationTopic/TopicsLinkCardGridItem.vue';
1618

1719
const defaultProps = {
1820
item: {
@@ -118,7 +120,29 @@ describe('TopicsLinkCardGridItem', () => {
118120
content: defaultProps.item.abstract,
119121
floatingStyle: true,
120122
size: 'large',
121-
linkText: 'Visit page',
123+
linkText: ROLE_LINK_TEXT[TopicRole.article],
122124
});
123125
});
126+
127+
it('renders different text for diff roles', () => {
128+
const wrapper = createWrapper({
129+
propsData: {
130+
...defaultProps,
131+
compact: false,
132+
item: { ...defaultProps.item, role: TopicRole.overview },
133+
},
134+
});
135+
// overview
136+
const card = wrapper.find(Card);
137+
expect(card.props('linkText')).toBe(ROLE_LINK_TEXT[TopicRole.overview]);
138+
// collection
139+
wrapper.setProps({ item: { ...defaultProps.item, role: TopicRole.collection } });
140+
expect(card.props('linkText')).toBe(ROLE_LINK_TEXT[TopicRole.collection]);
141+
// symbol
142+
wrapper.setProps({ item: { ...defaultProps.item, role: TopicRole.symbol } });
143+
expect(card.props('linkText')).toBe(ROLE_LINK_TEXT[TopicRole.symbol]);
144+
// other
145+
wrapper.setProps({ item: { ...defaultProps.item, role: TopicRole.link } });
146+
expect(card.props('linkText')).toBe('Learn more');
147+
});
124148
});

0 commit comments

Comments
 (0)