diff options
Diffstat (limited to 'spec/frontend/ide/stores/actions')
-rw-r--r-- | spec/frontend/ide/stores/actions/file_spec.js | 38 | ||||
-rw-r--r-- | spec/frontend/ide/stores/actions/merge_request_spec.js | 38 | ||||
-rw-r--r-- | spec/frontend/ide/stores/actions/project_spec.js | 30 | ||||
-rw-r--r-- | spec/frontend/ide/stores/actions/tree_spec.js | 29 |
4 files changed, 70 insertions, 65 deletions
diff --git a/spec/frontend/ide/stores/actions/file_spec.js b/spec/frontend/ide/stores/actions/file_spec.js index 744ac086b5f..9d367714bbe 100644 --- a/spec/frontend/ide/stores/actions/file_spec.js +++ b/spec/frontend/ide/stores/actions/file_spec.js @@ -7,7 +7,7 @@ import * as types from '~/ide/stores/mutation_types'; import service from '~/ide/services'; import { createRouter } from '~/ide/ide_router'; import eventHub from '~/ide/eventhub'; -import { file, createTriggerRenameAction } from '../../helpers'; +import { file, createTriggerRenameAction, createTriggerUpdatePayload } from '../../helpers'; const ORIGINAL_CONTENT = 'original content'; const RELATIVE_URL_ROOT = '/gitlab'; @@ -75,7 +75,7 @@ describe('IDE store file actions', () => { }); }); - it('closes file & opens next available file', () => { + it('switches to the next available file before closing the current one ', () => { const f = file('newOpenFile'); store.state.openFiles.push(f); @@ -90,10 +90,12 @@ describe('IDE store file actions', () => { }); it('removes file if it pending', () => { - store.state.openFiles.push({ - ...localFile, - pending: true, - }); + store.state.openFiles = [ + { + ...localFile, + pending: true, + }, + ]; return store.dispatch('closeFile', localFile).then(() => { expect(store.state.openFiles.length).toBe(0); @@ -189,7 +191,7 @@ describe('IDE store file actions', () => { }); describe('call to service', () => { - const callExpectation = serviceCalled => { + const callExpectation = (serviceCalled) => { store.dispatch('getFileData', { path: localFile.path }); if (serviceCalled) { @@ -422,11 +424,11 @@ describe('IDE store file actions', () => { loadingWhenGettingRawData = undefined; loadingWhenGettingBaseRawData = undefined; - jest.spyOn(service, 'getRawFileData').mockImplementation(f => { + jest.spyOn(service, 'getRawFileData').mockImplementation((f) => { loadingWhenGettingRawData = f.loading; return Promise.resolve('raw'); }); - jest.spyOn(service, 'getBaseRawFileData').mockImplementation(f => { + jest.spyOn(service, 'getBaseRawFileData').mockImplementation((f) => { loadingWhenGettingBaseRawData = f.loading; return Promise.resolve('rawBase'); }); @@ -510,12 +512,15 @@ describe('IDE store file actions', () => { describe('changeFileContent', () => { let tmpFile; + let onFilesChange; beforeEach(() => { tmpFile = file('tmpFile'); tmpFile.content = '\n'; tmpFile.raw = '\n'; store.state.entries[tmpFile.path] = tmpFile; + onFilesChange = jest.fn(); + eventHub.$on('ide.files.change', onFilesChange); }); it('updates file content', () => { @@ -580,6 +585,17 @@ describe('IDE store file actions', () => { expect(store.state.changedFiles.length).toBe(0); }); }); + + it('triggers ide.files.change', async () => { + expect(onFilesChange).not.toHaveBeenCalled(); + + await store.dispatch('changeFileContent', { + path: tmpFile.path, + content: 'content\n', + }); + + expect(onFilesChange).toHaveBeenCalledWith(createTriggerUpdatePayload(tmpFile.path)); + }); }); describe('with changed file', () => { @@ -743,7 +759,7 @@ describe('IDE store file actions', () => { }); it('returns true when opened', () => { - return store.dispatch('openPendingTab', { file: f, keyPrefix: 'pending' }).then(added => { + return store.dispatch('openPendingTab', { file: f, keyPrefix: 'pending' }).then((added) => { expect(added).toBe(true); }); }); @@ -755,7 +771,7 @@ describe('IDE store file actions', () => { key: `pending-${f.key}`, }); - return store.dispatch('openPendingTab', { file: f, keyPrefix: 'pending' }).then(added => { + return store.dispatch('openPendingTab', { file: f, keyPrefix: 'pending' }).then((added) => { expect(added).toBe(false); }); }); diff --git a/spec/frontend/ide/stores/actions/merge_request_spec.js b/spec/frontend/ide/stores/actions/merge_request_spec.js index b1cceda9d85..9b17d95ea35 100644 --- a/spec/frontend/ide/stores/actions/merge_request_spec.js +++ b/spec/frontend/ide/stores/actions/merge_request_spec.js @@ -49,7 +49,7 @@ describe('IDE store merge request actions', () => { mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, mockData); }); - it('calls getProjectMergeRequests service method', done => { + it('calls getProjectMergeRequests service method', (done) => { store .dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) .then(() => { @@ -66,19 +66,19 @@ describe('IDE store merge request actions', () => { .catch(done.fail); }); - it('sets the "Merge Request" Object', done => { + it('sets the "Merge Request" Object', (done) => { store .dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) .then(() => { expect(store.state.projects.abcproject.mergeRequests).toEqual({ - '2': expect.objectContaining(mrData), + 2: expect.objectContaining(mrData), }); done(); }) .catch(done.fail); }); - it('sets "Current Merge Request" object to the most recent MR', done => { + it('sets "Current Merge Request" object to the most recent MR', (done) => { store .dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) .then(() => { @@ -88,7 +88,7 @@ describe('IDE store merge request actions', () => { .catch(done.fail); }); - it('does nothing if user cannot read MRs', done => { + it('does nothing if user cannot read MRs', (done) => { store.state.projects[TEST_PROJECT].userPermissions[PERMISSION_READ_MR] = false; store @@ -108,7 +108,7 @@ describe('IDE store merge request actions', () => { mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, []); }); - it('does not fail if there are no merge requests for current branch', done => { + it('does not fail if there are no merge requests for current branch', (done) => { store .dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'foo' }) .then(() => { @@ -126,7 +126,7 @@ describe('IDE store merge request actions', () => { mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).networkError(); }); - it('flashes message, if error', done => { + it('flashes message, if error', (done) => { store .dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) .catch(() => { @@ -149,7 +149,7 @@ describe('IDE store merge request actions', () => { .reply(200, { title: 'mergerequest' }); }); - it('calls getProjectMergeRequestData service method', done => { + it('calls getProjectMergeRequestData service method', (done) => { store .dispatch('getMergeRequestData', { projectId: TEST_PROJECT, mergeRequestId: 1 }) .then(() => { @@ -160,7 +160,7 @@ describe('IDE store merge request actions', () => { .catch(done.fail); }); - it('sets the Merge Request Object', done => { + it('sets the Merge Request Object', (done) => { store .dispatch('getMergeRequestData', { projectId: TEST_PROJECT, mergeRequestId: 1 }) .then(() => { @@ -180,7 +180,7 @@ describe('IDE store merge request actions', () => { mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/).networkError(); }); - it('dispatches error action', done => { + it('dispatches error action', (done) => { const dispatch = jest.fn(); getMergeRequestData( @@ -224,7 +224,7 @@ describe('IDE store merge request actions', () => { .reply(200, { title: 'mergerequest' }); }); - it('calls getProjectMergeRequestChanges service method', done => { + it('calls getProjectMergeRequestChanges service method', (done) => { store .dispatch('getMergeRequestChanges', { projectId: TEST_PROJECT, mergeRequestId: 1 }) .then(() => { @@ -235,7 +235,7 @@ describe('IDE store merge request actions', () => { .catch(done.fail); }); - it('sets the Merge Request Changes Object', done => { + it('sets the Merge Request Changes Object', (done) => { store .dispatch('getMergeRequestChanges', { projectId: TEST_PROJECT, mergeRequestId: 1 }) .then(() => { @@ -253,7 +253,7 @@ describe('IDE store merge request actions', () => { mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/).networkError(); }); - it('dispatches error action', done => { + it('dispatches error action', (done) => { const dispatch = jest.fn(); getMergeRequestChanges( @@ -296,7 +296,7 @@ describe('IDE store merge request actions', () => { jest.spyOn(service, 'getProjectMergeRequestVersions'); }); - it('calls getProjectMergeRequestVersions service method', done => { + it('calls getProjectMergeRequestVersions service method', (done) => { store .dispatch('getMergeRequestVersions', { projectId: TEST_PROJECT, mergeRequestId: 1 }) .then(() => { @@ -307,7 +307,7 @@ describe('IDE store merge request actions', () => { .catch(done.fail); }); - it('sets the Merge Request Versions Object', done => { + it('sets the Merge Request Versions Object', (done) => { store .dispatch('getMergeRequestVersions', { projectId: TEST_PROJECT, mergeRequestId: 1 }) .then(() => { @@ -323,7 +323,7 @@ describe('IDE store merge request actions', () => { mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/).networkError(); }); - it('dispatches error action', done => { + it('dispatches error action', (done) => { const dispatch = jest.fn(); getMergeRequestVersions( @@ -422,7 +422,7 @@ describe('IDE store merge request actions', () => { ); }); - it('dispatches actions for merge request data', done => { + it('dispatches actions for merge request data', (done) => { openMergeRequest({ state: store.state, dispatch: store.dispatch, getters: mockGetters }, mr) .then(() => { expect(store.dispatch.mock.calls).toEqual([ @@ -451,7 +451,7 @@ describe('IDE store merge request actions', () => { .catch(done.fail); }); - it('updates activity bar view and gets file data, if changes are found', done => { + it('updates activity bar view and gets file data, if changes are found', (done) => { store.state.entries.foo = { type: 'blob', }; @@ -490,7 +490,7 @@ describe('IDE store merge request actions', () => { .catch(done.fail); }); - it('flashes message, if error', done => { + it('flashes message, if error', (done) => { store.dispatch.mockRejectedValue(); openMergeRequest(store, mr) diff --git a/spec/frontend/ide/stores/actions/project_spec.js b/spec/frontend/ide/stores/actions/project_spec.js index ca3687307a9..1244c8af91a 100644 --- a/spec/frontend/ide/stores/actions/project_spec.js +++ b/spec/frontend/ide/stores/actions/project_spec.js @@ -53,7 +53,7 @@ describe('IDE store project actions', () => { }); }); - it('calls the service', done => { + it('calls the service', (done) => { store .dispatch('refreshLastCommitData', { projectId: store.state.currentProjectId, @@ -67,7 +67,7 @@ describe('IDE store project actions', () => { .catch(done.fail); }); - it('commits getBranchData', done => { + it('commits getBranchData', (done) => { testAction( refreshLastCommitData, { @@ -94,7 +94,7 @@ describe('IDE store project actions', () => { }); describe('showBranchNotFoundError', () => { - it('dispatches setErrorMessage', done => { + it('dispatches setErrorMessage', (done) => { testAction( showBranchNotFoundError, 'master', @@ -123,7 +123,7 @@ describe('IDE store project actions', () => { jest.spyOn(api, 'createBranch').mockResolvedValue(); }); - it('calls API', done => { + it('calls API', (done) => { createNewBranchFromDefault( { state: { @@ -148,7 +148,7 @@ describe('IDE store project actions', () => { .catch(done.fail); }); - it('clears error message', done => { + it('clears error message', (done) => { const dispatchSpy = jest.fn().mockName('dispatch'); createNewBranchFromDefault( @@ -172,7 +172,7 @@ describe('IDE store project actions', () => { .catch(done.fail); }); - it('reloads window', done => { + it('reloads window', (done) => { createNewBranchFromDefault( { state: { @@ -196,7 +196,7 @@ describe('IDE store project actions', () => { }); describe('loadEmptyBranch', () => { - it('creates a blank tree and sets loading state to false', done => { + it('creates a blank tree and sets loading state to false', (done) => { testAction( loadEmptyBranch, { projectId: TEST_PROJECT_ID, branchId: 'master' }, @@ -213,7 +213,7 @@ describe('IDE store project actions', () => { ); }); - it('does nothing, if tree already exists', done => { + it('does nothing, if tree already exists', (done) => { const trees = { [`${TEST_PROJECT_ID}/master`]: [] }; testAction( @@ -279,7 +279,7 @@ describe('IDE store project actions', () => { const branchId = '123-lorem'; const ref = 'abcd2322'; - it('when empty repo, loads empty branch', done => { + it('when empty repo, loads empty branch', (done) => { const mockGetters = { emptyRepo: true }; testAction( @@ -292,13 +292,13 @@ describe('IDE store project actions', () => { ); }); - it('when branch already exists, does nothing', done => { + it('when branch already exists, does nothing', (done) => { store.state.projects[projectId].branches[branchId] = {}; testAction(loadBranch, { projectId, branchId }, store.state, [], [], done); }); - it('fetches branch data', done => { + it('fetches branch data', (done) => { const mockGetters = { findBranch: () => ({ commit: { id: ref } }) }; jest.spyOn(store, 'dispatch').mockResolvedValue(); @@ -317,7 +317,7 @@ describe('IDE store project actions', () => { .catch(done.fail); }); - it('shows an error if branch can not be fetched', done => { + it('shows an error if branch can not be fetched', (done) => { jest.spyOn(store, 'dispatch').mockReturnValue(Promise.reject()); loadBranch(store, { projectId, branchId }) @@ -356,7 +356,7 @@ describe('IDE store project actions', () => { jest.spyOn(store, 'dispatch').mockResolvedValue(); }); - it('dispatches branch actions', done => { + it('dispatches branch actions', (done) => { openBranch(store, branch) .then(() => { expect(store.dispatch.mock.calls).toEqual([ @@ -375,9 +375,9 @@ describe('IDE store project actions', () => { jest.spyOn(store, 'dispatch').mockReturnValue(Promise.reject()); }); - it('dispatches correct branch actions', done => { + it('dispatches correct branch actions', (done) => { openBranch(store, branch) - .then(val => { + .then((val) => { expect(store.dispatch.mock.calls).toEqual([ ['setCurrentBranchId', branchId], ['loadBranch', { projectId, branchId }], diff --git a/spec/frontend/ide/stores/actions/tree_spec.js b/spec/frontend/ide/stores/actions/tree_spec.js index 0eabd982d57..7831df9f3a4 100644 --- a/spec/frontend/ide/stores/actions/tree_spec.js +++ b/spec/frontend/ide/stores/actions/tree_spec.js @@ -1,6 +1,6 @@ import MockAdapter from 'axios-mock-adapter'; import testAction from 'helpers/vuex_action_helper'; -import { TEST_HOST } from 'jest/helpers/test_constants'; +import { TEST_HOST } from 'helpers/test_constants'; import { showTreeEntry, getFiles, setDirectoryData } from '~/ide/stores/actions/tree'; import * as types from '~/ide/stores/mutation_types'; import axios from '~/lib/utils/axios_utils'; @@ -57,26 +57,15 @@ describe('Multi-file store tree actions', () => { }); it('calls service getFiles', () => { - return ( - store - .dispatch('getFiles', basicCallParameters) - // getFiles actions calls lodash.defer - .then(() => jest.runOnlyPendingTimers()) - .then(() => { - expect(service.getFiles).toHaveBeenCalledWith('foo/abcproject', '12345678'); - }) - ); + return store.dispatch('getFiles', basicCallParameters).then(() => { + expect(service.getFiles).toHaveBeenCalledWith('foo/abcproject', '12345678'); + }); }); - it('adds data into tree', done => { + it('adds data into tree', (done) => { store .dispatch('getFiles', basicCallParameters) .then(() => { - // The populating of the tree is deferred for performance reasons. - // See this merge request for details: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/25700 - jest.advanceTimersByTime(1); - }) - .then(() => { projectTree = store.state.trees['abcproject/master']; expect(projectTree.tree.length).toBe(2); @@ -93,7 +82,7 @@ describe('Multi-file store tree actions', () => { }); describe('error', () => { - it('dispatches error action', done => { + it('dispatches error action', (done) => { const dispatch = jest.fn(); store.state.projects = { @@ -148,7 +137,7 @@ describe('Multi-file store tree actions', () => { store.state.entries[tree.path] = tree; }); - it('toggles the tree open', done => { + it('toggles the tree open', (done) => { store .dispatch('toggleTreeOpen', tree.path) .then(() => { @@ -174,7 +163,7 @@ describe('Multi-file store tree actions', () => { Object.assign(store.state.entries, createEntriesFromPaths(paths)); }); - it('opens the parents', done => { + it('opens the parents', (done) => { testAction( showTreeEntry, 'grandparent/parent/child.txt', @@ -187,7 +176,7 @@ describe('Multi-file store tree actions', () => { }); describe('setDirectoryData', () => { - it('sets tree correctly if there are no opened files yet', done => { + it('sets tree correctly if there are no opened files yet', (done) => { const treeFile = file({ name: 'README.md' }); store.state.trees['abcproject/master'] = {}; |