debian-mirror-gitlab/spec/javascripts/notes/components/note_header_spec.js

115 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
import noteHeader from '~/notes/components/note_header.vue';
import store from '~/notes/stores';
describe('note_header component', () => {
let vm;
let Component;
beforeEach(() => {
Component = Vue.extend(noteHeader);
});
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,
2018-03-27 19:54:05 +05:30
expanded: true,
2018-03-17 18:26:18 +05:30
},
}).$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');
});
it('should render timestamp link', () => {
expect(vm.$el.querySelector('a[href="#note_1394"]')).toBeDefined();
});
});
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,
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-03-27 19:54:05 +05:30
it('emits toggle event on click', (done) => {
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();
});
});
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;
2018-03-17 18:26:18 +05:30
Vue.nextTick(() => {
expect(
2018-03-27 19:54:05 +05:30
vm.$el.querySelector('.js-vue-toggle-button i').classList,
).toContain('fa-chevron-down');
2018-03-17 18:26:18 +05:30
done();
});
});
});
});