Commit 3313df58 authored by Phil Hughes's avatar Phil Hughes

Added a bunch of specs for the different components

parent 5a5b06de
......@@ -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');
}
......
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,42 +13,45 @@ 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);
});
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, issueShowInterceptor);
});
it('should render a title/description and update title/description on update', (done) => {
const IssuableDescriptionComponent = Vue.extend(issuableApp);
Vue.http.interceptors.push(issueShowInterceptor(issueShowData.initialRequest));
const issueShowComponent = new IssueTitleDescriptionComponent({
vm = new IssuableDescriptionComponent({
propsData: {
canUpdateIssue: '.css-stuff',
canUpdate: true,
endpoint: '/gitlab-org/gitlab-shell/issues/9/rendered_title',
issuableRef: '#1',
initialTitle: '',
initialDescriptionHtml: '',
initialDescriptionText: '',
},
}).$mount();
});
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, issueShowInterceptor);
});
it('should render a title/description and update title/description on update', (done) => {
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();
});
......
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();
});
});
});
});
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();
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment