2019-11-12 10:06:26 -05:00
|
|
|
/* global List */
|
|
|
|
|
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';
|
2019-11-12 10:06:26 -05:00
|
|
|
import waitForPromises from '../helpers/wait_for_promises';
|
|
|
|
|
|
|
|
import '~/boards/models/list';
|
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;
|
2019-11-12 10:06:26 -05:00
|
|
|
let getIssues;
|
|
|
|
function generateIssues(compWrapper) {
|
|
|
|
for (let i = 1; i < 20; i += 1) {
|
|
|
|
const issue = Object.assign({}, compWrapper.list.issues[0]);
|
|
|
|
issue.id += i;
|
|
|
|
compWrapper.list.issues.push(issue);
|
|
|
|
}
|
|
|
|
}
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
describe('When Expanded', () => {
|
|
|
|
beforeEach(done => {
|
|
|
|
getIssues = spyOn(List.prototype, 'getIssues').and.returnValue(new Promise(() => {}));
|
|
|
|
({ mock, component } = createComponent({ done }));
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
component.$destroy();
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('loads first page of issues', done => {
|
|
|
|
waitForPromises()
|
|
|
|
.then(() => {
|
|
|
|
expect(getIssues).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('renders component', () => {
|
|
|
|
expect(component.$el.classList.contains('board-list-component')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders loading icon', done => {
|
|
|
|
component.loading = true;
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.board-list-loading')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
done();
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('renders issues', () => {
|
|
|
|
expect(component.$el.querySelectorAll('.board-card').length).toBe(1);
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('sets data attribute with issue id', () => {
|
|
|
|
expect(component.$el.querySelector('.board-card').getAttribute('data-issue-id')).toBe('1');
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('shows new issue form', done => {
|
|
|
|
component.toggleForm();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
expect(component.$el.querySelector('.is-smaller')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
done();
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('shows new issue form after eventhub event', done => {
|
|
|
|
eventHub.$emit(`hide-issue-form-${component.list.id}`);
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
expect(component.$el.querySelector('.is-smaller')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
done();
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('does not show new issue form for closed list', done => {
|
|
|
|
component.list.type = 'closed';
|
|
|
|
component.toggleForm();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.board-new-issue-form')).toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
done();
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('shows count list item', done => {
|
|
|
|
component.showCount = true;
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.board-list-count')).not.toBeNull();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe(
|
|
|
|
'Showing all issues',
|
|
|
|
);
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
done();
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('sets data attribute with invalid id', done => {
|
|
|
|
component.showCount = true;
|
2018-01-09 04:24:08 -05:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.board-list-count').getAttribute('data-issue-id')).toBe(
|
|
|
|
'-1',
|
|
|
|
);
|
2018-01-09 04:24:08 -05:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
done();
|
|
|
|
});
|
2018-01-09 04:24:08 -05:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('shows how many more issues to load', done => {
|
|
|
|
component.showCount = true;
|
|
|
|
component.list.issuesSize = 20;
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe(
|
|
|
|
'Showing 1 of 20 issues',
|
|
|
|
);
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
done();
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('loads more issues after scrolling', done => {
|
|
|
|
spyOn(component.list, 'nextPage');
|
|
|
|
component.$refs.list.style.height = '100px';
|
|
|
|
component.$refs.list.style.overflow = 'scroll';
|
|
|
|
generateIssues(component);
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
component.$refs.list.scrollTop = 20000;
|
|
|
|
|
|
|
|
waitForPromises()
|
|
|
|
.then(() => {
|
|
|
|
expect(component.list.nextPage).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('does not load issues if already loading', done => {
|
|
|
|
component.list.nextPage = spyOn(component.list, 'nextPage').and.returnValue(
|
|
|
|
new Promise(() => {}),
|
|
|
|
);
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
component.onScroll();
|
|
|
|
component.onScroll();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
waitForPromises()
|
|
|
|
.then(() => {
|
|
|
|
expect(component.list.nextPage).toHaveBeenCalledTimes(1);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('shows loading more spinner', done => {
|
|
|
|
component.showCount = true;
|
|
|
|
component.list.loadingMore = true;
|
2018-08-16 11:27:56 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.board-list-count .gl-spinner')).not.toBeNull();
|
2018-08-16 11:27:56 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-08-16 11:27:56 -04:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
describe('When Collapsed', () => {
|
|
|
|
beforeEach(done => {
|
|
|
|
getIssues = spyOn(List.prototype, 'getIssues').and.returnValue(new Promise(() => {}));
|
|
|
|
({ mock, component } = createComponent({
|
|
|
|
done,
|
|
|
|
listProps: { type: 'closed', collapsed: true, issuesSize: 50 },
|
|
|
|
}));
|
|
|
|
generateIssues(component);
|
|
|
|
component.scrollHeight = spyOn(component, 'scrollHeight').and.returnValue(0);
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
component.$destroy();
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('does not load all issues', done => {
|
|
|
|
waitForPromises()
|
|
|
|
.then(() => {
|
|
|
|
// Initial getIssues from list constructor
|
|
|
|
expect(getIssues).toHaveBeenCalledTimes(1);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
});
|
2019-11-21 01:06:32 -05:00
|
|
|
|
|
|
|
describe('max issue count warning', () => {
|
|
|
|
beforeEach(done => {
|
|
|
|
({ mock, component } = createComponent({
|
|
|
|
done,
|
|
|
|
listProps: { type: 'closed', collapsed: true, issuesSize: 50 },
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
component.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when issue count exceeds max issue count', () => {
|
|
|
|
it('sets background to bg-danger-100', done => {
|
|
|
|
component.list.issuesSize = 4;
|
|
|
|
component.list.maxIssueCount = 3;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.bg-danger-100')).not.toBeNull();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when list issue count does NOT exceed list max issue count', () => {
|
|
|
|
it('does not sets background to bg-danger-100', done => {
|
|
|
|
component.list.issuesSize = 2;
|
|
|
|
component.list.maxIssueCount = 3;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.bg-danger-100')).toBeNull();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when list max issue count is 0', () => {
|
|
|
|
it('does not sets background to bg-danger-100', done => {
|
|
|
|
component.list.maxIssueCount = 0;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('.bg-danger-100')).toBeNull();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|