blob: 8b0daf2fe2f5135b5d6798291205571f8301f328 (
plain)
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
|
import { mount } from '@vue/test-utils';
import noSavedRepliesResponse from 'test_fixtures/graphql/comment_templates/saved_replies_empty.query.graphql.json';
import savedRepliesResponse from 'test_fixtures/graphql/comment_templates/saved_replies.query.graphql.json';
import List from '~/comment_templates/components/list.vue';
import ListItem from '~/comment_templates/components/list_item.vue';
let wrapper;
function createComponent(res = {}) {
const { savedReplies } = res.data.currentUser;
return mount(List, {
propsData: {
savedReplies: savedReplies.nodes,
pageInfo: savedReplies.pageInfo,
count: savedReplies.count,
},
});
}
describe('Comment templates list component', () => {
it('does not render any list items when response is empty', () => {
wrapper = createComponent(noSavedRepliesResponse);
expect(wrapper.findAllComponents(ListItem).length).toBe(0);
});
it('render comment templates count', () => {
wrapper = createComponent(savedRepliesResponse);
expect(wrapper.find('[data-testid="title"]').text()).toEqual('My comment templates (2)');
});
it('renders list of comment templates', () => {
const savedReplies = savedRepliesResponse.data.currentUser.savedReplies.nodes;
wrapper = createComponent(savedRepliesResponse);
expect(wrapper.findAllComponents(ListItem).length).toBe(2);
expect(wrapper.findAllComponents(ListItem).at(0).props('template')).toEqual(
expect.objectContaining(savedReplies[0]),
);
expect(wrapper.findAllComponents(ListItem).at(1).props('template')).toEqual(
expect.objectContaining(savedReplies[1]),
);
});
});
|