2017-08-09 09:18:43 -04:00
|
|
|
import Vue from 'vue';
|
2017-12-04 11:19:07 -05:00
|
|
|
import noteHeader from '~/notes/components/note_header.vue';
|
2018-06-21 08:22:40 -04:00
|
|
|
import createStore from '~/notes/stores';
|
2017-08-09 09:18:43 -04:00
|
|
|
|
2017-12-04 11:19:07 -05:00
|
|
|
describe('note_header component', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
let store;
|
2017-08-09 09:18:43 -04:00
|
|
|
let vm;
|
|
|
|
let Component;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-12-04 11:19:07 -05:00
|
|
|
Component = Vue.extend(noteHeader);
|
2018-06-21 08:22:40 -04:00
|
|
|
store = createStore();
|
2017-08-09 09:18:43 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-09 09:18:43 -04:00
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2017-08-09 09:18:43 -04:00
|
|
|
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,
|
2018-02-27 19:10:43 -05:00
|
|
|
expanded: true,
|
2017-08-09 09:18:43 -04:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render user information', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(vm.$el.querySelector('.note-header-author-name').textContent.trim()).toEqual('Root');
|
|
|
|
expect(vm.$el.querySelector('.note-header-info a').getAttribute('href')).toEqual('/root');
|
2017-08-09 09:18:43 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-09 09:18:43 -04:00
|
|
|
it('should render timestamp link', () => {
|
|
|
|
expect(vm.$el.querySelector('a[href="#note_1394"]')).toBeDefined();
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('discussion', () => {
|
2017-08-09 09:18:43 -04:00
|
|
|
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,
|
2018-02-27 19:10:43 -05:00
|
|
|
expanded: true,
|
2017-08-09 09:18:43 -04:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
});
|
|
|
|
|
2017-08-04 11:51:35 -04:00
|
|
|
it('should render toggle button', () => {
|
2017-08-09 09:18:43 -04:00
|
|
|
expect(vm.$el.querySelector('.js-vue-toggle-button')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('emits toggle event on click', done => {
|
2018-02-27 19:10:43 -05:00
|
|
|
spyOn(vm, '$emit');
|
2017-08-09 09:18:43 -04:00
|
|
|
|
|
|
|
vm.$el.querySelector('.js-vue-toggle-button').click();
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-02-27 19:10:43 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$emit).toHaveBeenCalledWith('toggleHandler');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('renders up arrow when open', done => {
|
2018-02-27 19:10:43 -05:00
|
|
|
vm.expanded = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(vm.$el.querySelector('.js-vue-toggle-button i').classList).toContain(
|
|
|
|
'fa-chevron-up',
|
|
|
|
);
|
2018-02-27 19:10:43 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('renders down arrow when closed', done => {
|
2018-02-27 19:10:43 -05:00
|
|
|
vm.expanded = false;
|
|
|
|
|
2017-08-09 09:18:43 -04:00
|
|
|
Vue.nextTick(() => {
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(vm.$el.querySelector('.js-vue-toggle-button i').classList).toContain(
|
|
|
|
'fa-chevron-down',
|
|
|
|
);
|
2017-08-09 09:18:43 -04:00
|
|
|
done();
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
2017-08-09 09:18:43 -04:00
|
|
|
});
|