diff options
Diffstat (limited to 'spec/frontend/ide/stores')
25 files changed, 248 insertions, 236 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'] = {}; diff --git a/spec/frontend/ide/stores/actions_spec.js b/spec/frontend/ide/stores/actions_spec.js index 04128c27e70..036bc91cd11 100644 --- a/spec/frontend/ide/stores/actions_spec.js +++ b/spec/frontend/ide/stores/actions_spec.js @@ -1,4 +1,5 @@ import MockAdapter from 'axios-mock-adapter'; +import testAction from 'helpers/vuex_action_helper'; import { visitUrl } from '~/lib/utils/url_utility'; import { createStore } from '~/ide/stores'; import { createRouter } from '~/ide/ide_router'; @@ -20,7 +21,6 @@ import { import axios from '~/lib/utils/axios_utils'; import * as types from '~/ide/stores/mutation_types'; import { file, createTriggerRenameAction, createTriggerChangeAction } from '../helpers'; -import testAction from '../../helpers/vuex_action_helper'; import eventHub from '~/ide/eventhub'; jest.mock('~/lib/utils/url_utility', () => ({ @@ -42,7 +42,7 @@ describe('Multi-file store actions', () => { }); describe('redirectToUrl', () => { - it('calls visitUrl', done => { + it('calls visitUrl', (done) => { store .dispatch('redirectToUrl', 'test') .then(() => { @@ -55,7 +55,7 @@ describe('Multi-file store actions', () => { }); describe('setInitialData', () => { - it('commits initial data', done => { + it('commits initial data', (done) => { store .dispatch('setInitialData', { canCommit: true }) .then(() => { @@ -70,7 +70,7 @@ describe('Multi-file store actions', () => { const paths = ['to_discard', 'another_one_to_discard']; beforeEach(() => { - paths.forEach(path => { + paths.forEach((path) => { const f = file(path); f.changed = true; @@ -81,14 +81,14 @@ describe('Multi-file store actions', () => { }); it('discards all changes in file', () => { - const expectedCalls = paths.map(path => ['restoreOriginalFile', path]); + const expectedCalls = paths.map((path) => ['restoreOriginalFile', path]); discardAllChanges(store); expect(store.dispatch.mock.calls).toEqual(expect.arrayContaining(expectedCalls)); }); - it('removes all files from changedFiles state', done => { + it('removes all files from changedFiles state', (done) => { store .dispatch('discardAllChanges') .then(() => { @@ -120,7 +120,7 @@ describe('Multi-file store actions', () => { }); describe('tree', () => { - it('creates temp tree', done => { + it('creates temp tree', (done) => { store .dispatch('createTempEntry', { name: 'test', @@ -137,7 +137,7 @@ describe('Multi-file store actions', () => { .catch(done.fail); }); - it('creates new folder inside another tree', done => { + it('creates new folder inside another tree', (done) => { const tree = { type: 'tree', name: 'testing', @@ -162,7 +162,7 @@ describe('Multi-file store actions', () => { .catch(done.fail); }); - it('does not create new tree if already exists', done => { + it('does not create new tree if already exists', (done) => { const tree = { type: 'tree', path: 'testing', @@ -188,18 +188,20 @@ describe('Multi-file store actions', () => { }); describe('blob', () => { - it('creates temp file', done => { + it('creates temp file', (done) => { const name = 'test'; store .dispatch('createTempEntry', { name, type: 'blob', + mimeType: 'test/mime', }) .then(() => { const f = store.state.entries[name]; expect(f.tempFile).toBeTruthy(); + expect(f.mimeType).toBe('test/mime'); expect(store.state.trees['abcproject/mybranch'].tree.length).toBe(1); done(); @@ -207,7 +209,7 @@ describe('Multi-file store actions', () => { .catch(done.fail); }); - it('adds tmp file to open files', done => { + it('adds tmp file to open files', (done) => { const name = 'test'; store @@ -226,7 +228,7 @@ describe('Multi-file store actions', () => { .catch(done.fail); }); - it('adds tmp file to staged files', done => { + it('adds tmp file to staged files', (done) => { const name = 'test'; store @@ -248,7 +250,7 @@ describe('Multi-file store actions', () => { expect(store.dispatch).toHaveBeenCalledWith('setFileActive', 'test'); }); - it('creates flash message if file already exists', done => { + it('creates flash message if file already exists', (done) => { const f = file('test', '1', 'blob'); store.state.trees['abcproject/mybranch'].tree = [f]; store.state.entries[f.path] = f; @@ -271,7 +273,7 @@ describe('Multi-file store actions', () => { }); describe('scrollToTab', () => { - it('focuses the current active element', done => { + it('focuses the current active element', (done) => { document.body.innerHTML += '<div id="tabs"><div class="active"><div class="repo-tab"></div></div></div>'; const el = document.querySelector('.repo-tab'); @@ -376,7 +378,7 @@ describe('Multi-file store actions', () => { }); describe('updateViewer', () => { - it('updates viewer state', done => { + it('updates viewer state', (done) => { store .dispatch('updateViewer', 'diff') .then(() => { @@ -388,7 +390,7 @@ describe('Multi-file store actions', () => { }); describe('updateActivityBarView', () => { - it('commits UPDATE_ACTIVITY_BAR_VIEW', done => { + it('commits UPDATE_ACTIVITY_BAR_VIEW', (done) => { testAction( updateActivityBarView, 'test', @@ -401,7 +403,7 @@ describe('Multi-file store actions', () => { }); describe('setEmptyStateSvgs', () => { - it('commits setEmptyStateSvgs', done => { + it('commits setEmptyStateSvgs', (done) => { testAction( setEmptyStateSvgs, 'svg', @@ -414,7 +416,7 @@ describe('Multi-file store actions', () => { }); describe('updateTempFlagForEntry', () => { - it('commits UPDATE_TEMP_FLAG', done => { + it('commits UPDATE_TEMP_FLAG', (done) => { const f = { ...file(), path: 'test', @@ -432,7 +434,7 @@ describe('Multi-file store actions', () => { ); }); - it('commits UPDATE_TEMP_FLAG and dispatches for parent', done => { + it('commits UPDATE_TEMP_FLAG and dispatches for parent', (done) => { const parent = { ...file(), path: 'testing', @@ -455,7 +457,7 @@ describe('Multi-file store actions', () => { ); }); - it('does not dispatch for parent, if parent does not exist', done => { + it('does not dispatch for parent, if parent does not exist', (done) => { const f = { ...file(), path: 'test', @@ -475,7 +477,7 @@ describe('Multi-file store actions', () => { }); describe('setCurrentBranchId', () => { - it('commits setCurrentBranchId', done => { + it('commits setCurrentBranchId', (done) => { testAction( setCurrentBranchId, 'branchId', @@ -488,7 +490,7 @@ describe('Multi-file store actions', () => { }); describe('toggleFileFinder', () => { - it('commits TOGGLE_FILE_FINDER', done => { + it('commits TOGGLE_FILE_FINDER', (done) => { testAction( toggleFileFinder, true, @@ -501,7 +503,7 @@ describe('Multi-file store actions', () => { }); describe('setErrorMessage', () => { - it('commis error messsage', done => { + it('commis error messsage', (done) => { testAction( setErrorMessage, 'error', @@ -514,7 +516,7 @@ describe('Multi-file store actions', () => { }); describe('deleteEntry', () => { - it('commits entry deletion', done => { + it('commits entry deletion', (done) => { store.state.entries.path = 'testing'; testAction( @@ -527,7 +529,7 @@ describe('Multi-file store actions', () => { ); }); - it('does not delete a folder after it is emptied', done => { + it('does not delete a folder after it is emptied', (done) => { const testFolder = { type: 'tree', tree: [], @@ -573,7 +575,7 @@ describe('Multi-file store actions', () => { }); describe('and previous does not exist', () => { - it('reverts the rename before deleting', done => { + it('reverts the rename before deleting', (done) => { testAction( deleteEntry, testEntry.path, @@ -608,7 +610,7 @@ describe('Multi-file store actions', () => { store.state.entries[oldEntry.path] = oldEntry; }); - it('does not revert rename before deleting', done => { + it('does not revert rename before deleting', (done) => { testAction( deleteEntry, testEntry.path, @@ -619,7 +621,7 @@ describe('Multi-file store actions', () => { ); }); - it('when previous is deleted, it reverts rename before deleting', done => { + it('when previous is deleted, it reverts rename before deleting', (done) => { store.state.entries[testEntry.prevPath].deleted = true; testAction( @@ -654,7 +656,7 @@ describe('Multi-file store actions', () => { jest.spyOn(eventHub, '$emit').mockImplementation(); }); - it('does not purge model cache for temporary entries that got renamed', done => { + it('does not purge model cache for temporary entries that got renamed', (done) => { Object.assign(store.state.entries, { test: { ...file('test'), @@ -676,7 +678,7 @@ describe('Multi-file store actions', () => { .catch(done.fail); }); - it('purges model cache for renamed entry', done => { + it('purges model cache for renamed entry', (done) => { Object.assign(store.state.entries, { test: { ...file('test'), @@ -735,7 +737,7 @@ describe('Multi-file store actions', () => { ]); }); - it('if not changed, completely unstages and discards entry if renamed to original', done => { + it('if not changed, completely unstages and discards entry if renamed to original', (done) => { testAction( renameEntry, { path: 'renamed', name: 'orig' }, @@ -759,7 +761,7 @@ describe('Multi-file store actions', () => { ); }); - it('if already in changed, does not add to change', done => { + it('if already in changed, does not add to change', (done) => { store.state.changedFiles.push(renamedEntry); testAction( @@ -772,7 +774,7 @@ describe('Multi-file store actions', () => { ); }); - it('routes to the renamed file if the original file has been opened', done => { + it('routes to the renamed file if the original file has been opened', (done) => { store.state.currentProjectId = 'test/test'; store.state.currentBranchId = 'master'; @@ -813,7 +815,7 @@ describe('Multi-file store actions', () => { }); }); - it('updates entries in a folder correctly, when folder is renamed', done => { + it('updates entries in a folder correctly, when folder is renamed', (done) => { store .dispatch('renameEntry', { path: 'folder', @@ -831,7 +833,7 @@ describe('Multi-file store actions', () => { .catch(done.fail); }); - it('discards renaming of an entry if the root folder is renamed back to a previous name', done => { + it('discards renaming of an entry if the root folder is renamed back to a previous name', (done) => { const rootFolder = file('old-folder', 'old-folder', 'tree'); const testEntry = file('test', 'test', 'blob', rootFolder); @@ -923,7 +925,7 @@ describe('Multi-file store actions', () => { }); }); - it('creates new directory', done => { + it('creates new directory', (done) => { expect(store.state.entries[newParentPath]).toBeUndefined(); store @@ -953,7 +955,7 @@ describe('Multi-file store actions', () => { rootDir.tree.push(newDir); }); - it('inserts in new directory', done => { + it('inserts in new directory', (done) => { expect(newDir.tree).toEqual([]); store @@ -969,11 +971,11 @@ describe('Multi-file store actions', () => { .catch(done.fail); }); - it('when new directory is deleted, it undeletes it', done => { + it('when new directory is deleted, it undeletes it', (done) => { store.dispatch('deleteEntry', newParentPath); expect(store.state.entries[newParentPath].deleted).toBe(true); - expect(rootDir.tree.some(x => x.path === newParentPath)).toBe(false); + expect(rootDir.tree.some((x) => x.path === newParentPath)).toBe(false); store .dispatch('renameEntry', { @@ -983,7 +985,7 @@ describe('Multi-file store actions', () => { }) .then(() => { expect(store.state.entries[newParentPath].deleted).toBe(false); - expect(rootDir.tree.some(x => x.path === newParentPath)).toBe(true); + expect(rootDir.tree.some((x) => x.path === newParentPath)).toBe(true); }) .then(done) .catch(done.fail); @@ -1027,12 +1029,12 @@ describe('Multi-file store actions', () => { document.querySelector('.flash-container').remove(); }); - it('passes the error further unchanged without dispatching any action when response is 404', done => { + it('passes the error further unchanged without dispatching any action when response is 404', (done) => { mock.onGet(/(.*)/).replyOnce(404); getBranchData(...callParams) .then(done.fail) - .catch(e => { + .catch((e) => { expect(dispatch.mock.calls).toHaveLength(0); expect(e.response.status).toEqual(404); expect(document.querySelector('.flash-alert')).toBeNull(); @@ -1040,12 +1042,12 @@ describe('Multi-file store actions', () => { }); }); - it('does not pass the error further and flashes an alert if error is not 404', done => { + it('does not pass the error further and flashes an alert if error is not 404', (done) => { mock.onGet(/(.*)/).replyOnce(418); getBranchData(...callParams) .then(done.fail) - .catch(e => { + .catch((e) => { expect(dispatch.mock.calls).toHaveLength(0); expect(e.response).toBeUndefined(); expect(document.querySelector('.flash-alert')).not.toBeNull(); diff --git a/spec/frontend/ide/stores/extend_spec.js b/spec/frontend/ide/stores/extend_spec.js index b0f1063153e..ffb00f9ef5b 100644 --- a/spec/frontend/ide/stores/extend_spec.js +++ b/spec/frontend/ide/stores/extend_spec.js @@ -15,7 +15,7 @@ describe('ide/stores/extend', () => { store = {}; el = {}; - [terminalPlugin, terminalSyncPlugin].forEach(x => { + [terminalPlugin, terminalSyncPlugin].forEach((x) => { const plugin = jest.fn(); x.mockImplementation(() => plugin); @@ -28,7 +28,7 @@ describe('ide/stores/extend', () => { terminalSyncPlugin.mockClear(); }); - const withGonFeatures = features => { + const withGonFeatures = (features) => { global.gon = { ...global.gon, features }; }; diff --git a/spec/frontend/ide/stores/getters_spec.js b/spec/frontend/ide/stores/getters_spec.js index 5ae87f5f9cd..1787f9e9361 100644 --- a/spec/frontend/ide/stores/getters_spec.js +++ b/spec/frontend/ide/stores/getters_spec.js @@ -407,7 +407,7 @@ describe('IDE store getters', () => { ${'canCreateMergeRequests'} | ${'createMergeRequestIn'} ${'canPushCode'} | ${'pushCode'} `('$getterName', ({ getterName, permissionKey }) => { - it.each([true, false])('finds permission for current project (%s)', val => { + it.each([true, false])('finds permission for current project (%s)', (val) => { localState.projects[TEST_PROJECT_ID] = { userPermissions: { [permissionKey]: val, diff --git a/spec/frontend/ide/stores/integration_spec.js b/spec/frontend/ide/stores/integration_spec.js index b6a7c7fd02d..388bd3b99d2 100644 --- a/spec/frontend/ide/stores/integration_spec.js +++ b/spec/frontend/ide/stores/integration_spec.js @@ -84,7 +84,7 @@ describe('IDE store integration', () => { store.dispatch('commit/updateFilesAfterCommit', { data: {} }); expect(store.state.entries[TEST_PATH]).toEqual(expected); - expect(store.state.entries[TEST_PATH_DIR].tree.find(x => x.path === TEST_PATH)).toEqual( + expect(store.state.entries[TEST_PATH_DIR].tree.find((x) => x.path === TEST_PATH)).toEqual( expected, ); }); diff --git a/spec/frontend/ide/stores/modules/branches/actions_spec.js b/spec/frontend/ide/stores/modules/branches/actions_spec.js index 2ab4126cccf..b1c077c4082 100644 --- a/spec/frontend/ide/stores/modules/branches/actions_spec.js +++ b/spec/frontend/ide/stores/modules/branches/actions_spec.js @@ -42,7 +42,7 @@ describe('IDE branches actions', () => { }); describe('requestBranches', () => { - it('should commit request', done => { + it('should commit request', (done) => { testAction( requestBranches, null, @@ -55,7 +55,7 @@ describe('IDE branches actions', () => { }); describe('receiveBranchesError', () => { - it('should commit error', done => { + it('should commit error', (done) => { testAction( receiveBranchesError, { search: TEST_SEARCH }, @@ -78,7 +78,7 @@ describe('IDE branches actions', () => { }); describe('receiveBranchesSuccess', () => { - it('should commit received data', done => { + it('should commit received data', (done) => { testAction( receiveBranchesSuccess, branches, @@ -110,7 +110,7 @@ describe('IDE branches actions', () => { }); }); - it('dispatches success with received data', done => { + it('dispatches success with received data', (done) => { testAction( fetchBranches, { search: TEST_SEARCH }, @@ -131,7 +131,7 @@ describe('IDE branches actions', () => { mock.onGet(/\/api\/v4\/projects\/\d+\/repository\/branches(.*)$/).replyOnce(500); }); - it('dispatches error', done => { + it('dispatches error', (done) => { testAction( fetchBranches, { search: TEST_SEARCH }, @@ -148,7 +148,7 @@ describe('IDE branches actions', () => { }); describe('resetBranches', () => { - it('commits reset', done => { + it('commits reset', (done) => { testAction( resetBranches, null, diff --git a/spec/frontend/ide/stores/modules/branches/mutations_spec.js b/spec/frontend/ide/stores/modules/branches/mutations_spec.js index ed8e05bf299..ddf55479be9 100644 --- a/spec/frontend/ide/stores/modules/branches/mutations_spec.js +++ b/spec/frontend/ide/stores/modules/branches/mutations_spec.js @@ -28,7 +28,7 @@ describe('IDE branches mutations', () => { describe('RECEIVE_BRANCHES_SUCCESS', () => { it('sets branches', () => { - const expectedBranches = branches.map(branch => ({ + const expectedBranches = branches.map((branch) => ({ name: branch.name, committedDate: branch.commit.committed_date, })); diff --git a/spec/frontend/ide/stores/modules/clientside/actions_spec.js b/spec/frontend/ide/stores/modules/clientside/actions_spec.js index a47bc0bd711..05627f8ed0e 100644 --- a/spec/frontend/ide/stores/modules/clientside/actions_spec.js +++ b/spec/frontend/ide/stores/modules/clientside/actions_spec.js @@ -25,7 +25,7 @@ describe('IDE store module clientside actions', () => { }); describe('pingUsage', () => { - it('posts to usage endpoint', done => { + it('posts to usage endpoint', (done) => { const usageSpy = jest.fn(() => [200]); mock.onPost(TEST_USAGE_URL).reply(() => usageSpy()); diff --git a/spec/frontend/ide/stores/modules/commit/actions_spec.js b/spec/frontend/ide/stores/modules/commit/actions_spec.js index cfe2bddf76c..5be0e22a9fc 100644 --- a/spec/frontend/ide/stores/modules/commit/actions_spec.js +++ b/spec/frontend/ide/stores/modules/commit/actions_spec.js @@ -1,6 +1,7 @@ import { file } from 'jest/ide/helpers'; import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; +import testAction from 'helpers/vuex_action_helper'; import { visitUrl } from '~/lib/utils/url_utility'; import { createStore } from '~/ide/stores'; import service from '~/ide/services'; @@ -11,7 +12,6 @@ import * as mutationTypes from '~/ide/stores/modules/commit/mutation_types'; import * as actions from '~/ide/stores/modules/commit/actions'; import { createUnexpectedCommitError } from '~/ide/lib/errors'; import { commitActionTypes, PERMISSION_CREATE_MR } from '~/ide/constants'; -import testAction from '../../../../helpers/vuex_action_helper'; jest.mock('~/lib/utils/url_utility', () => ({ ...jest.requireActual('~/lib/utils/url_utility'), @@ -19,6 +19,17 @@ jest.mock('~/lib/utils/url_utility', () => ({ })); const TEST_COMMIT_SHA = '123456789'; +const COMMIT_RESPONSE = { + id: '123456', + short_id: '123', + message: 'test message', + committed_date: 'date', + parent_ids: [], + stats: { + additions: '1', + deletions: '2', + }, +}; describe('IDE commit module actions', () => { let mock; @@ -32,7 +43,9 @@ describe('IDE commit module actions', () => { mock = new MockAdapter(axios); jest.spyOn(router, 'push').mockImplementation(); - mock.onGet('/api/v1/projects/abcproject/repository/branches/master').reply(200); + mock + .onGet('/api/v1/projects/abcproject/repository/branches/master') + .reply(200, { commit: COMMIT_RESPONSE }); }); afterEach(() => { @@ -41,7 +54,7 @@ describe('IDE commit module actions', () => { }); describe('updateCommitMessage', () => { - it('updates store with new commit message', done => { + it('updates store with new commit message', (done) => { store .dispatch('commit/updateCommitMessage', 'testing') .then(() => { @@ -53,7 +66,7 @@ describe('IDE commit module actions', () => { }); describe('discardDraft', () => { - it('resets commit message to blank', done => { + it('resets commit message to blank', (done) => { store.state.commit.commitMessage = 'testing'; store @@ -67,7 +80,7 @@ describe('IDE commit module actions', () => { }); describe('updateCommitAction', () => { - it('updates store with new commit action', done => { + it('updates store with new commit action', (done) => { store .dispatch('commit/updateCommitAction', '1') .then(() => { @@ -123,7 +136,7 @@ describe('IDE commit module actions', () => { }); }); - it('updates commit message with short_id', done => { + it('updates commit message with short_id', (done) => { store .dispatch('commit/setLastCommitMessage', { short_id: '123' }) .then(() => { @@ -135,7 +148,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('updates commit message with stats', done => { + it('updates commit message with stats', (done) => { store .dispatch('commit/setLastCommitMessage', { short_id: '123', @@ -200,12 +213,12 @@ describe('IDE commit module actions', () => { }); store.state.openFiles = store.state.stagedFiles; - store.state.stagedFiles.forEach(stagedFile => { + store.state.stagedFiles.forEach((stagedFile) => { store.state.entries[stagedFile.path] = stagedFile; }); }); - it('updates stores working reference', done => { + it('updates stores working reference', (done) => { store .dispatch('commit/updateFilesAfterCommit', { data, @@ -218,14 +231,14 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('resets all files changed status', done => { + it('resets all files changed status', (done) => { store .dispatch('commit/updateFilesAfterCommit', { data, branch, }) .then(() => { - store.state.openFiles.forEach(entry => { + store.state.openFiles.forEach((entry) => { expect(entry.changed).toBeFalsy(); }); }) @@ -233,7 +246,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('sets files commit data', done => { + it('sets files commit data', (done) => { store .dispatch('commit/updateFilesAfterCommit', { data, @@ -246,7 +259,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('updates raw content for changed file', done => { + it('updates raw content for changed file', (done) => { store .dispatch('commit/updateFilesAfterCommit', { data, @@ -259,7 +272,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('emits changed event for file', done => { + it('emits changed event for file', (done) => { store .dispatch('commit/updateFilesAfterCommit', { data, @@ -319,7 +332,7 @@ describe('IDE commit module actions', () => { store.state.commit.commitAction = '2'; store.state.commit.commitMessage = 'testing 123'; - store.state.openFiles.forEach(localF => { + store.state.openFiles.forEach((localF) => { store.state.entries[localF.path] = localF; }); }); @@ -329,23 +342,11 @@ describe('IDE commit module actions', () => { }); describe('success', () => { - const COMMIT_RESPONSE = { - id: '123456', - short_id: '123', - message: 'test message', - committed_date: 'date', - parent_ids: '321', - stats: { - additions: '1', - deletions: '2', - }, - }; - beforeEach(() => { jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE }); }); - it('calls service', done => { + it('calls service', (done) => { store .dispatch('commit/commitChanges') .then(() => { @@ -370,7 +371,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('sends lastCommit ID when not creating new branch', done => { + it('sends lastCommit ID when not creating new branch', (done) => { store.state.commit.commitAction = '1'; store @@ -397,7 +398,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('sets last Commit Msg', done => { + it('sets last Commit Msg', (done) => { store .dispatch('commit/commitChanges') .then(() => { @@ -410,7 +411,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('adds commit data to files', done => { + it('adds commit data to files', (done) => { store .dispatch('commit/commitChanges') .then(() => { @@ -423,7 +424,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('resets stores commit actions', done => { + it('resets stores commit actions', (done) => { store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH; store @@ -435,7 +436,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('removes all staged files', done => { + it('removes all staged files', (done) => { store .dispatch('commit/commitChanges') .then(() => { @@ -446,7 +447,7 @@ describe('IDE commit module actions', () => { }); describe('merge request', () => { - it('redirects to new merge request page', done => { + it('redirects to new merge request page', (done) => { jest.spyOn(eventHub, '$on').mockImplementation(); store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH; @@ -456,9 +457,7 @@ describe('IDE commit module actions', () => { .dispatch('commit/commitChanges') .then(() => { expect(visitUrl).toHaveBeenCalledWith( - `webUrl/-/merge_requests/new?merge_request[source_branch]=${ - store.getters['commit/placeholderBranchName'] - }&merge_request[target_branch]=master&nav_source=webide`, + `webUrl/-/merge_requests/new?merge_request[source_branch]=${store.getters['commit/placeholderBranchName']}&merge_request[target_branch]=master&nav_source=webide`, ); done(); @@ -466,7 +465,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('does not redirect to new merge request page when shouldCreateMR is not checked', done => { + it('does not redirect to new merge request page when shouldCreateMR is not checked', (done) => { jest.spyOn(eventHub, '$on').mockImplementation(); store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH; @@ -512,7 +511,7 @@ describe('IDE commit module actions', () => { }); }); - it('shows failed message', done => { + it('shows failed message', (done) => { store .dispatch('commit/commitChanges') .then(() => { @@ -546,19 +545,7 @@ describe('IDE commit module actions', () => { }); describe('first commit of a branch', () => { - const COMMIT_RESPONSE = { - id: '123456', - short_id: '123', - message: 'test message', - committed_date: 'date', - parent_ids: [], - stats: { - additions: '1', - deletions: '2', - }, - }; - - it('commits TOGGLE_EMPTY_STATE mutation on empty repo', done => { + it('commits TOGGLE_EMPTY_STATE mutation on empty repo', (done) => { jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE }); jest.spyOn(store, 'commit'); @@ -575,7 +562,7 @@ describe('IDE commit module actions', () => { .catch(done.fail); }); - it('does not commmit TOGGLE_EMPTY_STATE mutation on existing project', done => { + it('does not commmit TOGGLE_EMPTY_STATE mutation on existing project', (done) => { COMMIT_RESPONSE.parent_ids.push('1234'); jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE }); jest.spyOn(store, 'commit'); @@ -596,7 +583,7 @@ describe('IDE commit module actions', () => { }); describe('toggleShouldCreateMR', () => { - it('commits both toggle and interacting with MR checkbox actions', done => { + it('commits both toggle and interacting with MR checkbox actions', (done) => { testAction( actions.toggleShouldCreateMR, {}, diff --git a/spec/frontend/ide/stores/modules/commit/getters_spec.js b/spec/frontend/ide/stores/modules/commit/getters_spec.js index adbfd7c6835..66ed51dbd13 100644 --- a/spec/frontend/ide/stores/modules/commit/getters_spec.js +++ b/spec/frontend/ide/stores/modules/commit/getters_spec.js @@ -103,7 +103,7 @@ describe('IDE commit module getters', () => { expect(getters.preBuiltCommitMessage(state, null, rootState)).toBe('test commit message'); }); - ['changedFiles', 'stagedFiles'].forEach(key => { + ['changedFiles', 'stagedFiles'].forEach((key) => { it('returns commitMessage with updated file', () => { rootState[key].push({ path: 'test-file', diff --git a/spec/frontend/ide/stores/modules/editor/setup_spec.js b/spec/frontend/ide/stores/modules/editor/setup_spec.js index 71b5d7590c5..659bfb2742f 100644 --- a/spec/frontend/ide/stores/modules/editor/setup_spec.js +++ b/spec/frontend/ide/stores/modules/editor/setup_spec.js @@ -1,8 +1,9 @@ +import { cloneDeep } from 'lodash'; import Vuex from 'vuex'; import eventHub from '~/ide/eventhub'; import { createStoreOptions } from '~/ide/stores'; import { setupFileEditorsSync } from '~/ide/stores/modules/editor/setup'; -import { createTriggerRenamePayload } from '../../../helpers'; +import { createTriggerRenamePayload, createTriggerUpdatePayload } from '../../../helpers'; describe('~/ide/stores/modules/editor/setup', () => { let store; @@ -33,6 +34,14 @@ describe('~/ide/stores/modules/editor/setup', () => { }); }); + it('when files update is emitted, does nothing', () => { + const origState = cloneDeep(store.state); + + eventHub.$emit('ide.files.change', createTriggerUpdatePayload('foo')); + + expect(store.state).toEqual(origState); + }); + it('when files rename is emitted, renames fileEditor', () => { eventHub.$emit('ide.files.change', createTriggerRenamePayload('foo', 'foo_new')); diff --git a/spec/frontend/ide/stores/modules/file_templates/actions_spec.js b/spec/frontend/ide/stores/modules/file_templates/actions_spec.js index 6c1fa163a91..76898e83c7a 100644 --- a/spec/frontend/ide/stores/modules/file_templates/actions_spec.js +++ b/spec/frontend/ide/stores/modules/file_templates/actions_spec.js @@ -20,7 +20,7 @@ describe('IDE file templates actions', () => { }); describe('requestTemplateTypes', () => { - it('commits REQUEST_TEMPLATE_TYPES', done => { + it('commits REQUEST_TEMPLATE_TYPES', (done) => { testAction( actions.requestTemplateTypes, null, @@ -33,7 +33,7 @@ describe('IDE file templates actions', () => { }); describe('receiveTemplateTypesError', () => { - it('commits RECEIVE_TEMPLATE_TYPES_ERROR and dispatches setErrorMessage', done => { + it('commits RECEIVE_TEMPLATE_TYPES_ERROR and dispatches setErrorMessage', (done) => { testAction( actions.receiveTemplateTypesError, null, @@ -55,7 +55,7 @@ describe('IDE file templates actions', () => { }); describe('receiveTemplateTypesSuccess', () => { - it('commits RECEIVE_TEMPLATE_TYPES_SUCCESS', done => { + it('commits RECEIVE_TEMPLATE_TYPES_SUCCESS', (done) => { testAction( actions.receiveTemplateTypesSuccess, 'test', @@ -81,7 +81,7 @@ describe('IDE file templates actions', () => { }); }); - it('rejects if selectedTemplateType is empty', done => { + it('rejects if selectedTemplateType is empty', (done) => { const dispatch = jest.fn().mockName('dispatch'); actions @@ -94,7 +94,7 @@ describe('IDE file templates actions', () => { }); }); - it('dispatches actions', done => { + it('dispatches actions', (done) => { state.selectedTemplateType = { key: 'licenses' }; testAction( @@ -121,7 +121,7 @@ describe('IDE file templates actions', () => { mock.onGet(/api\/(.*)\/templates\/licenses/).replyOnce(500); }); - it('dispatches actions', done => { + it('dispatches actions', (done) => { state.selectedTemplateType = { key: 'licenses' }; testAction( @@ -184,7 +184,7 @@ describe('IDE file templates actions', () => { }); describe('receiveTemplateError', () => { - it('dispatches setErrorMessage', done => { + it('dispatches setErrorMessage', (done) => { testAction( actions.receiveTemplateError, 'test', @@ -217,7 +217,7 @@ describe('IDE file templates actions', () => { .replyOnce(200, { content: 'testing content' }); }); - it('dispatches setFileTemplate if template already has content', done => { + it('dispatches setFileTemplate if template already has content', (done) => { const template = { content: 'already has content' }; testAction( @@ -230,7 +230,7 @@ describe('IDE file templates actions', () => { ); }); - it('dispatches success', done => { + it('dispatches success', (done) => { const template = { key: 'mit' }; state.selectedTemplateType = { key: 'licenses' }; @@ -245,7 +245,7 @@ describe('IDE file templates actions', () => { ); }); - it('dispatches success and uses name key for API call', done => { + it('dispatches success and uses name key for API call', (done) => { const template = { name: 'testing' }; state.selectedTemplateType = { key: 'licenses' }; @@ -266,7 +266,7 @@ describe('IDE file templates actions', () => { mock.onGet(/api\/(.*)\/templates\/licenses\/mit/).replyOnce(500); }); - it('dispatches error', done => { + it('dispatches error', (done) => { const template = { name: 'testing' }; state.selectedTemplateType = { key: 'licenses' }; diff --git a/spec/frontend/ide/stores/modules/merge_requests/actions_spec.js b/spec/frontend/ide/stores/modules/merge_requests/actions_spec.js index ec472ab418f..6594d65f558 100644 --- a/spec/frontend/ide/stores/modules/merge_requests/actions_spec.js +++ b/spec/frontend/ide/stores/modules/merge_requests/actions_spec.js @@ -1,4 +1,5 @@ import MockAdapter from 'axios-mock-adapter'; +import testAction from 'helpers/vuex_action_helper'; import axios from '~/lib/utils/axios_utils'; import state from '~/ide/stores/modules/merge_requests/state'; import * as types from '~/ide/stores/modules/merge_requests/mutation_types'; @@ -10,7 +11,6 @@ import { resetMergeRequests, } from '~/ide/stores/modules/merge_requests/actions'; import { mergeRequests } from '../../../mock_data'; -import testAction from '../../../../helpers/vuex_action_helper'; describe('IDE merge requests actions', () => { let mockedState; @@ -28,7 +28,7 @@ describe('IDE merge requests actions', () => { }); describe('requestMergeRequests', () => { - it('should commit request', done => { + it('should commit request', (done) => { testAction( requestMergeRequests, null, @@ -41,7 +41,7 @@ describe('IDE merge requests actions', () => { }); describe('receiveMergeRequestsError', () => { - it('should commit error', done => { + it('should commit error', (done) => { testAction( receiveMergeRequestsError, { type: 'created', search: '' }, @@ -64,7 +64,7 @@ describe('IDE merge requests actions', () => { }); describe('receiveMergeRequestsSuccess', () => { - it('should commit received data', done => { + it('should commit received data', (done) => { testAction( receiveMergeRequestsSuccess, mergeRequests, @@ -118,7 +118,7 @@ describe('IDE merge requests actions', () => { }); }); - it('dispatches success with received data', done => { + it('dispatches success with received data', (done) => { testAction( fetchMergeRequests, { type: 'created' }, @@ -156,7 +156,7 @@ describe('IDE merge requests actions', () => { ); }); - it('dispatches success with received data', done => { + it('dispatches success with received data', (done) => { testAction( fetchMergeRequests, { type: null }, @@ -177,7 +177,7 @@ describe('IDE merge requests actions', () => { mock.onGet(/\/api\/v4\/merge_requests(.*)$/).replyOnce(500); }); - it('dispatches error', done => { + it('dispatches error', (done) => { testAction( fetchMergeRequests, { type: 'created', search: '' }, @@ -195,7 +195,7 @@ describe('IDE merge requests actions', () => { }); describe('resetMergeRequests', () => { - it('commits reset', done => { + it('commits reset', (done) => { testAction( resetMergeRequests, null, diff --git a/spec/frontend/ide/stores/modules/pane/actions_spec.js b/spec/frontend/ide/stores/modules/pane/actions_spec.js index 8c56714e0ed..42fe8b400b8 100644 --- a/spec/frontend/ide/stores/modules/pane/actions_spec.js +++ b/spec/frontend/ide/stores/modules/pane/actions_spec.js @@ -7,18 +7,18 @@ describe('IDE pane module actions', () => { const TEST_VIEW_KEEP_ALIVE = { name: 'test-keep-alive', keepAlive: true }; describe('toggleOpen', () => { - it('dispatches open if closed', done => { + it('dispatches open if closed', (done) => { testAction(actions.toggleOpen, TEST_VIEW, { isOpen: false }, [], [{ type: 'open' }], done); }); - it('dispatches close if opened', done => { + it('dispatches close if opened', (done) => { testAction(actions.toggleOpen, TEST_VIEW, { isOpen: true }, [], [{ type: 'close' }], done); }); }); describe('open', () => { describe('with a view specified', () => { - it('commits SET_OPEN and SET_CURRENT_VIEW', done => { + it('commits SET_OPEN and SET_CURRENT_VIEW', (done) => { testAction( actions.open, TEST_VIEW, @@ -32,7 +32,7 @@ describe('IDE pane module actions', () => { ); }); - it('commits KEEP_ALIVE_VIEW if keepAlive is true', done => { + it('commits KEEP_ALIVE_VIEW if keepAlive is true', (done) => { testAction( actions.open, TEST_VIEW_KEEP_ALIVE, @@ -49,7 +49,7 @@ describe('IDE pane module actions', () => { }); describe('without a view specified', () => { - it('commits SET_OPEN', done => { + it('commits SET_OPEN', (done) => { testAction( actions.open, undefined, @@ -63,7 +63,7 @@ describe('IDE pane module actions', () => { }); describe('close', () => { - it('commits SET_OPEN', done => { + it('commits SET_OPEN', (done) => { testAction(actions.close, null, {}, [{ type: types.SET_OPEN, payload: false }], [], done); }); }); diff --git a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js index 8511843cc92..b7ed257e954 100644 --- a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js +++ b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js @@ -1,6 +1,7 @@ import Visibility from 'visibilityjs'; import MockAdapter from 'axios-mock-adapter'; import { TEST_HOST } from 'helpers/test_constants'; +import testAction from 'helpers/vuex_action_helper'; import axios from '~/lib/utils/axios_utils'; import { requestLatestPipeline, @@ -24,7 +25,6 @@ import { import state from '~/ide/stores/modules/pipelines/state'; import * as types from '~/ide/stores/modules/pipelines/mutation_types'; import { rightSidebarViews } from '~/ide/constants'; -import testAction from '../../../../helpers/vuex_action_helper'; import { pipelines, jobs } from '../../../mock_data'; describe('IDE pipelines actions', () => { @@ -44,7 +44,7 @@ describe('IDE pipelines actions', () => { }); describe('requestLatestPipeline', () => { - it('commits request', done => { + it('commits request', (done) => { testAction( requestLatestPipeline, null, @@ -57,7 +57,7 @@ describe('IDE pipelines actions', () => { }); describe('receiveLatestPipelineError', () => { - it('commits error', done => { + it('commits error', (done) => { testAction( receiveLatestPipelineError, { status: 404 }, @@ -68,7 +68,7 @@ describe('IDE pipelines actions', () => { ); }); - it('dispatches setErrorMessage is not 404', done => { + it('dispatches setErrorMessage is not 404', (done) => { testAction( receiveLatestPipelineError, { status: 500 }, @@ -123,7 +123,7 @@ describe('IDE pipelines actions', () => { .reply(200, { data: { foo: 'bar' } }, { 'poll-interval': '10000' }); }); - it('dispatches request', done => { + it('dispatches request', (done) => { jest.spyOn(axios, 'get'); jest.spyOn(Visibility, 'hidden').mockReturnValue(false); @@ -139,7 +139,7 @@ describe('IDE pipelines actions', () => { jest.advanceTimersByTime(1000); - new Promise(resolve => requestAnimationFrame(resolve)) + new Promise((resolve) => requestAnimationFrame(resolve)) .then(() => { expect(axios.get).toHaveBeenCalled(); expect(axios.get).toHaveBeenCalledTimes(1); @@ -150,7 +150,7 @@ describe('IDE pipelines actions', () => { jest.advanceTimersByTime(10000); }) - .then(() => new Promise(resolve => requestAnimationFrame(resolve))) + .then(() => new Promise((resolve) => requestAnimationFrame(resolve))) .then(() => { expect(axios.get).toHaveBeenCalled(); expect(axios.get).toHaveBeenCalledTimes(2); @@ -169,7 +169,7 @@ describe('IDE pipelines actions', () => { mock.onGet('/abc/def/commit/abc123def456ghi789jkl/pipelines').reply(500); }); - it('dispatches error', done => { + it('dispatches error', (done) => { const dispatch = jest.fn().mockName('dispatch'); const rootGetters = { lastCommit: { id: 'abc123def456ghi789jkl' }, @@ -180,7 +180,7 @@ describe('IDE pipelines actions', () => { jest.advanceTimersByTime(1500); - new Promise(resolve => requestAnimationFrame(resolve)) + new Promise((resolve) => requestAnimationFrame(resolve)) .then(() => { expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineError', expect.anything()); }) @@ -191,13 +191,13 @@ describe('IDE pipelines actions', () => { }); describe('requestJobs', () => { - it('commits request', done => { + it('commits request', (done) => { testAction(requestJobs, 1, mockedState, [{ type: types.REQUEST_JOBS, payload: 1 }], [], done); }); }); describe('receiveJobsError', () => { - it('commits error', done => { + it('commits error', (done) => { testAction( receiveJobsError, { id: 1 }, @@ -220,7 +220,7 @@ describe('IDE pipelines actions', () => { }); describe('receiveJobsSuccess', () => { - it('commits data', done => { + it('commits data', (done) => { testAction( receiveJobsSuccess, { id: 1, data: jobs }, @@ -240,7 +240,7 @@ describe('IDE pipelines actions', () => { mock.onGet(stage.dropdownPath).replyOnce(200, jobs); }); - it('dispatches request', done => { + it('dispatches request', (done) => { testAction( fetchJobs, stage, @@ -260,7 +260,7 @@ describe('IDE pipelines actions', () => { mock.onGet(stage.dropdownPath).replyOnce(500); }); - it('dispatches error', done => { + it('dispatches error', (done) => { testAction( fetchJobs, stage, @@ -277,7 +277,7 @@ describe('IDE pipelines actions', () => { }); describe('toggleStageCollapsed', () => { - it('commits collapse', done => { + it('commits collapse', (done) => { testAction( toggleStageCollapsed, 1, @@ -290,7 +290,7 @@ describe('IDE pipelines actions', () => { }); describe('setDetailJob', () => { - it('commits job', done => { + it('commits job', (done) => { testAction( setDetailJob, 'job', @@ -301,7 +301,7 @@ describe('IDE pipelines actions', () => { ); }); - it('dispatches rightPane/open as pipeline when job is null', done => { + it('dispatches rightPane/open as pipeline when job is null', (done) => { testAction( setDetailJob, null, @@ -312,7 +312,7 @@ describe('IDE pipelines actions', () => { ); }); - it('dispatches rightPane/open as job', done => { + it('dispatches rightPane/open as job', (done) => { testAction( setDetailJob, 'job', @@ -325,13 +325,13 @@ describe('IDE pipelines actions', () => { }); describe('requestJobLogs', () => { - it('commits request', done => { + it('commits request', (done) => { testAction(requestJobLogs, null, mockedState, [{ type: types.REQUEST_JOB_LOGS }], [], done); }); }); describe('receiveJobLogsError', () => { - it('commits error', done => { + it('commits error', (done) => { testAction( receiveJobLogsError, null, @@ -354,7 +354,7 @@ describe('IDE pipelines actions', () => { }); describe('receiveJobLogsSuccess', () => { - it('commits data', done => { + it('commits data', (done) => { testAction( receiveJobLogsSuccess, 'data', @@ -377,7 +377,7 @@ describe('IDE pipelines actions', () => { mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(200, { html: 'html' }); }); - it('dispatches request', done => { + it('dispatches request', (done) => { testAction( fetchJobLogs, null, @@ -408,7 +408,7 @@ describe('IDE pipelines actions', () => { mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(500); }); - it('dispatches error', done => { + it('dispatches error', (done) => { testAction( fetchJobLogs, null, @@ -422,7 +422,7 @@ describe('IDE pipelines actions', () => { }); describe('resetLatestPipeline', () => { - it('commits reset mutations', done => { + it('commits reset mutations', (done) => { testAction( resetLatestPipeline, null, diff --git a/spec/frontend/ide/stores/modules/pipelines/mutations_spec.js b/spec/frontend/ide/stores/modules/pipelines/mutations_spec.js index 7d2f5d5d710..d820bf0291e 100644 --- a/spec/frontend/ide/stores/modules/pipelines/mutations_spec.js +++ b/spec/frontend/ide/stores/modules/pipelines/mutations_spec.js @@ -137,7 +137,7 @@ describe('IDE pipelines mutations', () => { mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, { id: mockedState.stages[0].id, data }); expect(mockedState.stages[0].jobs.length).toBe(jobs.length); expect(mockedState.stages[0].jobs).toEqual( - jobs.map(job => ({ + jobs.map((job) => ({ id: job.id, name: job.name, status: job.status, diff --git a/spec/frontend/ide/stores/modules/terminal/actions/checks_spec.js b/spec/frontend/ide/stores/modules/terminal/actions/checks_spec.js index 242b1579be7..05935f1db38 100644 --- a/spec/frontend/ide/stores/modules/terminal/actions/checks_spec.js +++ b/spec/frontend/ide/stores/modules/terminal/actions/checks_spec.js @@ -102,7 +102,7 @@ describe('IDE store terminal check actions', () => { ); }); - [httpStatus.FORBIDDEN, httpStatus.NOT_FOUND].forEach(status => { + [httpStatus.FORBIDDEN, httpStatus.NOT_FOUND].forEach((status) => { it(`hides tab, when status is ${status}`, () => { const payload = { response: { status } }; diff --git a/spec/frontend/ide/stores/modules/terminal/actions/session_controls_spec.js b/spec/frontend/ide/stores/modules/terminal/actions/session_controls_spec.js index d0ac2af3ffd..dd51786745f 100644 --- a/spec/frontend/ide/stores/modules/terminal/actions/session_controls_spec.js +++ b/spec/frontend/ide/stores/modules/terminal/actions/session_controls_spec.js @@ -281,7 +281,7 @@ describe('IDE store terminal session controls actions', () => { ); }); - [httpStatus.NOT_FOUND, httpStatus.UNPROCESSABLE_ENTITY].forEach(status => { + [httpStatus.NOT_FOUND, httpStatus.UNPROCESSABLE_ENTITY].forEach((status) => { it(`dispatches request and startSession on ${status}`, () => { mock .onPost(state.session.retryPath, { branch: rootState.currentBranchId, format: 'json' }) diff --git a/spec/frontend/ide/stores/modules/terminal/actions/session_status_spec.js b/spec/frontend/ide/stores/modules/terminal/actions/session_status_spec.js index e25746e1dd1..0e123dce798 100644 --- a/spec/frontend/ide/stores/modules/terminal/actions/session_status_spec.js +++ b/spec/frontend/ide/stores/modules/terminal/actions/session_status_spec.js @@ -98,7 +98,7 @@ describe('IDE store terminal session controls actions', () => { ); }); - [STOPPING, STOPPED, 'unexpected'].forEach(status => { + [STOPPING, STOPPED, 'unexpected'].forEach((status) => { it(`kills session if status is ${status}`, () => { return testAction( actions.receiveSessionStatusSuccess, diff --git a/spec/frontend/ide/stores/modules/terminal_sync/actions_spec.js b/spec/frontend/ide/stores/modules/terminal_sync/actions_spec.js index 3fa57bde415..2ae7e8a8727 100644 --- a/spec/frontend/ide/stores/modules/terminal_sync/actions_spec.js +++ b/spec/frontend/ide/stores/modules/terminal_sync/actions_spec.js @@ -22,7 +22,7 @@ describe('ide/stores/modules/terminal_sync/actions', () => { }); describe('upload', () => { - it('uploads to mirror and sets success', done => { + it('uploads to mirror and sets success', (done) => { mirror.upload.mockReturnValue(Promise.resolve()); testAction( @@ -38,7 +38,7 @@ describe('ide/stores/modules/terminal_sync/actions', () => { ); }); - it('sets error when failed', done => { + it('sets error when failed', (done) => { const err = { message: 'it failed!' }; mirror.upload.mockReturnValue(Promise.reject(err)); @@ -54,7 +54,7 @@ describe('ide/stores/modules/terminal_sync/actions', () => { }); describe('stop', () => { - it('disconnects from mirror', done => { + it('disconnects from mirror', (done) => { testAction(actions.stop, null, rootState, [{ type: types.STOP }], [], () => { expect(mirror.disconnect).toHaveBeenCalled(); done(); @@ -83,7 +83,7 @@ describe('ide/stores/modules/terminal_sync/actions', () => { }; }); - it('connects to mirror and sets success', done => { + it('connects to mirror and sets success', (done) => { mirror.connect.mockReturnValue(Promise.resolve()); testAction( diff --git a/spec/frontend/ide/stores/mutations/file_spec.js b/spec/frontend/ide/stores/mutations/file_spec.js index fd39cf21635..9bbdac0ae25 100644 --- a/spec/frontend/ide/stores/mutations/file_spec.js +++ b/spec/frontend/ide/stores/mutations/file_spec.js @@ -128,7 +128,7 @@ describe('IDE store file mutations', () => { localState.changedFiles[0], localState.openFiles[0], localFile, - ].forEach(f => { + ].forEach((f) => { expect(f).toEqual( expect.objectContaining({ path, @@ -142,7 +142,7 @@ describe('IDE store file mutations', () => { }); describe('SET_FILE_RAW_DATA', () => { - const callMutationForFile = f => { + const callMutationForFile = (f) => { mutations.SET_FILE_RAW_DATA(localState, { file: f, raw: 'testing', diff --git a/spec/frontend/ide/stores/plugins/terminal_sync_spec.js b/spec/frontend/ide/stores/plugins/terminal_sync_spec.js index 2aa3e770e7d..0e5f4184679 100644 --- a/spec/frontend/ide/stores/plugins/terminal_sync_spec.js +++ b/spec/frontend/ide/stores/plugins/terminal_sync_spec.js @@ -4,6 +4,7 @@ import { SET_SESSION_STATUS } from '~/ide/stores/modules/terminal/mutation_types import { RUNNING, STOPPING } from '~/ide/stores/modules/terminal/constants'; import { createStore } from '~/ide/stores'; import eventHub from '~/ide/eventhub'; +import { createTriggerUpdatePayload } from '../../helpers'; jest.mock('~/ide/lib/mirror'); @@ -51,6 +52,14 @@ describe('IDE stores/plugins/mirror', () => { expect(store.dispatch).toHaveBeenCalledWith(ACTION_UPLOAD); }); + it('does nothing when ide.files.change is emitted with "update"', () => { + eventHub.$emit(FILES_CHANGE_EVENT, createTriggerUpdatePayload('foo')); + + jest.runAllTimers(); + + expect(store.dispatch).not.toHaveBeenCalledWith(ACTION_UPLOAD); + }); + describe('when session stops', () => { beforeEach(() => { store.commit(`terminal/${SET_SESSION_STATUS}`, STOPPING); |