diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-13 18:08:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-13 18:08:02 +0300 |
commit | 4eeb6b0d16021ab4a730eec4610eff2606421147 (patch) | |
tree | 488db828fe58f1e80dc5415970e4c929db7e4c4b /spec/frontend | |
parent | 8cc5f2790908ba9bb8eecba2b78a3c5a88c77b90 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/boards/boards_store_spec.js | 491 | ||||
-rw-r--r-- | spec/frontend/boards/mock_data.js | 91 |
2 files changed, 581 insertions, 1 deletions
diff --git a/spec/frontend/boards/boards_store_spec.js b/spec/frontend/boards/boards_store_spec.js index f8e5873c87b..3588197ebdc 100644 --- a/spec/frontend/boards/boards_store_spec.js +++ b/spec/frontend/boards/boards_store_spec.js @@ -1,7 +1,23 @@ -import { TEST_HOST } from 'helpers/test_constants'; import AxiosMockAdapter from 'axios-mock-adapter'; +import { TEST_HOST } from 'helpers/test_constants'; import axios from '~/lib/utils/axios_utils'; import boardsStore from '~/boards/stores/boards_store'; +import eventHub from '~/boards/eventhub'; +import { listObj, listObjDuplicate } from './mock_data'; + +import ListIssue from '~/boards/models/issue'; +import '~/boards/models/list'; + +jest.mock('js-cookie'); + +const createTestIssue = () => ({ + title: 'Testing', + id: 1, + iid: 1, + confidential: false, + labels: [], + assignees: [], +}); describe('boardsStore', () => { const dummyResponse = "without type checking this doesn't matter"; @@ -23,6 +39,19 @@ describe('boardsStore', () => { }); }); + afterEach(() => { + axiosMock.restore(); + jest.clearAllMocks(); + }); + + const setupDefaultResponses = () => { + axiosMock + .onGet(`${endpoints.listsEndpoint}/${listObj.id}/issues?id=${listObj.id}&page=1`) + .reply(200, { issues: [createTestIssue()] }); + axiosMock.onPost(endpoints.listsEndpoint).reply(200, listObj); + axiosMock.onPut(); + }; + describe('all', () => { it('makes a request to fetch lists', () => { axiosMock.onGet(endpoints.listsEndpoint).replyOnce(200, dummyResponse); @@ -546,4 +575,464 @@ describe('boardsStore', () => { return expect(boardsStore.deleteBoard({ id })).rejects.toThrow(); }); }); + + describe('when created', () => { + beforeEach(() => { + setupDefaultResponses(); + + jest.spyOn(boardsStore, 'moveIssue').mockReturnValue(Promise.resolve()); + jest.spyOn(boardsStore, 'moveMultipleIssues').mockReturnValue(Promise.resolve()); + + boardsStore.create(); + }); + + it('starts with a blank state', () => { + expect(boardsStore.state.lists.length).toBe(0); + }); + + describe('addList', () => { + it('sorts by position', () => { + boardsStore.addList({ position: 2 }); + boardsStore.addList({ position: 1 }); + + expect(boardsStore.state.lists.map(({ position }) => position)).toEqual([1, 2]); + }); + }); + + describe('toggleFilter', () => { + const dummyFilter = 'x=42'; + let updateTokensSpy; + + beforeEach(() => { + updateTokensSpy = jest.fn(); + eventHub.$once('updateTokens', updateTokensSpy); + + // prevent using window.history + jest.spyOn(boardsStore, 'updateFiltersUrl').mockReturnValue(); + }); + + it('adds the filter if it is not present', () => { + boardsStore.filter.path = 'something'; + + boardsStore.toggleFilter(dummyFilter); + + expect(boardsStore.filter.path).toEqual(`something&${dummyFilter}`); + expect(updateTokensSpy).toHaveBeenCalled(); + expect(boardsStore.updateFiltersUrl).toHaveBeenCalled(); + }); + + it('removes the filter if it is present', () => { + boardsStore.filter.path = `something&${dummyFilter}`; + + boardsStore.toggleFilter(dummyFilter); + + expect(boardsStore.filter.path).toEqual('something'); + expect(updateTokensSpy).toHaveBeenCalled(); + expect(boardsStore.updateFiltersUrl).toHaveBeenCalled(); + }); + }); + + describe('lists', () => { + it('creates new list without persisting to DB', () => { + expect(boardsStore.state.lists.length).toBe(0); + + boardsStore.addList(listObj); + + expect(boardsStore.state.lists.length).toBe(1); + }); + + it('finds list by ID', () => { + boardsStore.addList(listObj); + const list = boardsStore.findList('id', listObj.id); + + expect(list.id).toBe(listObj.id); + }); + + it('finds list by type', () => { + boardsStore.addList(listObj); + const list = boardsStore.findList('type', 'label'); + + expect(list).toBeDefined(); + }); + + it('finds list by label ID', () => { + boardsStore.addList(listObj); + const list = boardsStore.findListByLabelId(listObj.label.id); + + expect(list.id).toBe(listObj.id); + }); + + it('gets issue when new list added', () => { + boardsStore.addList(listObj); + const list = boardsStore.findList('id', listObj.id); + + expect(boardsStore.state.lists.length).toBe(1); + + return axios.waitForAll().then(() => { + expect(list.issues.length).toBe(1); + expect(list.issues[0].id).toBe(1); + }); + }); + + it('persists new list', () => { + boardsStore.new({ + title: 'Test', + list_type: 'label', + label: { + id: 1, + title: 'Testing', + color: 'red', + description: 'testing;', + }, + }); + + expect(boardsStore.state.lists.length).toBe(1); + + return axios.waitForAll().then(() => { + const list = boardsStore.findList('id', listObj.id); + + expect(list).toEqual( + expect.objectContaining({ + id: listObj.id, + position: 0, + }), + ); + }); + }); + + it('check for blank state adding', () => { + expect(boardsStore.shouldAddBlankState()).toBe(true); + }); + + it('check for blank state not adding', () => { + boardsStore.addList(listObj); + + expect(boardsStore.shouldAddBlankState()).toBe(false); + }); + + it('check for blank state adding when closed list exist', () => { + boardsStore.addList({ + list_type: 'closed', + }); + + expect(boardsStore.shouldAddBlankState()).toBe(true); + }); + + it('adds the blank state', () => { + boardsStore.addBlankState(); + + const list = boardsStore.findList('type', 'blank', 'blank'); + + expect(list).toBeDefined(); + }); + + it('removes list from state', () => { + boardsStore.addList(listObj); + + expect(boardsStore.state.lists.length).toBe(1); + + boardsStore.removeList(listObj.id, 'label'); + + expect(boardsStore.state.lists.length).toBe(0); + }); + + it('moves the position of lists', () => { + const listOne = boardsStore.addList(listObj); + boardsStore.addList(listObjDuplicate); + + expect(boardsStore.state.lists.length).toBe(2); + + boardsStore.moveList(listOne, [listObjDuplicate.id, listObj.id]); + + expect(listOne.position).toBe(1); + }); + + it('moves an issue from one list to another', () => { + const listOne = boardsStore.addList(listObj); + const listTwo = boardsStore.addList(listObjDuplicate); + + expect(boardsStore.state.lists.length).toBe(2); + + return axios.waitForAll().then(() => { + expect(listOne.issues.length).toBe(1); + expect(listTwo.issues.length).toBe(1); + + boardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(1)); + + expect(listOne.issues.length).toBe(0); + expect(listTwo.issues.length).toBe(1); + }); + }); + + it('moves an issue from backlog to a list', () => { + const backlog = boardsStore.addList({ + ...listObj, + list_type: 'backlog', + }); + const listTwo = boardsStore.addList(listObjDuplicate); + + expect(boardsStore.state.lists.length).toBe(2); + + return axios.waitForAll().then(() => { + expect(backlog.issues.length).toBe(1); + expect(listTwo.issues.length).toBe(1); + + boardsStore.moveIssueToList(backlog, listTwo, backlog.findIssue(1)); + + expect(backlog.issues.length).toBe(0); + expect(listTwo.issues.length).toBe(1); + }); + }); + + it('moves issue to top of another list', () => { + const listOne = boardsStore.addList(listObj); + const listTwo = boardsStore.addList(listObjDuplicate); + + expect(boardsStore.state.lists.length).toBe(2); + + return axios.waitForAll().then(() => { + listOne.issues[0].id = 2; + + expect(listOne.issues.length).toBe(1); + expect(listTwo.issues.length).toBe(1); + + boardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(2), 0); + + expect(listOne.issues.length).toBe(0); + expect(listTwo.issues.length).toBe(2); + expect(listTwo.issues[0].id).toBe(2); + expect(boardsStore.moveIssue).toHaveBeenCalledWith(2, listOne.id, listTwo.id, null, 1); + }); + }); + + it('moves issue to bottom of another list', () => { + const listOne = boardsStore.addList(listObj); + const listTwo = boardsStore.addList(listObjDuplicate); + + expect(boardsStore.state.lists.length).toBe(2); + + return axios.waitForAll().then(() => { + listOne.issues[0].id = 2; + + expect(listOne.issues.length).toBe(1); + expect(listTwo.issues.length).toBe(1); + + boardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(2), 1); + + expect(listOne.issues.length).toBe(0); + expect(listTwo.issues.length).toBe(2); + expect(listTwo.issues[1].id).toBe(2); + expect(boardsStore.moveIssue).toHaveBeenCalledWith(2, listOne.id, listTwo.id, 1, null); + }); + }); + + it('moves issue in list', () => { + const issue = new ListIssue({ + title: 'Testing', + id: 2, + iid: 2, + confidential: false, + labels: [], + assignees: [], + }); + const list = boardsStore.addList(listObj); + + return axios.waitForAll().then(() => { + list.addIssue(issue); + + expect(list.issues.length).toBe(2); + + boardsStore.moveIssueInList(list, issue, 0, 1, [1, 2]); + + expect(list.issues[0].id).toBe(2); + expect(boardsStore.moveIssue).toHaveBeenCalledWith(2, null, null, 1, null); + }); + }); + }); + + describe('setListDetail', () => { + it('sets the list detail', () => { + boardsStore.detail.list = 'not a list'; + + const dummyValue = 'new list'; + boardsStore.setListDetail(dummyValue); + + expect(boardsStore.detail.list).toEqual(dummyValue); + }); + }); + + describe('clearDetailIssue', () => { + it('resets issue details', () => { + boardsStore.detail.issue = 'something'; + + boardsStore.clearDetailIssue(); + + expect(boardsStore.detail.issue).toEqual({}); + }); + }); + + describe('setIssueDetail', () => { + it('sets issue details', () => { + boardsStore.detail.issue = 'some details'; + + const dummyValue = 'new details'; + boardsStore.setIssueDetail(dummyValue); + + expect(boardsStore.detail.issue).toEqual(dummyValue); + }); + }); + + describe('startMoving', () => { + it('stores list and issue', () => { + const dummyIssue = 'some issue'; + const dummyList = 'some list'; + + boardsStore.startMoving(dummyList, dummyIssue); + + expect(boardsStore.moving.issue).toEqual(dummyIssue); + expect(boardsStore.moving.list).toEqual(dummyList); + }); + }); + + describe('setTimeTrackingLimitToHours', () => { + it('sets the timeTracking.LimitToHours option', () => { + boardsStore.timeTracking.limitToHours = false; + + boardsStore.setTimeTrackingLimitToHours('true'); + + expect(boardsStore.timeTracking.limitToHours).toEqual(true); + }); + }); + + describe('setCurrentBoard', () => { + const dummyBoard = 'hoverboard'; + + it('sets the current board', () => { + const { state } = boardsStore; + state.currentBoard = null; + + boardsStore.setCurrentBoard(dummyBoard); + + expect(state.currentBoard).toEqual(dummyBoard); + }); + }); + + describe('toggleMultiSelect', () => { + let basicIssueObj; + + beforeAll(() => { + basicIssueObj = { id: 987654 }; + }); + + afterEach(() => { + boardsStore.clearMultiSelect(); + }); + + it('adds issue when not present', () => { + boardsStore.toggleMultiSelect(basicIssueObj); + + const selectedIds = boardsStore.multiSelect.list.map(({ id }) => id); + + expect(selectedIds.includes(basicIssueObj.id)).toEqual(true); + }); + + it('removes issue when issue is present', () => { + boardsStore.toggleMultiSelect(basicIssueObj); + let selectedIds = boardsStore.multiSelect.list.map(({ id }) => id); + + expect(selectedIds.includes(basicIssueObj.id)).toEqual(true); + + boardsStore.toggleMultiSelect(basicIssueObj); + selectedIds = boardsStore.multiSelect.list.map(({ id }) => id); + + expect(selectedIds.includes(basicIssueObj.id)).toEqual(false); + }); + }); + + describe('clearMultiSelect', () => { + it('clears all the multi selected issues', () => { + const issue1 = { id: 12345 }; + const issue2 = { id: 12346 }; + + boardsStore.toggleMultiSelect(issue1); + boardsStore.toggleMultiSelect(issue2); + + expect(boardsStore.multiSelect.list.length).toEqual(2); + + boardsStore.clearMultiSelect(); + + expect(boardsStore.multiSelect.list.length).toEqual(0); + }); + }); + + describe('moveMultipleIssuesToList', () => { + it('move issues on the new index', () => { + const listOne = boardsStore.addList(listObj); + const listTwo = boardsStore.addList(listObjDuplicate); + + expect(boardsStore.state.lists.length).toBe(2); + + return axios.waitForAll().then(() => { + expect(listOne.issues.length).toBe(1); + expect(listTwo.issues.length).toBe(1); + + boardsStore.moveMultipleIssuesToList({ + listFrom: listOne, + listTo: listTwo, + issues: listOne.issues, + newIndex: 0, + }); + + expect(listTwo.issues.length).toBe(1); + }); + }); + }); + + describe('moveMultipleIssuesInList', () => { + it('moves multiple issues in list', () => { + const issueObj = { + title: 'Issue #1', + id: 12345, + iid: 2, + confidential: false, + labels: [], + assignees: [], + }; + const issue1 = new ListIssue(issueObj); + const issue2 = new ListIssue({ + ...issueObj, + title: 'Issue #2', + id: 12346, + }); + + const list = boardsStore.addList(listObj); + + return axios.waitForAll().then(() => { + list.addIssue(issue1); + list.addIssue(issue2); + + expect(list.issues.length).toBe(3); + expect(list.issues[0].id).not.toBe(issue2.id); + + boardsStore.moveMultipleIssuesInList({ + list, + issues: [issue1, issue2], + oldIndicies: [0], + newIndex: 1, + idArray: [1, 12345, 12346], + }); + + expect(list.issues[0].id).toBe(issue1.id); + + expect(boardsStore.moveMultipleIssues).toHaveBeenCalledWith({ + ids: [issue1.id, issue2.id], + fromListId: null, + toListId: null, + moveBeforeId: 1, + moveAfterId: null, + }); + }); + }); + }); + }); }); diff --git a/spec/frontend/boards/mock_data.js b/spec/frontend/boards/mock_data.js new file mode 100644 index 00000000000..05f73e0d8dc --- /dev/null +++ b/spec/frontend/boards/mock_data.js @@ -0,0 +1,91 @@ +export const boardObj = { + id: 1, + name: 'test', + milestone_id: null, +}; + +export const listObj = { + id: 300, + position: 0, + title: 'Test', + list_type: 'label', + weight: 3, + label: { + id: 5000, + title: 'Test', + color: 'red', + description: 'testing;', + textColor: 'white', + }, +}; + +export const listObjDuplicate = { + id: listObj.id, + position: 1, + title: 'Test', + list_type: 'label', + weight: 3, + label: { + id: listObj.label.id, + title: 'Test', + color: 'red', + description: 'testing;', + }, +}; + +export const mockAssigneesList = [ + { + id: 2, + name: 'Terrell Graham', + username: 'monserrate.gleichner', + state: 'active', + avatar_url: 'https://www.gravatar.com/avatar/598fd02741ac58b88854a99d16704309?s=80&d=identicon', + web_url: 'http://127.0.0.1:3001/monserrate.gleichner', + path: '/monserrate.gleichner', + }, + { + id: 12, + name: 'Susy Johnson', + username: 'tana_harvey', + state: 'active', + avatar_url: 'https://www.gravatar.com/avatar/e021a7b0f3e4ae53b5068d487e68c031?s=80&d=identicon', + web_url: 'http://127.0.0.1:3001/tana_harvey', + path: '/tana_harvey', + }, + { + id: 20, + name: 'Conchita Eichmann', + username: 'juliana_gulgowski', + state: 'active', + avatar_url: 'https://www.gravatar.com/avatar/c43c506cb6fd7b37017d3b54b94aa937?s=80&d=identicon', + web_url: 'http://127.0.0.1:3001/juliana_gulgowski', + path: '/juliana_gulgowski', + }, + { + id: 6, + name: 'Bryce Turcotte', + username: 'melynda', + state: 'active', + avatar_url: 'https://www.gravatar.com/avatar/cc2518f2c6f19f8fac49e1a5ee092a9b?s=80&d=identicon', + web_url: 'http://127.0.0.1:3001/melynda', + path: '/melynda', + }, + { + id: 1, + name: 'Administrator', + username: 'root', + state: 'active', + avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + web_url: 'http://127.0.0.1:3001/root', + path: '/root', + }, +]; + +export const mockMilestone = { + id: 1, + state: 'active', + title: 'Milestone title', + description: 'Harum corporis aut consequatur quae dolorem error sequi quia.', + start_date: '2018-01-01', + due_date: '2019-12-31', +}; |