diff options
Diffstat (limited to 'spec/frontend/ide/stores/actions/file_spec.js')
-rw-r--r-- | spec/frontend/ide/stores/actions/file_spec.js | 38 |
1 files changed, 27 insertions, 11 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); }); }); |