2017-03-28 05:31:16 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import eventHub from '~/boards/eventhub';
|
2019-04-19 00:43:51 -04:00
|
|
|
import createComponent from './board_list_common_spec';
|
2017-03-28 05:31:16 -04:00
|
|
|
|
|
|
|
describe('Board list component', () => {
|
2017-12-15 03:31:14 -05:00
|
|
|
let mock;
|
2017-03-28 05:31:16 -04:00
|
|
|
let component;
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
beforeEach(done => {
|
2019-04-19 00:43:51 -04:00
|
|
|
({ mock, component } = createComponent({ done }));
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-01-23 06:42:02 -05:00
|
|
|
mock.restore();
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders component', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.classList.contains('board-list-component')).toBe(true);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('renders loading icon', done => {
|
2017-03-28 05:31:16 -04:00
|
|
|
component.loading = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.board-list-loading')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders issues', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelectorAll('.board-card').length).toBe(1);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets data attribute with issue id', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.board-card').getAttribute('data-issue-id')).toBe('1');
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('shows new issue form', done => {
|
2017-03-28 05:31:16 -04:00
|
|
|
component.toggleForm();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.is-smaller')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('shows new issue form after eventhub event', done => {
|
2017-03-28 05:31:16 -04:00
|
|
|
eventHub.$emit(`hide-issue-form-${component.list.id}`);
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.is-smaller')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('does not show new issue form for closed list', done => {
|
2017-03-28 05:31:16 -04:00
|
|
|
component.list.type = 'closed';
|
|
|
|
component.toggleForm();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.board-new-issue-form')).toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('shows count list item', done => {
|
2017-03-28 05:31:16 -04:00
|
|
|
component.showCount = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.board-list-count')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe(
|
|
|
|
'Showing all issues',
|
|
|
|
);
|
2017-03-28 05:31:16 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('sets data attribute with invalid id', done => {
|
2018-01-09 04:24:08 -05:00
|
|
|
component.showCount = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.board-list-count').getAttribute('data-issue-id')).toBe(
|
|
|
|
'-1',
|
|
|
|
);
|
2018-01-09 04:24:08 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('shows how many more issues to load', done => {
|
2017-03-28 05:31:16 -04:00
|
|
|
component.showCount = true;
|
|
|
|
component.list.issuesSize = 20;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe(
|
|
|
|
'Showing 1 of 20 issues',
|
|
|
|
);
|
2017-03-28 05:31:16 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('loads more issues after scrolling', done => {
|
2017-03-28 05:31:16 -04:00
|
|
|
spyOn(component.list, 'nextPage');
|
|
|
|
component.$refs.list.style.height = '100px';
|
|
|
|
component.$refs.list.style.overflow = 'scroll';
|
|
|
|
|
2018-01-23 04:37:07 -05:00
|
|
|
for (let i = 1; i < 20; i += 1) {
|
|
|
|
const issue = Object.assign({}, component.list.issues[0]);
|
|
|
|
issue.id += i;
|
2017-03-28 05:31:16 -04:00
|
|
|
component.list.issues.push(issue);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
component.$refs.list.scrollTop = 20000;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(component.list.nextPage).toHaveBeenCalled();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-16 11:27:56 -04:00
|
|
|
it('does not load issues if already loading', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
component.list.nextPage = spyOn(component.list, 'nextPage').and.returnValue(
|
|
|
|
new Promise(() => {}),
|
|
|
|
);
|
2018-08-16 11:27:56 -04:00
|
|
|
|
|
|
|
component.onScroll();
|
|
|
|
component.onScroll();
|
|
|
|
|
|
|
|
expect(component.list.nextPage).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('shows loading more spinner', done => {
|
2017-03-28 05:31:16 -04:00
|
|
|
component.showCount = true;
|
|
|
|
component.list.loadingMore = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2019-03-18 08:09:07 -04:00
|
|
|
expect(component.$el.querySelector('.board-list-count .spinner')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|