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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
import Vue from 'vue';
import noteHeader from '~/notes/components/note_header.vue';
import createStore from '~/notes/stores';
describe('note_header component', () => {
let store;
let vm;
let Component;
beforeEach(() => {
Component = Vue.extend(noteHeader);
store = createStore();
});
afterEach(() => {
vm.$destroy();
});
describe('individual note', () => {
beforeEach(() => {
vm = new Component({
store,
propsData: {
actionText: 'commented',
actionTextHtml: '',
author: {
avatar_url: null,
id: 1,
name: 'Root',
path: '/root',
state: 'active',
username: 'root',
},
createdAt: '2017-08-02T10:51:58.559Z',
includeToggle: false,
noteId: '1394',
expanded: true,
},
}).$mount();
});
it('should render user information', () => {
expect(vm.$el.querySelector('.note-header-author-name').textContent.trim()).toEqual('Root');
expect(vm.$el.querySelector('.note-header-info a').getAttribute('href')).toEqual('/root');
expect(vm.$el.querySelector('.note-header-info a').dataset.userId).toEqual('1');
expect(vm.$el.querySelector('.note-header-info a').dataset.username).toEqual('root');
expect(vm.$el.querySelector('.note-header-info a').classList).toContain('js-user-link');
});
it('should render timestamp link', () => {
expect(vm.$el.querySelector('a[href="#note_1394"]')).toBeDefined();
});
it('should not render user information when prop `author` is empty object', done => {
vm.author = {};
Vue.nextTick()
.then(() => {
expect(vm.$el.querySelector('.note-header-author-name')).toBeNull();
})
.then(done)
.catch(done.fail);
});
});
describe('discussion', () => {
beforeEach(() => {
vm = new Component({
store,
propsData: {
actionText: 'started a discussion',
actionTextHtml: '',
author: {
avatar_url: null,
id: 1,
name: 'Root',
path: '/root',
state: 'active',
username: 'root',
},
createdAt: '2017-08-02T10:51:58.559Z',
includeToggle: true,
noteId: '1395',
expanded: true,
},
}).$mount();
});
it('should render toggle button', () => {
expect(vm.$el.querySelector('.js-vue-toggle-button')).toBeDefined();
});
it('emits toggle event on click', done => {
jest.spyOn(vm, '$emit').mockImplementation(() => {});
vm.$el.querySelector('.js-vue-toggle-button').click();
Vue.nextTick(() => {
expect(vm.$emit).toHaveBeenCalledWith('toggleHandler');
done();
});
});
it('renders up arrow when open', done => {
vm.expanded = true;
Vue.nextTick(() => {
expect(vm.$el.querySelector('.js-vue-toggle-button i').classList).toContain(
'fa-chevron-up',
);
done();
});
});
it('renders down arrow when closed', done => {
vm.expanded = false;
Vue.nextTick(() => {
expect(vm.$el.querySelector('.js-vue-toggle-button i').classList).toContain(
'fa-chevron-down',
);
done();
});
});
});
});
|