2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import noteHeader from '~/notes/components/note_header.vue';
|
2018-11-08 19:23:39 +05:30
|
|
|
import createStore from '~/notes/stores';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('note_header component', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
let store;
|
2018-03-17 18:26:18 +05:30
|
|
|
let vm;
|
|
|
|
let Component;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Component = Vue.extend(noteHeader);
|
2018-11-08 19:23:39 +05:30
|
|
|
store = createStore();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2018-11-20 20:47:30 +05:30
|
|
|
noteId: '1394',
|
2018-03-27 19:54:05 +05:30
|
|
|
expanded: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render user information', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.$el.querySelector('.note-header-author-name').textContent.trim()).toEqual('Root');
|
|
|
|
expect(vm.$el.querySelector('.note-header-info a').getAttribute('href')).toEqual('/root');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render timestamp link', () => {
|
|
|
|
expect(vm.$el.querySelector('a[href="#note_1394"]')).toBeDefined();
|
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2018-11-20 20:47:30 +05:30
|
|
|
noteId: '1395',
|
2018-03-27 19:54:05 +05:30
|
|
|
expanded: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render toggle button', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-vue-toggle-button')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('emits toggle event on click', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
spyOn(vm, '$emit');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
vm.$el.querySelector('.js-vue-toggle-button').click();
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$emit).toHaveBeenCalledWith('toggleHandler');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('renders up arrow when open', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.expanded = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.$el.querySelector('.js-vue-toggle-button i').classList).toContain(
|
|
|
|
'fa-chevron-up',
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('renders down arrow when closed', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.expanded = false;
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
Vue.nextTick(() => {
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.$el.querySelector('.js-vue-toggle-button i').classList).toContain(
|
|
|
|
'fa-chevron-down',
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|