2017-05-04 08:11:15 -04:00
|
|
|
/* global ListAssignee */
|
2017-01-26 07:55:08 -05:00
|
|
|
/* global ListLabel */
|
|
|
|
/* global ListIssue */
|
|
|
|
|
2017-03-17 13:21:25 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
2018-03-05 07:35:58 -05:00
|
|
|
import '~/vue_shared/models/label';
|
2018-06-07 16:54:24 -04:00
|
|
|
import '~/vue_shared/models/assignee';
|
2017-05-04 08:11:15 -04:00
|
|
|
import '~/boards/models/issue';
|
|
|
|
import '~/boards/models/list';
|
|
|
|
import '~/boards/stores/boards_store';
|
2018-06-26 08:29:06 -04:00
|
|
|
import IssueCardInner from '~/boards/components/issue_card_inner.vue';
|
2017-12-15 03:31:14 -05:00
|
|
|
import { listObj } from './mock_data';
|
2017-01-26 07:55:08 -05:00
|
|
|
|
|
|
|
describe('Issue card component', () => {
|
2017-05-04 08:11:15 -04:00
|
|
|
const user = new ListAssignee({
|
2017-01-26 07:55:08 -05:00
|
|
|
id: 1,
|
|
|
|
name: 'testing 123',
|
|
|
|
username: 'test',
|
|
|
|
avatar: 'test_image',
|
|
|
|
});
|
|
|
|
const label1 = new ListLabel({
|
|
|
|
id: 3,
|
|
|
|
title: 'testing 123',
|
|
|
|
color: 'blue',
|
|
|
|
text_color: 'white',
|
|
|
|
description: 'test',
|
|
|
|
});
|
|
|
|
let component;
|
|
|
|
let issue;
|
|
|
|
let list;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures('<div class="test-container"></div>');
|
|
|
|
|
|
|
|
list = listObj;
|
|
|
|
issue = new ListIssue({
|
|
|
|
title: 'Testing',
|
2017-09-06 02:49:19 -04:00
|
|
|
id: 1,
|
2017-01-26 07:55:08 -05:00
|
|
|
iid: 1,
|
|
|
|
confidential: false,
|
|
|
|
labels: [list.label],
|
2017-05-04 08:11:15 -04:00
|
|
|
assignees: [],
|
2018-04-05 11:28:49 -04:00
|
|
|
reference_path: '#1',
|
2018-04-05 13:57:48 -04:00
|
|
|
real_path: '/test/1',
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
component = new Vue({
|
|
|
|
el: document.querySelector('.test-container'),
|
2018-01-03 18:14:55 -05:00
|
|
|
components: {
|
2018-06-26 08:29:06 -04:00
|
|
|
'issue-card': IssueCardInner,
|
2018-01-03 18:14:55 -05:00
|
|
|
},
|
2017-01-26 07:55:08 -05:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
list,
|
|
|
|
issue,
|
|
|
|
issueLinkBase: '/test',
|
2017-01-31 06:54:04 -05:00
|
|
|
rootPath: '/',
|
2017-01-26 07:55:08 -05:00
|
|
|
};
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<issue-card
|
|
|
|
:issue="issue"
|
|
|
|
:list="list"
|
2017-01-31 06:54:04 -05:00
|
|
|
:issue-link-base="issueLinkBase"
|
|
|
|
:root-path="rootPath"></issue-card>
|
2017-01-26 07:55:08 -05:00
|
|
|
`,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders issue title', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.board-card-title').textContent).toContain(issue.title);
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('includes issue base in link', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.board-card-title a').getAttribute('href')).toContain(
|
|
|
|
'/test',
|
|
|
|
);
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('includes issue title on link', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.board-card-title a').getAttribute('title')).toBe(
|
|
|
|
issue.title,
|
|
|
|
);
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render confidential icon', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.fa-eye-flash')).toBeNull();
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
2018-08-07 02:04:33 -04:00
|
|
|
it('renders confidential icon', done => {
|
2017-01-26 07:55:08 -05:00
|
|
|
component.issue.confidential = true;
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
Vue.nextTick(() => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.confidential-icon')).not.toBeNull();
|
2017-01-26 07:55:08 -05:00
|
|
|
done();
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders issue ID with #', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.board-card-number').textContent).toContain(`#${issue.id}`);
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('assignee', () => {
|
|
|
|
it('does not render assignee', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.board-card-assignee .avatar')).toBeNull();
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('exists', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
beforeEach(done => {
|
2017-05-04 08:11:15 -04:00
|
|
|
component.issue.assignees = [user];
|
2017-01-26 07:55:08 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
Vue.nextTick(() => done());
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders assignee', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.board-card-assignee .avatar')).not.toBeNull();
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets title', () => {
|
|
|
|
expect(
|
2018-08-07 02:04:33 -04:00
|
|
|
component.$el
|
|
|
|
.querySelector('.board-card-assignee img')
|
|
|
|
.getAttribute('data-original-title'),
|
2017-01-26 07:55:08 -05:00
|
|
|
).toContain(`Assigned to ${user.name}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets users path', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.board-card-assignee a').getAttribute('href')).toBe(
|
|
|
|
'/test',
|
|
|
|
);
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders avatar', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.board-card-assignee img')).not.toBeNull();
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
});
|
2017-05-04 11:33:25 -04:00
|
|
|
|
|
|
|
describe('assignee default avatar', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
beforeEach(done => {
|
|
|
|
component.issue.assignees = [
|
|
|
|
new ListAssignee(
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
name: 'testing 123',
|
|
|
|
username: 'test',
|
|
|
|
},
|
|
|
|
'default_avatar',
|
|
|
|
),
|
|
|
|
];
|
2017-05-04 11:33:25 -04:00
|
|
|
|
|
|
|
Vue.nextTick(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays defaults avatar if users avatar is null', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.board-card-assignee img')).not.toBeNull();
|
|
|
|
expect(component.$el.querySelector('.board-card-assignee img').getAttribute('src')).toBe(
|
|
|
|
'default_avatar?width=20',
|
|
|
|
);
|
2017-05-04 11:33:25 -04:00
|
|
|
});
|
|
|
|
});
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
describe('multiple assignees', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
beforeEach(done => {
|
2017-05-04 08:11:15 -04:00
|
|
|
component.issue.assignees = [
|
|
|
|
user,
|
|
|
|
new ListAssignee({
|
|
|
|
id: 2,
|
|
|
|
name: 'user2',
|
|
|
|
username: 'user2',
|
|
|
|
avatar: 'test_image',
|
|
|
|
}),
|
|
|
|
new ListAssignee({
|
|
|
|
id: 3,
|
|
|
|
name: 'user3',
|
|
|
|
username: 'user3',
|
|
|
|
avatar: 'test_image',
|
|
|
|
}),
|
|
|
|
new ListAssignee({
|
|
|
|
id: 4,
|
|
|
|
name: 'user4',
|
|
|
|
username: 'user4',
|
|
|
|
avatar: 'test_image',
|
2018-08-07 02:04:33 -04:00
|
|
|
}),
|
|
|
|
];
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
Vue.nextTick(() => done());
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders all four assignees', () => {
|
2018-04-13 16:27:10 -04:00
|
|
|
expect(component.$el.querySelectorAll('.board-card-assignee .avatar').length).toEqual(4);
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('more than four assignees', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
beforeEach(done => {
|
|
|
|
component.issue.assignees.push(
|
|
|
|
new ListAssignee({
|
|
|
|
id: 5,
|
|
|
|
name: 'user5',
|
|
|
|
username: 'user5',
|
|
|
|
avatar: 'test_image',
|
|
|
|
}),
|
|
|
|
);
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
Vue.nextTick(() => done());
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders more avatar counter', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.board-card-assignee .avatar-counter').innerText,
|
|
|
|
).toEqual('+2');
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders three assignees', () => {
|
2018-04-13 16:27:10 -04:00
|
|
|
expect(component.$el.querySelectorAll('.board-card-assignee .avatar').length).toEqual(3);
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
|
|
|
|
2018-08-07 02:04:33 -04:00
|
|
|
it('renders 99+ avatar counter', done => {
|
2017-05-04 08:11:15 -04:00
|
|
|
for (let i = 5; i < 104; i += 1) {
|
|
|
|
const u = new ListAssignee({
|
|
|
|
id: i,
|
|
|
|
name: 'name',
|
|
|
|
username: 'username',
|
|
|
|
avatar: 'test_image',
|
|
|
|
});
|
|
|
|
component.issue.assignees.push(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.board-card-assignee .avatar-counter').innerText,
|
|
|
|
).toEqual('99+');
|
2017-05-04 08:11:15 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-26 07:55:08 -05:00
|
|
|
describe('labels', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
beforeEach(done => {
|
2017-09-06 02:49:19 -04:00
|
|
|
component.issue.addLabel(label1);
|
2017-01-26 07:55:08 -05:00
|
|
|
|
2017-09-06 02:49:19 -04:00
|
|
|
Vue.nextTick(() => done());
|
|
|
|
});
|
2017-01-26 07:55:08 -05:00
|
|
|
|
2017-09-06 02:49:19 -04:00
|
|
|
it('renders list label', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelectorAll('.badge').length).toBe(2);
|
2017-09-06 02:49:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders label', () => {
|
|
|
|
const nodes = [];
|
2018-08-07 02:04:33 -04:00
|
|
|
component.$el.querySelectorAll('.badge').forEach(label => {
|
2018-06-27 10:10:50 -04:00
|
|
|
nodes.push(label.getAttribute('data-original-title'));
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(nodes.includes(label1.description)).toBe(true);
|
2017-09-06 02:49:19 -04:00
|
|
|
});
|
2017-08-07 21:52:18 -04:00
|
|
|
|
2017-09-06 02:49:19 -04:00
|
|
|
it('sets label description as title', () => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelector('.badge').getAttribute('data-original-title')).toContain(
|
|
|
|
label1.description,
|
|
|
|
);
|
2017-09-06 02:49:19 -04:00
|
|
|
});
|
2017-01-26 07:55:08 -05:00
|
|
|
|
2017-09-06 02:49:19 -04:00
|
|
|
it('sets background color of button', () => {
|
|
|
|
const nodes = [];
|
2018-08-07 02:04:33 -04:00
|
|
|
component.$el.querySelectorAll('.badge').forEach(label => {
|
2017-09-06 02:49:19 -04:00
|
|
|
nodes.push(label.style.backgroundColor);
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(nodes.includes(label1.color)).toBe(true);
|
2017-09-06 02:49:19 -04:00
|
|
|
});
|
2017-08-07 21:52:18 -04:00
|
|
|
|
2018-08-07 02:04:33 -04:00
|
|
|
it('does not render label if label does not have an ID', done => {
|
|
|
|
component.issue.addLabel(
|
|
|
|
new ListLabel({
|
|
|
|
title: 'closed',
|
|
|
|
}),
|
|
|
|
);
|
2017-08-18 05:57:02 -04:00
|
|
|
|
2017-09-06 02:49:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
2018-08-07 02:04:33 -04:00
|
|
|
expect(component.$el.querySelectorAll('.badge').length).toBe(2);
|
|
|
|
expect(component.$el.textContent).not.toContain('closed');
|
2017-08-18 05:57:02 -04:00
|
|
|
|
2017-09-06 02:49:19 -04:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
2017-01-26 07:55:08 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|