Commit 7075970b authored by Florie Guibert's avatar Florie Guibert Committed by Natalia Tepluhina

Fix loading all issues when board list is collapsed

parent e345f835
...@@ -84,7 +84,8 @@ export default { ...@@ -84,7 +84,8 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
if ( if (
this.scrollHeight() <= this.listHeight() && this.scrollHeight() <= this.listHeight() &&
this.list.issuesSize > this.list.issues.length this.list.issuesSize > this.list.issues.length &&
this.list.isExpanded
) { ) {
this.list.page += 1; this.list.page += 1;
this.list.getIssues(false).catch(() => { this.list.getIssues(false).catch(() => {
......
...@@ -50,8 +50,8 @@ class List { ...@@ -50,8 +50,8 @@ class List {
this.page = 1; this.page = 1;
this.loading = true; this.loading = true;
this.loadingMore = false; this.loadingMore = false;
this.issues = []; this.issues = obj.issues || [];
this.issuesSize = 0; this.issuesSize = obj.issuesSize ? obj.issuesSize : 0;
this.defaultAvatar = defaultAvatar; this.defaultAvatar = defaultAvatar;
if (obj.label) { if (obj.label) {
......
---
title: Fix closed board list loading issue
merge_request:
author:
type: fixed
...@@ -28,7 +28,7 @@ dast_environment_deploy: ...@@ -28,7 +28,7 @@ dast_environment_deploy:
variables: variables:
- $CI_DEFAULT_BRANCH != $CI_COMMIT_REF_NAME - $CI_DEFAULT_BRANCH != $CI_COMMIT_REF_NAME
- $DAST_DISABLED || $DAST_DISABLED_FOR_DEFAULT_BRANCH - $DAST_DISABLED || $DAST_DISABLED_FOR_DEFAULT_BRANCH
- $DAST_WEBSITE # we don't need to create a review app if a URL is already given - $DAST_WEBSITE # we don't need to create a review app if a URL is already given
stop_dast_environment: stop_dast_environment:
extends: .auto-deploy extends: .auto-deploy
......
...@@ -15,7 +15,12 @@ import boardsStore from '~/boards/stores/boards_store'; ...@@ -15,7 +15,12 @@ import boardsStore from '~/boards/stores/boards_store';
window.Sortable = Sortable; window.Sortable = Sortable;
export default function createComponent({ done, listIssueProps = {}, componentProps = {} }) { export default function createComponent({
done,
listIssueProps = {},
componentProps = {},
listProps = {},
}) {
const el = document.createElement('div'); const el = document.createElement('div');
document.body.appendChild(el); document.body.appendChild(el);
...@@ -25,7 +30,7 @@ export default function createComponent({ done, listIssueProps = {}, componentPr ...@@ -25,7 +30,7 @@ export default function createComponent({ done, listIssueProps = {}, componentPr
boardsStore.create(); boardsStore.create();
const BoardListComp = Vue.extend(BoardList); const BoardListComp = Vue.extend(BoardList);
const list = new List(listObj); const list = new List({ ...listObj, ...listProps });
const issue = new ListIssue({ const issue = new ListIssue({
title: 'Testing', title: 'Testing',
id: 1, id: 1,
...@@ -35,7 +40,9 @@ export default function createComponent({ done, listIssueProps = {}, componentPr ...@@ -35,7 +40,9 @@ export default function createComponent({ done, listIssueProps = {}, componentPr
assignees: [], assignees: [],
...listIssueProps, ...listIssueProps,
}); });
list.issuesSize = 1; if (!Object.prototype.hasOwnProperty.call(listProps, 'issuesSize')) {
list.issuesSize = 1;
}
list.issues.push(issue); list.issues.push(issue);
const component = new BoardListComp({ const component = new BoardListComp({
......
/* global List */
import Vue from 'vue'; import Vue from 'vue';
import eventHub from '~/boards/eventhub'; import eventHub from '~/boards/eventhub';
import createComponent from './board_list_common_spec'; import createComponent from './board_list_common_spec';
import waitForPromises from '../helpers/wait_for_promises';
import '~/boards/models/list';
describe('Board list component', () => { describe('Board list component', () => {
let mock; let mock;
let component; let component;
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);
}
}
beforeEach(done => { describe('When Expanded', () => {
({ mock, component } = createComponent({ done })); beforeEach(done => {
}); getIssues = spyOn(List.prototype, 'getIssues').and.returnValue(new Promise(() => {}));
({ mock, component } = createComponent({ done }));
});
afterEach(() => { afterEach(() => {
mock.restore(); mock.restore();
}); component.$destroy();
});
it('renders component', () => { it('loads first page of issues', done => {
expect(component.$el.classList.contains('board-list-component')).toBe(true); waitForPromises()
}); .then(() => {
expect(getIssues).toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
});
it('renders loading icon', done => { it('renders component', () => {
component.loading = true; expect(component.$el.classList.contains('board-list-component')).toBe(true);
});
it('renders loading icon', done => {
component.loading = true;
Vue.nextTick(() => { Vue.nextTick(() => {
expect(component.$el.querySelector('.board-list-loading')).not.toBeNull(); expect(component.$el.querySelector('.board-list-loading')).not.toBeNull();
done(); done();
});
}); });
});
it('renders issues', () => { it('renders issues', () => {
expect(component.$el.querySelectorAll('.board-card').length).toBe(1); expect(component.$el.querySelectorAll('.board-card').length).toBe(1);
}); });
it('sets data attribute with issue id', () => { it('sets data attribute with issue id', () => {
expect(component.$el.querySelector('.board-card').getAttribute('data-issue-id')).toBe('1'); expect(component.$el.querySelector('.board-card').getAttribute('data-issue-id')).toBe('1');
}); });
it('shows new issue form', done => { it('shows new issue form', done => {
component.toggleForm(); component.toggleForm();
Vue.nextTick(() => { Vue.nextTick(() => {
expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull(); expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull();
expect(component.$el.querySelector('.is-smaller')).not.toBeNull(); expect(component.$el.querySelector('.is-smaller')).not.toBeNull();
done(); done();
});
}); });
});
it('shows new issue form after eventhub event', done => { it('shows new issue form after eventhub event', done => {
eventHub.$emit(`hide-issue-form-${component.list.id}`); eventHub.$emit(`hide-issue-form-${component.list.id}`);
Vue.nextTick(() => { Vue.nextTick(() => {
expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull(); expect(component.$el.querySelector('.board-new-issue-form')).not.toBeNull();
expect(component.$el.querySelector('.is-smaller')).not.toBeNull(); expect(component.$el.querySelector('.is-smaller')).not.toBeNull();
done(); done();
});
}); });
});
it('does not show new issue form for closed list', done => { it('does not show new issue form for closed list', done => {
component.list.type = 'closed'; component.list.type = 'closed';
component.toggleForm(); component.toggleForm();
Vue.nextTick(() => { Vue.nextTick(() => {
expect(component.$el.querySelector('.board-new-issue-form')).toBeNull(); expect(component.$el.querySelector('.board-new-issue-form')).toBeNull();
done(); done();
});
}); });
});
it('shows count list item', done => { it('shows count list item', done => {
component.showCount = true; component.showCount = true;
Vue.nextTick(() => { Vue.nextTick(() => {
expect(component.$el.querySelector('.board-list-count')).not.toBeNull(); expect(component.$el.querySelector('.board-list-count')).not.toBeNull();
expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe( expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe(
'Showing all issues', 'Showing all issues',
); );
done(); done();
});
}); });
});
it('sets data attribute with invalid id', done => { it('sets data attribute with invalid id', done => {
component.showCount = true; component.showCount = true;
Vue.nextTick(() => { Vue.nextTick(() => {
expect(component.$el.querySelector('.board-list-count').getAttribute('data-issue-id')).toBe( expect(component.$el.querySelector('.board-list-count').getAttribute('data-issue-id')).toBe(
'-1', '-1',
); );
done(); done();
});
}); });
});
it('shows how many more issues to load', done => { it('shows how many more issues to load', done => {
component.showCount = true; component.showCount = true;
component.list.issuesSize = 20; component.list.issuesSize = 20;
Vue.nextTick(() => { Vue.nextTick(() => {
expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe( expect(component.$el.querySelector('.board-list-count').textContent.trim()).toBe(
'Showing 1 of 20 issues', 'Showing 1 of 20 issues',
); );
done(); done();
});
}); });
});
it('loads more issues after scrolling', done => {
spyOn(component.list, 'nextPage');
component.$refs.list.style.height = '100px';
component.$refs.list.style.overflow = 'scroll';
for (let i = 1; i < 20; i += 1) { it('loads more issues after scrolling', done => {
const issue = Object.assign({}, component.list.issues[0]); spyOn(component.list, 'nextPage');
issue.id += i; component.$refs.list.style.height = '100px';
component.list.issues.push(issue); 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);
});
});
Vue.nextTick(() => { it('does not load issues if already loading', done => {
component.$refs.list.scrollTop = 20000; component.list.nextPage = spyOn(component.list, 'nextPage').and.returnValue(
new Promise(() => {}),
);
setTimeout(() => { component.onScroll();
expect(component.list.nextPage).toHaveBeenCalled(); component.onScroll();
done(); waitForPromises()
}); .then(() => {
expect(component.list.nextPage).toHaveBeenCalledTimes(1);
})
.then(done)
.catch(done.fail);
}); });
});
it('does not load issues if already loading', () => { it('shows loading more spinner', done => {
component.list.nextPage = spyOn(component.list, 'nextPage').and.returnValue( component.showCount = true;
new Promise(() => {}), component.list.loadingMore = true;
);
component.onScroll(); Vue.nextTick(() => {
component.onScroll(); expect(component.$el.querySelector('.board-list-count .gl-spinner')).not.toBeNull();
expect(component.list.nextPage).toHaveBeenCalledTimes(1); done();
});
});
}); });
it('shows loading more spinner', done => { describe('When Collapsed', () => {
component.showCount = true; beforeEach(done => {
component.list.loadingMore = true; 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);
});
Vue.nextTick(() => { afterEach(() => {
expect(component.$el.querySelector('.board-list-count .gl-spinner')).not.toBeNull(); mock.restore();
component.$destroy();
});
done(); it('does not load all issues', done => {
waitForPromises()
.then(() => {
// Initial getIssues from list constructor
expect(getIssues).toHaveBeenCalledTimes(1);
})
.then(done)
.catch(done.fail);
}); });
}); });
}); });
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