From be2f4c5788975597dd7be1c8a3525549770c1216 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 24 Mar 2020 03:09:28 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/javascripts/boards/board_blank_state_spec.js | 99 --------- spec/javascripts/boards/board_new_issue_spec.js | 227 --------------------- .../boards/components/board_form_spec.js | 56 ----- spec/javascripts/boards/issue_spec.js | 197 ------------------ spec/javascripts/boards/mock_data.js | 54 ----- 5 files changed, 633 deletions(-) delete mode 100644 spec/javascripts/boards/board_blank_state_spec.js delete mode 100644 spec/javascripts/boards/board_new_issue_spec.js delete mode 100644 spec/javascripts/boards/components/board_form_spec.js delete mode 100644 spec/javascripts/boards/issue_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/boards/board_blank_state_spec.js b/spec/javascripts/boards/board_blank_state_spec.js deleted file mode 100644 index b64859ec32a..00000000000 --- a/spec/javascripts/boards/board_blank_state_spec.js +++ /dev/null @@ -1,99 +0,0 @@ -import Vue from 'vue'; -import boardsStore from '~/boards/stores/boards_store'; -import BoardBlankState from '~/boards/components/board_blank_state.vue'; - -describe('Boards blank state', () => { - let vm; - let fail = false; - - beforeEach(done => { - const Comp = Vue.extend(BoardBlankState); - - boardsStore.create(); - - spyOn(boardsStore, 'addList').and.stub(); - spyOn(boardsStore, 'removeList').and.stub(); - spyOn(boardsStore, 'generateDefaultLists').and.callFake( - () => - new Promise((resolve, reject) => { - if (fail) { - reject(); - } else { - resolve({ - data: [ - { - id: 1, - title: 'To Do', - label: { id: 1 }, - }, - { - id: 2, - title: 'Doing', - label: { id: 2 }, - }, - ], - }); - } - }), - ); - - vm = new Comp(); - - setTimeout(() => { - vm.$mount(); - done(); - }); - }); - - it('renders pre-defined labels', () => { - expect(vm.$el.querySelectorAll('.board-blank-state-list li').length).toBe(2); - - expect(vm.$el.querySelectorAll('.board-blank-state-list li')[0].textContent.trim()).toEqual( - 'To Do', - ); - - expect(vm.$el.querySelectorAll('.board-blank-state-list li')[1].textContent.trim()).toEqual( - 'Doing', - ); - }); - - it('clears blank state', done => { - vm.$el.querySelector('.btn-default').click(); - - setTimeout(() => { - expect(boardsStore.welcomeIsHidden()).toBeTruthy(); - - done(); - }); - }); - - it('creates pre-defined labels', done => { - vm.$el.querySelector('.btn-success').click(); - - setTimeout(() => { - expect(boardsStore.addList).toHaveBeenCalledTimes(2); - expect(boardsStore.addList).toHaveBeenCalledWith( - jasmine.objectContaining({ title: 'To Do' }), - ); - - expect(boardsStore.addList).toHaveBeenCalledWith( - jasmine.objectContaining({ title: 'Doing' }), - ); - - done(); - }); - }); - - it('resets the store if request fails', done => { - fail = true; - - vm.$el.querySelector('.btn-success').click(); - - setTimeout(() => { - expect(boardsStore.welcomeIsHidden()).toBeFalsy(); - expect(boardsStore.removeList).toHaveBeenCalledWith(undefined, 'label'); - - done(); - }); - }); -}); diff --git a/spec/javascripts/boards/board_new_issue_spec.js b/spec/javascripts/boards/board_new_issue_spec.js deleted file mode 100644 index 8e4093cc25c..00000000000 --- a/spec/javascripts/boards/board_new_issue_spec.js +++ /dev/null @@ -1,227 +0,0 @@ -/* global List */ - -import Vue from 'vue'; -import MockAdapter from 'axios-mock-adapter'; -import axios from '~/lib/utils/axios_utils'; -import boardNewIssue from '~/boards/components/board_new_issue.vue'; -import boardsStore from '~/boards/stores/boards_store'; - -import '~/boards/models/list'; -import { listObj, boardsMockInterceptor } from './mock_data'; - -describe('Issue boards new issue form', () => { - let vm; - let list; - let mock; - let newIssueMock; - const promiseReturn = { - data: { - iid: 100, - }, - }; - - const submitIssue = () => { - const dummySubmitEvent = { - preventDefault() {}, - }; - vm.$refs.submitButton = vm.$el.querySelector('.btn-success'); - return vm.submit(dummySubmitEvent); - }; - - beforeEach(done => { - setFixtures('
'); - - const BoardNewIssueComp = Vue.extend(boardNewIssue); - - mock = new MockAdapter(axios); - mock.onAny().reply(boardsMockInterceptor); - - boardsStore.create(); - - list = new List(listObj); - - newIssueMock = Promise.resolve(promiseReturn); - spyOn(list, 'newIssue').and.callFake(() => newIssueMock); - - vm = new BoardNewIssueComp({ - propsData: { - list, - }, - }).$mount(document.querySelector('.test-container')); - - Vue.nextTick() - .then(done) - .catch(done.fail); - }); - - afterEach(() => { - vm.$destroy(); - mock.restore(); - }); - - it('calls submit if submit button is clicked', done => { - spyOn(vm, 'submit').and.callFake(e => e.preventDefault()); - vm.title = 'Testing Title'; - - Vue.nextTick() - .then(() => { - vm.$el.querySelector('.btn-success').click(); - - expect(vm.submit.calls.count()).toBe(1); - }) - .then(done) - .catch(done.fail); - }); - - it('disables submit button if title is empty', () => { - expect(vm.$el.querySelector('.btn-success').disabled).toBe(true); - }); - - it('enables submit button if title is not empty', done => { - vm.title = 'Testing Title'; - - Vue.nextTick() - .then(() => { - expect(vm.$el.querySelector('.form-control').value).toBe('Testing Title'); - expect(vm.$el.querySelector('.btn-success').disabled).not.toBe(true); - }) - .then(done) - .catch(done.fail); - }); - - it('clears title after clicking cancel', done => { - vm.$el.querySelector('.btn-default').click(); - - Vue.nextTick() - .then(() => { - expect(vm.title).toBe(''); - }) - .then(done) - .catch(done.fail); - }); - - it('does not create new issue if title is empty', done => { - submitIssue() - .then(() => { - expect(list.newIssue).not.toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); - }); - - describe('submit success', () => { - it('creates new issue', done => { - vm.title = 'submit title'; - - Vue.nextTick() - .then(submitIssue) - .then(() => { - expect(list.newIssue).toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); - }); - - it('enables button after submit', done => { - vm.title = 'submit issue'; - - Vue.nextTick() - .then(submitIssue) - .then(() => { - expect(vm.$el.querySelector('.btn-success').disabled).toBe(false); - }) - .then(done) - .catch(done.fail); - }); - - it('clears title after submit', done => { - vm.title = 'submit issue'; - - Vue.nextTick() - .then(submitIssue) - .then(() => { - expect(vm.title).toBe(''); - }) - .then(done) - .catch(done.fail); - }); - - it('sets detail issue after submit', done => { - expect(boardsStore.detail.issue.title).toBe(undefined); - vm.title = 'submit issue'; - - Vue.nextTick() - .then(submitIssue) - .then(() => { - expect(boardsStore.detail.issue.title).toBe('submit issue'); - }) - .then(done) - .catch(done.fail); - }); - - it('sets detail list after submit', done => { - vm.title = 'submit issue'; - - Vue.nextTick() - .then(submitIssue) - .then(() => { - expect(boardsStore.detail.list.id).toBe(list.id); - }) - .then(done) - .catch(done.fail); - }); - - it('sets detail weight after submit', done => { - boardsStore.weightFeatureAvailable = true; - vm.title = 'submit issue'; - - Vue.nextTick() - .then(submitIssue) - .then(() => { - expect(boardsStore.detail.list.weight).toBe(list.weight); - }) - .then(done) - .catch(done.fail); - }); - - it('does not set detail weight after submit', done => { - boardsStore.weightFeatureAvailable = false; - vm.title = 'submit issue'; - - Vue.nextTick() - .then(submitIssue) - .then(() => { - expect(boardsStore.detail.list.weight).toBe(list.weight); - }) - .then(done) - .catch(done.fail); - }); - }); - - describe('submit error', () => { - beforeEach(() => { - newIssueMock = Promise.reject(new Error('My hovercraft is full of eels!')); - vm.title = 'error'; - }); - - it('removes issue', done => { - Vue.nextTick() - .then(submitIssue) - .then(() => { - expect(list.issues.length).toBe(1); - }) - .then(done) - .catch(done.fail); - }); - - it('shows error', done => { - Vue.nextTick() - .then(submitIssue) - .then(() => { - expect(vm.error).toBe(true); - }) - .then(done) - .catch(done.fail); - }); - }); -}); diff --git a/spec/javascripts/boards/components/board_form_spec.js b/spec/javascripts/boards/components/board_form_spec.js deleted file mode 100644 index fd1c79d44e1..00000000000 --- a/spec/javascripts/boards/components/board_form_spec.js +++ /dev/null @@ -1,56 +0,0 @@ -import $ from 'jquery'; -import Vue from 'vue'; -import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import boardsStore from '~/boards/stores/boards_store'; -import boardForm from '~/boards/components/board_form.vue'; - -describe('board_form.vue', () => { - const props = { - canAdminBoard: false, - labelsPath: `${gl.TEST_HOST}/labels/path`, - milestonePath: `${gl.TEST_HOST}/milestone/path`, - }; - let vm; - - beforeEach(() => { - spyOn($, 'ajax'); - boardsStore.state.currentPage = 'edit'; - const Component = Vue.extend(boardForm); - vm = mountComponent(Component, props); - }); - - afterEach(() => { - vm.$destroy(); - }); - - describe('methods', () => { - describe('cancel', () => { - it('resets currentPage', done => { - vm.cancel(); - - Vue.nextTick() - .then(() => { - expect(boardsStore.state.currentPage).toBe(''); - }) - .then(done) - .catch(done.fail); - }); - }); - }); - - describe('buttons', () => { - it('cancel button triggers cancel()', done => { - spyOn(vm, 'cancel'); - - Vue.nextTick() - .then(() => { - const cancelButton = vm.$el.querySelector('button[data-dismiss="modal"]'); - cancelButton.click(); - - expect(vm.cancel).toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); - }); - }); -}); diff --git a/spec/javascripts/boards/issue_spec.js b/spec/javascripts/boards/issue_spec.js deleted file mode 100644 index 181e7af7451..00000000000 --- a/spec/javascripts/boards/issue_spec.js +++ /dev/null @@ -1,197 +0,0 @@ -/* global ListIssue */ - -import axios from '~/lib/utils/axios_utils'; -import '~/boards/models/label'; -import '~/boards/models/assignee'; -import '~/boards/models/issue'; -import '~/boards/models/list'; -import boardsStore from '~/boards/stores/boards_store'; -import { setMockEndpoints } from './mock_data'; - -describe('Issue model', () => { - let issue; - - beforeEach(() => { - setMockEndpoints(); - boardsStore.create(); - - issue = new ListIssue({ - title: 'Testing', - id: 1, - iid: 1, - confidential: false, - labels: [ - { - id: 1, - title: 'test', - color: 'red', - description: 'testing', - }, - ], - assignees: [ - { - id: 1, - name: 'name', - username: 'username', - avatar_url: 'http://avatar_url', - }, - ], - }); - }); - - it('has label', () => { - expect(issue.labels.length).toBe(1); - }); - - it('add new label', () => { - issue.addLabel({ - id: 2, - title: 'bug', - color: 'blue', - description: 'bugs!', - }); - - expect(issue.labels.length).toBe(2); - }); - - it('does not add label if label id exists', () => { - issue.addLabel({ - id: 1, - title: 'test 2', - color: 'blue', - description: 'testing', - }); - - expect(issue.labels.length).toBe(1); - expect(issue.labels[0].color).toBe('red'); - }); - - it('adds other label with same title', () => { - issue.addLabel({ - id: 2, - title: 'test', - color: 'blue', - description: 'other test', - }); - - expect(issue.labels.length).toBe(2); - }); - - it('finds label', () => { - const label = issue.findLabel(issue.labels[0]); - - expect(label).toBeDefined(); - }); - - it('removes label', () => { - const label = issue.findLabel(issue.labels[0]); - issue.removeLabel(label); - - expect(issue.labels.length).toBe(0); - }); - - it('removes multiple labels', () => { - issue.addLabel({ - id: 2, - title: 'bug', - color: 'blue', - description: 'bugs!', - }); - - expect(issue.labels.length).toBe(2); - - issue.removeLabels([issue.labels[0], issue.labels[1]]); - - expect(issue.labels.length).toBe(0); - }); - - it('adds assignee', () => { - issue.addAssignee({ - id: 2, - name: 'Bruce Wayne', - username: 'batman', - avatar_url: 'http://batman', - }); - - expect(issue.assignees.length).toBe(2); - }); - - it('finds assignee', () => { - const assignee = issue.findAssignee(issue.assignees[0]); - - expect(assignee).toBeDefined(); - }); - - it('removes assignee', () => { - const assignee = issue.findAssignee(issue.assignees[0]); - issue.removeAssignee(assignee); - - expect(issue.assignees.length).toBe(0); - }); - - it('removes all assignees', () => { - issue.removeAllAssignees(); - - expect(issue.assignees.length).toBe(0); - }); - - it('sets position to infinity if no position is stored', () => { - expect(issue.position).toBe(Infinity); - }); - - it('sets position', () => { - const relativePositionIssue = new ListIssue({ - title: 'Testing', - iid: 1, - confidential: false, - relative_position: 1, - labels: [], - assignees: [], - }); - - expect(relativePositionIssue.position).toBe(1); - }); - - it('updates data', () => { - issue.updateData({ subscribed: true }); - - expect(issue.subscribed).toBe(true); - }); - - it('sets fetching state', () => { - expect(issue.isFetching.subscriptions).toBe(true); - - issue.setFetchingState('subscriptions', false); - - expect(issue.isFetching.subscriptions).toBe(false); - }); - - it('sets loading state', () => { - issue.setLoadingState('foo', true); - - expect(issue.isLoading.foo).toBe(true); - }); - - describe('update', () => { - it('passes assignee ids when there are assignees', done => { - spyOn(axios, 'patch').and.callFake((url, data) => { - expect(data.issue.assignee_ids).toEqual([1]); - done(); - return Promise.resolve(); - }); - - issue.update('url'); - }); - - it('passes assignee ids of [0] when there are no assignees', done => { - spyOn(axios, 'patch').and.callFake((url, data) => { - expect(data.issue.assignee_ids).toEqual([0]); - done(); - return Promise.resolve(); - }); - - issue.removeAllAssignees(); - issue.update('url'); - }); - }); -}); diff --git a/spec/javascripts/boards/mock_data.js b/spec/javascripts/boards/mock_data.js index fcb5d9cfa08..8b39ad1abb4 100644 --- a/spec/javascripts/boards/mock_data.js +++ b/spec/javascripts/boards/mock_data.js @@ -1,55 +1 @@ -import boardsStore from '~/boards/stores/boards_store'; -import { listObj } from '../../frontend/boards/mock_data'; - export * from '../../frontend/boards/mock_data'; - -export const BoardsMockData = { - GET: { - '/test/-/boards/1/lists/300/issues?id=300&page=1': { - issues: [ - { - title: 'Testing', - id: 1, - iid: 1, - confidential: false, - labels: [], - assignees: [], - }, - ], - }, - '/test/issue-boards/-/milestones.json': [ - { - id: 1, - title: 'test', - }, - ], - }, - POST: { - '/test/-/boards/1/lists': listObj, - }, - PUT: { - '/test/issue-boards/-/board/1/lists{/id}': {}, - }, - DELETE: { - '/test/issue-boards/-/board/1/lists{/id}': {}, - }, -}; - -export const boardsMockInterceptor = config => { - const body = BoardsMockData[config.method.toUpperCase()][config.url]; - return [200, body]; -}; - -export const setMockEndpoints = (opts = {}) => { - const boardsEndpoint = opts.boardsEndpoint || '/test/issue-boards/-/boards.json'; - const listsEndpoint = opts.listsEndpoint || '/test/-/boards/1/lists'; - const bulkUpdatePath = opts.bulkUpdatePath || ''; - const boardId = opts.boardId || '1'; - - boardsStore.setEndpoints({ - boardsEndpoint, - listsEndpoint, - bulkUpdatePath, - boardId, - }); -}; -- cgit v1.2.3