summaryrefslogtreecommitdiff
path: root/spec/frontend/boards/list_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-31 18:07:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-31 18:07:42 +0000
commit580622bdb3c762a8e89facd8a3946881ee480442 (patch)
tree3ac9d759da23f78f95f50684bd238a9f76839538 /spec/frontend/boards/list_spec.js
parentb211a4ea14d5e9ed9b0c248a4e8c5c1d85b542cb (diff)
downloadgitlab-ce-580622bdb3c762a8e89facd8a3946881ee480442.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/boards/list_spec.js')
-rw-r--r--spec/frontend/boards/list_spec.js232
1 files changed, 232 insertions, 0 deletions
diff --git a/spec/frontend/boards/list_spec.js b/spec/frontend/boards/list_spec.js
new file mode 100644
index 00000000000..c0dd5afe498
--- /dev/null
+++ b/spec/frontend/boards/list_spec.js
@@ -0,0 +1,232 @@
+/* global List */
+/* global ListAssignee */
+/* global ListIssue */
+/* global ListLabel */
+
+import MockAdapter from 'axios-mock-adapter';
+import axios from '~/lib/utils/axios_utils';
+import '~/boards/models/label';
+import '~/boards/models/assignee';
+import '~/boards/models/issue';
+import '~/boards/models/list';
+import { ListType } from '~/boards/constants';
+import boardsStore from '~/boards/stores/boards_store';
+import waitForPromises from 'helpers/wait_for_promises';
+import { listObj, listObjDuplicate, boardsMockInterceptor } from './mock_data';
+
+describe('List model', () => {
+ let list;
+ let mock;
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ mock.onAny().reply(boardsMockInterceptor);
+ boardsStore.create();
+ boardsStore.setEndpoints({
+ listsEndpoint: '/test/-/boards/1/lists',
+ });
+
+ list = new List(listObj);
+ return waitForPromises();
+ });
+
+ afterEach(() => {
+ mock.restore();
+ });
+
+ describe('list type', () => {
+ const notExpandableList = ['blank'];
+
+ const table = Object.keys(ListType).map(k => {
+ const value = ListType[k];
+ return [value, !notExpandableList.includes(value)];
+ });
+ it.each(table)(`when list_type is %s boards isExpandable is %p`, (type, result) => {
+ expect(new List({ id: 1, list_type: type }).isExpandable).toBe(result);
+ });
+ });
+
+ it('gets issues when created', () => {
+ expect(list.issues.length).toBe(1);
+ });
+
+ it('saves list and returns ID', () => {
+ list = new List({
+ title: 'test',
+ label: {
+ id: 1,
+ title: 'test',
+ color: 'red',
+ text_color: 'white',
+ },
+ });
+ return list.save().then(() => {
+ expect(list.id).toBe(listObj.id);
+ expect(list.type).toBe('label');
+ expect(list.position).toBe(0);
+ expect(list.label.color).toBe('red');
+ expect(list.label.textColor).toBe('white');
+ });
+ });
+
+ it('destroys the list', () => {
+ boardsStore.addList(listObj);
+ list = boardsStore.findList('id', listObj.id);
+
+ expect(boardsStore.state.lists.length).toBe(1);
+ list.destroy();
+
+ return waitForPromises().then(() => {
+ expect(boardsStore.state.lists.length).toBe(0);
+ });
+ });
+
+ it('gets issue from list', () => {
+ const issue = list.findIssue(1);
+
+ expect(issue).toBeDefined();
+ });
+
+ it('removes issue', () => {
+ const issue = list.findIssue(1);
+
+ expect(list.issues.length).toBe(1);
+ list.removeIssue(issue);
+
+ expect(list.issues.length).toBe(0);
+ });
+
+ it('sends service request to update issue label', () => {
+ const listDup = new List(listObjDuplicate);
+ const issue = new ListIssue({
+ title: 'Testing',
+ id: 1,
+ iid: 1,
+ confidential: false,
+ labels: [list.label, listDup.label],
+ assignees: [],
+ });
+
+ list.issues.push(issue);
+ listDup.issues.push(issue);
+
+ jest.spyOn(boardsStore, 'moveIssue');
+
+ listDup.updateIssueLabel(issue, list);
+
+ expect(boardsStore.moveIssue).toHaveBeenCalledWith(
+ issue.id,
+ list.id,
+ listDup.id,
+ undefined,
+ undefined,
+ );
+ });
+
+ describe('page number', () => {
+ beforeEach(() => {
+ jest.spyOn(list, 'getIssues').mockImplementation(() => {});
+ list.issues = [];
+ });
+
+ it('increase page number if current issue count is more than the page size', () => {
+ for (let i = 0; i < 30; i += 1) {
+ list.issues.push(
+ new ListIssue({
+ title: 'Testing',
+ id: i,
+ iid: i,
+ confidential: false,
+ labels: [list.label],
+ assignees: [],
+ }),
+ );
+ }
+ list.issuesSize = 50;
+
+ expect(list.issues.length).toBe(30);
+
+ list.nextPage();
+
+ expect(list.page).toBe(2);
+ expect(list.getIssues).toHaveBeenCalled();
+ });
+
+ it('does not increase page number if issue count is less than the page size', () => {
+ list.issues.push(
+ new ListIssue({
+ title: 'Testing',
+ id: 1,
+ confidential: false,
+ labels: [list.label],
+ assignees: [],
+ }),
+ );
+ list.issuesSize = 2;
+
+ list.nextPage();
+
+ expect(list.page).toBe(1);
+ expect(list.getIssues).toHaveBeenCalled();
+ });
+ });
+
+ describe('newIssue', () => {
+ beforeEach(() => {
+ jest.spyOn(boardsStore, 'newIssue').mockReturnValue(
+ Promise.resolve({
+ data: {
+ id: 42,
+ subscribed: false,
+ assignable_labels_endpoint: '/issue/42/labels',
+ toggle_subscription_endpoint: '/issue/42/subscriptions',
+ issue_sidebar_endpoint: '/issue/42/sidebar_info',
+ },
+ }),
+ );
+ list.issues = [];
+ });
+
+ it('adds new issue to top of list', done => {
+ const user = new ListAssignee({
+ id: 1,
+ name: 'testing 123',
+ username: 'test',
+ avatar: 'test_image',
+ });
+
+ list.issues.push(
+ new ListIssue({
+ title: 'Testing',
+ id: 1,
+ confidential: false,
+ labels: [new ListLabel(list.label)],
+ assignees: [],
+ }),
+ );
+ const dummyIssue = new ListIssue({
+ title: 'new issue',
+ id: 2,
+ confidential: false,
+ labels: [new ListLabel(list.label)],
+ assignees: [user],
+ subscribed: false,
+ });
+
+ list
+ .newIssue(dummyIssue)
+ .then(() => {
+ expect(list.issues.length).toBe(2);
+ expect(list.issues[0]).toBe(dummyIssue);
+ expect(list.issues[0].subscribed).toBe(false);
+ expect(list.issues[0].assignableLabelsEndpoint).toBe('/issue/42/labels');
+ expect(list.issues[0].toggleSubscriptionEndpoint).toBe('/issue/42/subscriptions');
+ expect(list.issues[0].sidebarInfoEndpoint).toBe('/issue/42/sidebar_info');
+ expect(list.issues[0].labels).toBe(dummyIssue.labels);
+ expect(list.issues[0].assignees).toBe(dummyIssue.assignees);
+ })
+ .then(done)
+ .catch(done.fail);
+ });
+ });
+});