Skip to content

Commit 3d7130e

Browse files
author
Dobromir Hristov
committed
refactor: extract title class to a constant
1 parent 46a2da5 commit 3d7130e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/components/DocumentationTopic/ContentTableSection.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
3232
import { anchorize } from 'docc-render/utils/strings';
3333
34+
export const TITLE_CLASS_NAME = 'contenttable-title';
35+
3436
export default {
3537
name: 'ContentTableSection',
3638
components: { LinkableHeading },
@@ -46,7 +48,7 @@ export default {
4648
},
4749
computed: {
4850
anchorComputed: ({ title, anchor }) => anchor || anchorize(title),
49-
className: () => 'contenttable-title',
51+
className: () => TITLE_CLASS_NAME,
5052
},
5153
};
5254
</script>

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
*/
1010

1111
import { shallowMount } from '@vue/test-utils';
12-
import ContentTableSection from 'docc-render/components/DocumentationTopic/ContentTableSection.vue';
12+
import ContentTableSection, {
13+
TITLE_CLASS_NAME,
14+
} from 'docc-render/components/DocumentationTopic/ContentTableSection.vue';
1315

1416
const {
1517
LinkableHeading,
@@ -33,12 +35,12 @@ describe('ContentTableSection', () => {
3335
const title = div.find(LinkableHeading);
3436
expect(title.exists()).toBe(true);
3537
expect(title.props('level')).toBe(3);
36-
expect(title.classes()).toContain('contenttable-title');
38+
expect(title.classes()).toContain(TITLE_CLASS_NAME);
3739
expect(title.text()).toContain(propsData.title);
3840
});
3941

4042
it('renders an `id` if `anchor` is provided', () => {
41-
const title = wrapper.find('.title');
43+
const title = wrapper.find(`.${TITLE_CLASS_NAME}`);
4244
expect(title.attributes('id')).toBe(undefined);
4345
wrapper.setProps({
4446
anchor: 'foo-bar',
@@ -54,7 +56,7 @@ describe('ContentTableSection', () => {
5456
},
5557
});
5658
const div = wrapper.find('.section-title');
57-
const title = div.find('.contenttable-title');
59+
const title = div.find(`.${TITLE_CLASS_NAME}`);
5860
expect(title.text()).toEqual('Title Text');
5961
});
6062

0 commit comments

Comments
 (0)