2017-08-17 22:00:37 +05:30
|
|
|
/* global List */
|
|
|
|
/* global ListIssue */
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
import Vue from 'vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2018-11-08 19:23:39 +05:30
|
|
|
import Sortable from 'sortablejs';
|
2018-03-17 18:26:18 +05:30
|
|
|
import BoardList from '~/boards/components/board_list.vue';
|
2017-08-17 22:00:37 +05:30
|
|
|
import eventHub from '~/boards/eventhub';
|
|
|
|
import '~/boards/models/issue';
|
|
|
|
import '~/boards/models/list';
|
2018-12-13 13:39:08 +05:30
|
|
|
import boardsStore from '~/boards/stores/boards_store';
|
2018-03-17 18:26:18 +05:30
|
|
|
import { listObj, boardsMockInterceptor, mockBoardService } from './mock_data';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
window.Sortable = Sortable;
|
|
|
|
|
|
|
|
describe('Board list component', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
let mock;
|
2017-08-17 22:00:37 +05:30
|
|
|
let component;
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
const el = document.createElement('div');
|
|
|
|
|
|
|
|
document.body.appendChild(el);
|
2018-03-17 18:26:18 +05:30
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onAny().reply(boardsMockInterceptor);
|
|
|
|
gl.boardService = mockBoardService();
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.create();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
const BoardListComp = Vue.extend(BoardList);
|
|
|
|
const list = new List(listObj);
|
|
|
|
const issue = new ListIssue({
|
|
|
|
title: 'Testing',
|
2018-03-17 18:26:18 +05:30
|
|
|
id: 1,
|
2017-08-17 22:00:37 +05:30
|
|
|
iid: 1,
|
|
|
|
confidential: false,
|
|
|
|
labels: [],
|
|
|
|
assignees: [],
|
|
|
|
});
|
|
|
|
list.issuesSize = 1;
|
|
|
|
list.issues.push(issue);
|
|
|
|
|
|
|
|
component = new BoardListComp({
|
|
|
|
el,
|
|
|
|
propsData: {
|
|
|
|
disabled: false,
|
|
|
|
list,
|
|
|
|
issues: list.issues,
|
|
|
|
loading: false,
|
|
|
|
issueLinkBase: '/issues',
|
|
|
|
rootPath: '/',
|
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
mock.restore();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders component', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.classList.contains('board-list-component')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('renders loading icon', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
component.loading = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-list-loading')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders issues', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelectorAll('.board-card').length).toBe(1);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('sets data attribute with issue id', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-card').getAttribute('data-issue-id')).toBe('1');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('shows new issue form', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
component.toggleForm();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.is-smaller')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('shows new issue form after eventhub event', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
eventHub.$emit(`hide-issue-form-${component.list.id}`);
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.is-smaller')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('does not show new issue form for closed list', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
component.list.type = 'closed';
|
|
|
|
component.toggleForm();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-new-issue-form')).toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('shows count list item', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
component.showCount = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-list-count')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe(
|
|
|
|
'Showing all issues',
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('sets data attribute with invalid id', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
component.showCount = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-list-count').getAttribute('data-issue-id')).toBe(
|
|
|
|
'-1',
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('shows how many more issues to load', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
component.showCount = true;
|
|
|
|
component.list.issuesSize = 20;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe(
|
|
|
|
'Showing 1 of 20 issues',
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('loads more issues after scrolling', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
spyOn(component.list, 'nextPage');
|
|
|
|
component.$refs.list.style.height = '100px';
|
|
|
|
component.$refs.list.style.overflow = 'scroll';
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
for (let i = 1; i < 20; i += 1) {
|
|
|
|
const issue = Object.assign({}, component.list.issues[0]);
|
|
|
|
issue.id += i;
|
2017-08-17 22:00:37 +05:30
|
|
|
component.list.issues.push(issue);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
component.$refs.list.scrollTop = 20000;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(component.list.nextPage).toHaveBeenCalled();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it('does not load issues if already loading', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
component.list.nextPage = spyOn(component.list, 'nextPage').and.returnValue(
|
|
|
|
new Promise(() => {}),
|
|
|
|
);
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
component.onScroll();
|
|
|
|
component.onScroll();
|
|
|
|
|
|
|
|
expect(component.list.nextPage).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('shows loading more spinner', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
component.showCount = true;
|
|
|
|
component.list.loadingMore = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(component.$el.querySelector('.board-list-count .fa-spinner')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|