Added a bunch of specs for the different components
This commit is contained in:
parent
5a5b06de3e
commit
3313df580c
4 changed files with 193 additions and 28 deletions
|
@ -57,17 +57,17 @@
|
|||
},
|
||||
taskStatus() {
|
||||
const taskRegexMatches = this.taskStatus.match(/(\d+) of (\d+)/);
|
||||
const $issueableHeader = $('.issuable-meta');
|
||||
let $tasks = $('#task_status');
|
||||
let $tasksShort = $('#task_status_short');
|
||||
const $issuableHeader = $('.issuable-meta');
|
||||
let $tasks = $('#task_status', $issuableHeader);
|
||||
let $tasksShort = $('#task_status_short', $issuableHeader);
|
||||
|
||||
if (this.taskStatus.indexOf('0 of 0') >= 0 || this.taskStatus.trim() === '') {
|
||||
$tasks.remove();
|
||||
$tasksShort.remove();
|
||||
} else if (!$tasks.length && !$tasksShort.length) {
|
||||
$tasks = $issueableHeader.append('<span id="task_status" class="hidden-xs hidden-sm"></span>')
|
||||
$tasks = $issuableHeader.append('<span id="task_status" class="hidden-xs hidden-sm"></span>')
|
||||
.find('#task_status');
|
||||
$tasksShort = $issueableHeader.append('<span id="task_status_short" class="hidden-md hidden-lg"></span>')
|
||||
$tasksShort = $issuableHeader.append('<span id="task_status_short" class="hidden-md hidden-lg"></span>')
|
||||
.find('#task_status_short');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
import Vue from 'vue';
|
||||
import $ from 'jquery';
|
||||
import '~/render_math';
|
||||
import '~/render_gfm';
|
||||
import issueTitleDescription from '~/issue_show/issue_title_description.vue';
|
||||
import issueShowData from './mock_data';
|
||||
|
||||
window.$ = $;
|
||||
import issuableApp from '~/issue_show/components/app.vue';
|
||||
import issueShowData from '../mock_data';
|
||||
|
||||
const issueShowInterceptor = data => (request, next) => {
|
||||
next(request.respondWith(JSON.stringify(data), {
|
||||
|
@ -16,13 +13,25 @@ const issueShowInterceptor = data => (request, next) => {
|
|||
}));
|
||||
};
|
||||
|
||||
describe('Issue Title', () => {
|
||||
describe('Issuable output', () => {
|
||||
document.body.innerHTML = '<span id="task_status"></span>';
|
||||
|
||||
let IssueTitleDescriptionComponent;
|
||||
let vm;
|
||||
|
||||
beforeEach(() => {
|
||||
IssueTitleDescriptionComponent = Vue.extend(issueTitleDescription);
|
||||
const IssuableDescriptionComponent = Vue.extend(issuableApp);
|
||||
Vue.http.interceptors.push(issueShowInterceptor(issueShowData.initialRequest));
|
||||
|
||||
vm = new IssuableDescriptionComponent({
|
||||
propsData: {
|
||||
canUpdate: true,
|
||||
endpoint: '/gitlab-org/gitlab-shell/issues/9/rendered_title',
|
||||
issuableRef: '#1',
|
||||
initialTitle: '',
|
||||
initialDescriptionHtml: '',
|
||||
initialDescriptionText: '',
|
||||
},
|
||||
}).$mount();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -30,28 +39,19 @@ describe('Issue Title', () => {
|
|||
});
|
||||
|
||||
it('should render a title/description and update title/description on update', (done) => {
|
||||
Vue.http.interceptors.push(issueShowInterceptor(issueShowData.initialRequest));
|
||||
|
||||
const issueShowComponent = new IssueTitleDescriptionComponent({
|
||||
propsData: {
|
||||
canUpdateIssue: '.css-stuff',
|
||||
endpoint: '/gitlab-org/gitlab-shell/issues/9/rendered_title',
|
||||
},
|
||||
}).$mount();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(document.querySelector('title').innerText).toContain('this is a title (#1)');
|
||||
expect(issueShowComponent.$el.querySelector('.title').innerHTML).toContain('<p>this is a title</p>');
|
||||
expect(issueShowComponent.$el.querySelector('.wiki').innerHTML).toContain('<p>this is a description!</p>');
|
||||
expect(issueShowComponent.$el.querySelector('.js-task-list-field').innerText).toContain('this is a description');
|
||||
expect(vm.$el.querySelector('.title').innerHTML).toContain('<p>this is a title</p>');
|
||||
expect(vm.$el.querySelector('.wiki').innerHTML).toContain('<p>this is a description!</p>');
|
||||
expect(vm.$el.querySelector('.js-task-list-field').innerText).toContain('this is a description');
|
||||
|
||||
Vue.http.interceptors.push(issueShowInterceptor(issueShowData.secondRequest));
|
||||
|
||||
setTimeout(() => {
|
||||
expect(document.querySelector('title').innerText).toContain('2 (#1)');
|
||||
expect(issueShowComponent.$el.querySelector('.title').innerHTML).toContain('<p>2</p>');
|
||||
expect(issueShowComponent.$el.querySelector('.wiki').innerHTML).toContain('<p>42</p>');
|
||||
expect(issueShowComponent.$el.querySelector('.js-task-list-field').innerText).toContain('42');
|
||||
expect(vm.$el.querySelector('.title').innerHTML).toContain('<p>2</p>');
|
||||
expect(vm.$el.querySelector('.wiki').innerHTML).toContain('<p>42</p>');
|
||||
expect(vm.$el.querySelector('.js-task-list-field').innerText).toContain('42');
|
||||
|
||||
done();
|
||||
});
|
98
spec/javascripts/issue_show/components/description_spec.js
Normal file
98
spec/javascripts/issue_show/components/description_spec.js
Normal file
|
@ -0,0 +1,98 @@
|
|||
import Vue from 'vue';
|
||||
import descriptionComponent from '~/issue_show/components/description.vue';
|
||||
|
||||
describe('Description component', () => {
|
||||
let vm;
|
||||
|
||||
beforeEach(() => {
|
||||
const Component = Vue.extend(descriptionComponent);
|
||||
|
||||
if (!document.querySelector('.issuable-meta')) {
|
||||
const metaData = document.createElement('div');
|
||||
metaData.classList.add('issuable-meta');
|
||||
|
||||
document.body.appendChild(metaData);
|
||||
}
|
||||
|
||||
vm = new Component({
|
||||
propsData: {
|
||||
canUpdate: true,
|
||||
descriptionHtml: 'test',
|
||||
descriptionText: 'test',
|
||||
updatedAt: new Date().toString(),
|
||||
taskStatus: '',
|
||||
},
|
||||
}).$mount();
|
||||
});
|
||||
|
||||
it('animates description changes', (done) => {
|
||||
vm.descriptionHtml = 'changed';
|
||||
|
||||
Vue.nextTick(() => {
|
||||
expect(
|
||||
vm.$el.querySelector('.wiki').classList.contains('issue-realtime-pre-pulse'),
|
||||
).toBeTruthy();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(
|
||||
vm.$el.querySelector('.wiki').classList.contains('issue-realtime-trigger-pulse'),
|
||||
).toBeTruthy();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('re-inits the TaskList when description changed', (done) => {
|
||||
spyOn(gl, 'TaskList');
|
||||
vm.descriptionHtml = 'changed';
|
||||
|
||||
setTimeout(() => {
|
||||
expect(
|
||||
gl.TaskList,
|
||||
).toHaveBeenCalled();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('does not re-init the TaskList when canUpdate is false', (done) => {
|
||||
spyOn(gl, 'TaskList');
|
||||
vm.canUpdate = false;
|
||||
vm.descriptionHtml = 'changed';
|
||||
|
||||
setTimeout(() => {
|
||||
expect(
|
||||
gl.TaskList,
|
||||
).not.toHaveBeenCalled();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('taskStatus', () => {
|
||||
it('adds full taskStatus', (done) => {
|
||||
vm.taskStatus = '1 of 1';
|
||||
|
||||
setTimeout(() => {
|
||||
expect(
|
||||
document.querySelector('.issuable-meta #task_status').textContent.trim(),
|
||||
).toBe('1 of 1');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('adds short taskStatus', (done) => {
|
||||
vm.taskStatus = '1 of 1';
|
||||
|
||||
setTimeout(() => {
|
||||
expect(
|
||||
document.querySelector('.issuable-meta #task_status_short').textContent.trim(),
|
||||
).toBe('1/1 task');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
67
spec/javascripts/issue_show/components/title_spec.js
Normal file
67
spec/javascripts/issue_show/components/title_spec.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
import Vue from 'vue';
|
||||
import titleComponent from '~/issue_show/components/title.vue';
|
||||
|
||||
describe('Title component', () => {
|
||||
let vm;
|
||||
|
||||
beforeEach(() => {
|
||||
const Component = Vue.extend(titleComponent);
|
||||
vm = new Component({
|
||||
propsData: {
|
||||
issuableRef: '#1',
|
||||
titleHtml: 'Testing <img />',
|
||||
titleText: 'Testing',
|
||||
},
|
||||
}).$mount();
|
||||
});
|
||||
|
||||
it('renders title HTML', () => {
|
||||
expect(
|
||||
vm.$el.innerHTML.trim(),
|
||||
).toBe('Testing <img>');
|
||||
});
|
||||
|
||||
it('updates page title when changing titleHtml', (done) => {
|
||||
spyOn(vm, 'setPageTitle');
|
||||
vm.titleHtml = 'test';
|
||||
|
||||
Vue.nextTick(() => {
|
||||
expect(
|
||||
vm.setPageTitle,
|
||||
).toHaveBeenCalled();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('animates title changes', (done) => {
|
||||
vm.titleHtml = 'test';
|
||||
|
||||
Vue.nextTick(() => {
|
||||
expect(
|
||||
vm.$el.classList.contains('issue-realtime-pre-pulse'),
|
||||
).toBeTruthy();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(
|
||||
vm.$el.classList.contains('issue-realtime-trigger-pulse'),
|
||||
).toBeTruthy();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('updates page title after changing title', (done) => {
|
||||
vm.titleHtml = 'changed';
|
||||
vm.titleText = 'changed';
|
||||
|
||||
Vue.nextTick(() => {
|
||||
expect(
|
||||
document.querySelector('title').textContent.trim(),
|
||||
).toContain('changed');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue