diff options
Diffstat (limited to 'spec/frontend/ide/stores')
-rw-r--r-- | spec/frontend/ide/stores/actions/file_spec.js | 26 | ||||
-rw-r--r-- | spec/frontend/ide/stores/actions/merge_request_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/ide/stores/actions_spec.js | 15 | ||||
-rw-r--r-- | spec/frontend/ide/stores/getters_spec.js | 45 | ||||
-rw-r--r-- | spec/frontend/ide/stores/integration_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/ide/stores/modules/commit/actions_spec.js | 22 | ||||
-rw-r--r-- | spec/frontend/ide/stores/modules/commit/mutations_spec.js | 21 | ||||
-rw-r--r-- | spec/frontend/ide/stores/modules/pipelines/actions_spec.js | 40 | ||||
-rw-r--r-- | spec/frontend/ide/stores/modules/pipelines/mutations_spec.js | 12 | ||||
-rw-r--r-- | spec/frontend/ide/stores/mutations/file_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/ide/stores/mutations_spec.js | 18 |
11 files changed, 133 insertions, 72 deletions
diff --git a/spec/frontend/ide/stores/actions/file_spec.js b/spec/frontend/ide/stores/actions/file_spec.js index 88e7a9fff36..974c0715c06 100644 --- a/spec/frontend/ide/stores/actions/file_spec.js +++ b/spec/frontend/ide/stores/actions/file_spec.js @@ -27,6 +27,10 @@ describe('IDE store file actions', () => { }; store = createStore(); + + store.state.currentProjectId = 'test/test'; + store.state.currentBranchId = 'master'; + router = createRouter(store); jest.spyOn(store, 'commit'); @@ -72,10 +76,7 @@ describe('IDE store file actions', () => { }); it('closes file & opens next available file', () => { - const f = { - ...file('newOpenFile'), - url: '/newOpenFile', - }; + const f = file('newOpenFile'); store.state.openFiles.push(f); store.state.entries[f.path] = f; @@ -84,7 +85,7 @@ describe('IDE store file actions', () => { .dispatch('closeFile', localFile) .then(Vue.nextTick) .then(() => { - expect(router.push).toHaveBeenCalledWith(`/project${f.url}`); + expect(router.push).toHaveBeenCalledWith('/project/test/test/tree/master/-/newOpenFile/'); }); }); @@ -240,7 +241,6 @@ describe('IDE store file actions', () => { 200, { raw_path: 'raw_path', - binary: false, }, { 'page-title': 'testing getFileData', @@ -296,7 +296,6 @@ describe('IDE store file actions', () => { describe('Re-named success', () => { beforeEach(() => { localFile = file(`newCreate-${Math.random()}`); - localFile.url = `project/getFileDataURL`; localFile.prevPath = 'old-dull-file'; localFile.path = 'new-shiny-file'; store.state.entries[localFile.path] = localFile; @@ -305,7 +304,6 @@ describe('IDE store file actions', () => { 200, { raw_path: 'raw_path', - binary: false, }, { 'page-title': 'testing old-dull-file', @@ -393,7 +391,11 @@ describe('IDE store file actions', () => { tmpFile.mrChange = { new_file: false }; return store.dispatch('getRawFileData', { path: tmpFile.path }).then(() => { - expect(service.getBaseRawFileData).toHaveBeenCalledWith(tmpFile, 'SHA'); + expect(service.getBaseRawFileData).toHaveBeenCalledWith( + tmpFile, + 'gitlab-org/gitlab-ce', + 'SHA', + ); expect(tmpFile.baseRaw).toBe('baseraw'); }); }); @@ -660,7 +662,7 @@ describe('IDE store file actions', () => { }); it('pushes route for active file', () => { - expect(router.push).toHaveBeenCalledWith(`/project${tmpFile.url}`); + expect(router.push).toHaveBeenCalledWith('/project/test/test/tree/master/-/tempFile/'); }); }); }); @@ -735,10 +737,8 @@ describe('IDE store file actions', () => { }); it('pushes router URL when added', () => { - store.state.currentBranchId = 'master'; - return store.dispatch('openPendingTab', { file: f, keyPrefix: 'pending' }).then(() => { - expect(router.push).toHaveBeenCalledWith('/project/123/tree/master/'); + expect(router.push).toHaveBeenCalledWith('/project/test/test/tree/master/'); }); }); }); diff --git a/spec/frontend/ide/stores/actions/merge_request_spec.js b/spec/frontend/ide/stores/actions/merge_request_spec.js index 62971b9cad6..b1cceda9d85 100644 --- a/spec/frontend/ide/stores/actions/merge_request_spec.js +++ b/spec/frontend/ide/stores/actions/merge_request_spec.js @@ -453,11 +453,9 @@ describe('IDE store merge request actions', () => { it('updates activity bar view and gets file data, if changes are found', done => { store.state.entries.foo = { - url: 'test', type: 'blob', }; store.state.entries.bar = { - url: 'test', type: 'blob', }; diff --git a/spec/frontend/ide/stores/actions_spec.js b/spec/frontend/ide/stores/actions_spec.js index f77dbd80025..ebf39df2f6f 100644 --- a/spec/frontend/ide/stores/actions_spec.js +++ b/spec/frontend/ide/stores/actions_spec.js @@ -123,7 +123,6 @@ describe('Multi-file store actions', () => { it('creates temp tree', done => { store .dispatch('createTempEntry', { - branchId: store.state.currentBranchId, name: 'test', type: 'tree', }) @@ -150,7 +149,6 @@ describe('Multi-file store actions', () => { store .dispatch('createTempEntry', { - branchId: store.state.currentBranchId, name: 'testing/test', type: 'tree', }) @@ -176,7 +174,6 @@ describe('Multi-file store actions', () => { store .dispatch('createTempEntry', { - branchId: store.state.currentBranchId, name: 'testing', type: 'tree', }) @@ -197,7 +194,6 @@ describe('Multi-file store actions', () => { store .dispatch('createTempEntry', { name, - branchId: 'mybranch', type: 'blob', }) .then(() => { @@ -217,7 +213,6 @@ describe('Multi-file store actions', () => { store .dispatch('createTempEntry', { name, - branchId: 'mybranch', type: 'blob', }) .then(() => { @@ -237,7 +232,6 @@ describe('Multi-file store actions', () => { store .dispatch('createTempEntry', { name, - branchId: 'mybranch', type: 'blob', }) .then(() => { @@ -249,7 +243,7 @@ describe('Multi-file store actions', () => { }); it('sets tmp file as active', () => { - createTempEntry(store, { name: 'test', branchId: 'mybranch', type: 'blob' }); + createTempEntry(store, { name: 'test', type: 'blob' }); expect(store.dispatch).toHaveBeenCalledWith('setFileActive', 'test'); }); @@ -262,7 +256,6 @@ describe('Multi-file store actions', () => { store .dispatch('createTempEntry', { name: 'test', - branchId: 'mybranch', type: 'blob', }) .then(() => { @@ -780,9 +773,11 @@ describe('Multi-file store actions', () => { }); it('routes to the renamed file if the original file has been opened', done => { + store.state.currentProjectId = 'test/test'; + store.state.currentBranchId = 'master'; + Object.assign(store.state.entries.orig, { opened: true, - url: '/foo-bar.md', }); store @@ -792,7 +787,7 @@ describe('Multi-file store actions', () => { }) .then(() => { expect(router.push.mock.calls).toHaveLength(1); - expect(router.push).toHaveBeenCalledWith(`/project/foo-bar.md`); + expect(router.push).toHaveBeenCalledWith(`/project/test/test/tree/master/-/renamed/`); }) .then(done) .catch(done.fail); diff --git a/spec/frontend/ide/stores/getters_spec.js b/spec/frontend/ide/stores/getters_spec.js index dcf05329ce0..e24f08fa802 100644 --- a/spec/frontend/ide/stores/getters_spec.js +++ b/spec/frontend/ide/stores/getters_spec.js @@ -1,3 +1,4 @@ +import { TEST_HOST } from 'helpers/test_constants'; import * as getters from '~/ide/stores/getters'; import { createStore } from '~/ide/stores'; import { file } from '../helpers'; @@ -482,4 +483,48 @@ describe('IDE store getters', () => { expect(localStore.getters.getAvailableFileName('foo-bar1.jpg')).toBe('foo-bar1.jpg'); }); }); + + describe('getUrlForPath', () => { + it('returns a route url for the given path', () => { + localState.currentProjectId = 'test/test'; + localState.currentBranchId = 'master'; + + expect(localStore.getters.getUrlForPath('path/to/foo/bar-1.jpg')).toBe( + `/project/test/test/tree/master/-/path/to/foo/bar-1.jpg/`, + ); + }); + }); + + describe('getJsonSchemaForPath', () => { + beforeEach(() => { + localState.currentProjectId = 'path/to/some/project'; + localState.currentBranchId = 'master'; + }); + + it('returns a json schema uri and match config for a json/yaml file that can be loaded by monaco', () => { + expect(localStore.getters.getJsonSchemaForPath('.gitlab-ci.yml')).toEqual({ + fileMatch: ['*.gitlab-ci.yml'], + uri: `${TEST_HOST}/path/to/some/project/-/schema/master/.gitlab-ci.yml`, + }); + }); + + it('returns a path containing sha if branch details are present in state', () => { + localState.projects['path/to/some/project'] = { + name: 'project', + branches: { + master: { + name: 'master', + commit: { + id: 'abcdef123456', + }, + }, + }, + }; + + expect(localStore.getters.getJsonSchemaForPath('.gitlab-ci.yml')).toEqual({ + fileMatch: ['*.gitlab-ci.yml'], + uri: `${TEST_HOST}/path/to/some/project/-/schema/abcdef123456/.gitlab-ci.yml`, + }); + }); + }); }); diff --git a/spec/frontend/ide/stores/integration_spec.js b/spec/frontend/ide/stores/integration_spec.js index f95f036f572..b6a7c7fd02d 100644 --- a/spec/frontend/ide/stores/integration_spec.js +++ b/spec/frontend/ide/stores/integration_spec.js @@ -36,8 +36,6 @@ describe('IDE store integration', () => { beforeEach(() => { const { entries, treeList } = decorateFiles({ data: [`${TEST_PATH_DIR}/`, TEST_PATH, 'README.md'], - projectId: TEST_PROJECT_ID, - branchId: TEST_BRANCH, }); Object.assign(entries[TEST_PATH], { diff --git a/spec/frontend/ide/stores/modules/commit/actions_spec.js b/spec/frontend/ide/stores/modules/commit/actions_spec.js index a14879112fd..babc50e54f1 100644 --- a/spec/frontend/ide/stores/modules/commit/actions_spec.js +++ b/spec/frontend/ide/stores/modules/commit/actions_spec.js @@ -9,6 +9,7 @@ import eventHub from '~/ide/eventhub'; import consts from '~/ide/stores/modules/commit/constants'; 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'; @@ -510,7 +511,7 @@ describe('IDE commit module actions', () => { }); }); - describe('failed', () => { + describe('success response with failed message', () => { beforeEach(() => { jest.spyOn(service, 'commit').mockResolvedValue({ data: { @@ -533,6 +534,25 @@ describe('IDE commit module actions', () => { }); }); + describe('failed response', () => { + beforeEach(() => { + jest.spyOn(service, 'commit').mockRejectedValue({}); + }); + + it('commits error updates', async () => { + jest.spyOn(store, 'commit'); + + await store.dispatch('commit/commitChanges').catch(() => {}); + + expect(store.commit.mock.calls).toEqual([ + ['commit/CLEAR_ERROR', undefined, undefined], + ['commit/UPDATE_LOADING', true, undefined], + ['commit/UPDATE_LOADING', false, undefined], + ['commit/SET_ERROR', createUnexpectedCommitError(), undefined], + ]); + }); + }); + describe('first commit of a branch', () => { const COMMIT_RESPONSE = { id: '123456', diff --git a/spec/frontend/ide/stores/modules/commit/mutations_spec.js b/spec/frontend/ide/stores/modules/commit/mutations_spec.js index 45ac1a86ab3..6393a70eac6 100644 --- a/spec/frontend/ide/stores/modules/commit/mutations_spec.js +++ b/spec/frontend/ide/stores/modules/commit/mutations_spec.js @@ -1,5 +1,6 @@ import commitState from '~/ide/stores/modules/commit/state'; import mutations from '~/ide/stores/modules/commit/mutations'; +import * as types from '~/ide/stores/modules/commit/mutation_types'; describe('IDE commit module mutations', () => { let state; @@ -62,4 +63,24 @@ describe('IDE commit module mutations', () => { expect(state.shouldCreateMR).toBe(false); }); }); + + describe(types.CLEAR_ERROR, () => { + it('should clear commitError', () => { + state.commitError = {}; + + mutations[types.CLEAR_ERROR](state); + + expect(state.commitError).toBeNull(); + }); + }); + + describe(types.SET_ERROR, () => { + it('should set commitError', () => { + const error = { title: 'foo' }; + + mutations[types.SET_ERROR](state, error); + + expect(state.commitError).toBe(error); + }); + }); }); diff --git a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js index 71918e7e2c2..8511843cc92 100644 --- a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js +++ b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js @@ -15,10 +15,10 @@ import { fetchJobs, toggleStageCollapsed, setDetailJob, - requestJobTrace, - receiveJobTraceError, - receiveJobTraceSuccess, - fetchJobTrace, + requestJobLogs, + receiveJobLogsError, + receiveJobLogsSuccess, + fetchJobLogs, resetLatestPipeline, } from '~/ide/stores/modules/pipelines/actions'; import state from '~/ide/stores/modules/pipelines/state'; @@ -324,24 +324,24 @@ describe('IDE pipelines actions', () => { }); }); - describe('requestJobTrace', () => { + describe('requestJobLogs', () => { it('commits request', done => { - testAction(requestJobTrace, null, mockedState, [{ type: types.REQUEST_JOB_TRACE }], [], done); + testAction(requestJobLogs, null, mockedState, [{ type: types.REQUEST_JOB_LOGS }], [], done); }); }); - describe('receiveJobTraceError', () => { + describe('receiveJobLogsError', () => { it('commits error', done => { testAction( - receiveJobTraceError, + receiveJobLogsError, null, mockedState, - [{ type: types.RECEIVE_JOB_TRACE_ERROR }], + [{ type: types.RECEIVE_JOB_LOGS_ERROR }], [ { type: 'setErrorMessage', payload: { - text: 'An error occurred while fetching the job trace.', + text: 'An error occurred while fetching the job logs.', action: expect.any(Function), actionText: 'Please try again', actionPayload: null, @@ -353,20 +353,20 @@ describe('IDE pipelines actions', () => { }); }); - describe('receiveJobTraceSuccess', () => { + describe('receiveJobLogsSuccess', () => { it('commits data', done => { testAction( - receiveJobTraceSuccess, + receiveJobLogsSuccess, 'data', mockedState, - [{ type: types.RECEIVE_JOB_TRACE_SUCCESS, payload: 'data' }], + [{ type: types.RECEIVE_JOB_LOGS_SUCCESS, payload: 'data' }], [], done, ); }); }); - describe('fetchJobTrace', () => { + describe('fetchJobLogs', () => { beforeEach(() => { mockedState.detailJob = { path: `${TEST_HOST}/project/builds` }; }); @@ -379,20 +379,20 @@ describe('IDE pipelines actions', () => { it('dispatches request', done => { testAction( - fetchJobTrace, + fetchJobLogs, null, mockedState, [], [ - { type: 'requestJobTrace' }, - { type: 'receiveJobTraceSuccess', payload: { html: 'html' } }, + { type: 'requestJobLogs' }, + { type: 'receiveJobLogsSuccess', payload: { html: 'html' } }, ], done, ); }); it('sends get request to correct URL', () => { - fetchJobTrace({ + fetchJobLogs({ state: mockedState, dispatch() {}, @@ -410,11 +410,11 @@ describe('IDE pipelines actions', () => { it('dispatches error', done => { testAction( - fetchJobTrace, + fetchJobLogs, null, mockedState, [], - [{ type: 'requestJobTrace' }, { type: 'receiveJobTraceError' }], + [{ type: 'requestJobLogs' }, { type: 'receiveJobLogsError' }], done, ); }); diff --git a/spec/frontend/ide/stores/modules/pipelines/mutations_spec.js b/spec/frontend/ide/stores/modules/pipelines/mutations_spec.js index 3b7f92cfa74..7d2f5d5d710 100644 --- a/spec/frontend/ide/stores/modules/pipelines/mutations_spec.js +++ b/spec/frontend/ide/stores/modules/pipelines/mutations_spec.js @@ -175,37 +175,37 @@ describe('IDE pipelines mutations', () => { }); }); - describe('REQUEST_JOB_TRACE', () => { + describe('REQUEST_JOB_LOGS', () => { beforeEach(() => { mockedState.detailJob = { ...jobs[0] }; }); it('sets loading on detail job', () => { - mutations[types.REQUEST_JOB_TRACE](mockedState); + mutations[types.REQUEST_JOB_LOGS](mockedState); expect(mockedState.detailJob.isLoading).toBe(true); }); }); - describe('RECEIVE_JOB_TRACE_ERROR', () => { + describe('RECEIVE_JOB_LOGS_ERROR', () => { beforeEach(() => { mockedState.detailJob = { ...jobs[0], isLoading: true }; }); it('sets loading to false on detail job', () => { - mutations[types.RECEIVE_JOB_TRACE_ERROR](mockedState); + mutations[types.RECEIVE_JOB_LOGS_ERROR](mockedState); expect(mockedState.detailJob.isLoading).toBe(false); }); }); - describe('RECEIVE_JOB_TRACE_SUCCESS', () => { + describe('RECEIVE_JOB_LOGS_SUCCESS', () => { beforeEach(() => { mockedState.detailJob = { ...jobs[0], isLoading: true }; }); it('sets output on detail job', () => { - mutations[types.RECEIVE_JOB_TRACE_SUCCESS](mockedState, { html: 'html' }); + mutations[types.RECEIVE_JOB_LOGS_SUCCESS](mockedState, { html: 'html' }); expect(mockedState.detailJob.output).toBe('html'); expect(mockedState.detailJob.isLoading).toBe(false); }); diff --git a/spec/frontend/ide/stores/mutations/file_spec.js b/spec/frontend/ide/stores/mutations/file_spec.js index ff904bbc9cd..b53e40be980 100644 --- a/spec/frontend/ide/stores/mutations/file_spec.js +++ b/spec/frontend/ide/stores/mutations/file_spec.js @@ -61,13 +61,11 @@ describe('IDE store file mutations', () => { mutations.SET_FILE_DATA(localState, { data: { raw_path: 'raw', - binary: true, }, file: localFile, }); expect(localFile.rawPath).toBe('raw'); - expect(localFile.binary).toBeTruthy(); expect(localFile.raw).toBeNull(); expect(localFile.baseRaw).toBeNull(); }); diff --git a/spec/frontend/ide/stores/mutations_spec.js b/spec/frontend/ide/stores/mutations_spec.js index 1b29648fb8b..09e9481e5d4 100644 --- a/spec/frontend/ide/stores/mutations_spec.js +++ b/spec/frontend/ide/stores/mutations_spec.js @@ -113,8 +113,6 @@ describe('Multi-file store mutations', () => { }, treeList: [tmpFile], }, - projectId: 'gitlab-ce', - branchId: 'master', }); expect(localState.trees['gitlab-ce/master'].tree.length).toEqual(1); @@ -272,7 +270,6 @@ describe('Multi-file store mutations', () => { prevId: undefined, prevPath: undefined, prevName: undefined, - prevUrl: undefined, prevKey: undefined, }), ); @@ -337,7 +334,6 @@ describe('Multi-file store mutations', () => { }; Object.assign(localState.entries['root-folder/oldPath'], { parentPath: 'root-folder', - url: 'root-folder/oldPath-blob-root-folder/oldPath', }); mutations.RENAME_ENTRY(localState, { @@ -366,9 +362,6 @@ describe('Multi-file store mutations', () => { }); it('renames entry, preserving old parameters', () => { - Object.assign(localState.entries.oldPath, { - url: `project/-/oldPath`, - }); const oldPathData = localState.entries.oldPath; mutations.RENAME_ENTRY(localState, { @@ -382,12 +375,10 @@ describe('Multi-file store mutations', () => { id: 'newPath', path: 'newPath', name: 'newPath', - url: `project/-/newPath`, key: expect.stringMatching('newPath'), prevId: 'oldPath', prevName: 'oldPath', prevPath: 'oldPath', - prevUrl: `project/-/oldPath`, prevKey: oldPathData.key, prevParentPath: oldPathData.parentPath, }); @@ -409,7 +400,6 @@ describe('Multi-file store mutations', () => { prevId: expect.anything(), prevName: expect.anything(), prevPath: expect.anything(), - prevUrl: expect.anything(), prevKey: expect.anything(), prevParentPath: expect.anything(), }), @@ -419,7 +409,7 @@ describe('Multi-file store mutations', () => { it('properly handles files with spaces in name', () => { const path = 'my fancy path'; const newPath = 'new path'; - const oldEntry = { ...file(path, path, 'blob'), url: `project/-/${path}` }; + const oldEntry = file(path, path, 'blob'); localState.entries[path] = oldEntry; @@ -435,12 +425,10 @@ describe('Multi-file store mutations', () => { id: newPath, path: newPath, name: newPath, - url: `project/-/new path`, key: expect.stringMatching(newPath), prevId: path, prevName: path, prevPath: path, - prevUrl: `project/-/my fancy path`, prevKey: oldEntry.key, prevParentPath: oldEntry.parentPath, }); @@ -549,7 +537,7 @@ describe('Multi-file store mutations', () => { it('correctly saves original values if an entry is renamed multiple times', () => { const original = { ...localState.entries.oldPath }; - const paramsToCheck = ['prevId', 'prevPath', 'prevName', 'prevUrl']; + const paramsToCheck = ['prevId', 'prevPath', 'prevName']; const expectedObj = paramsToCheck.reduce( (o, param) => ({ ...o, [param]: original[param.replace('prev', '').toLowerCase()] }), {}, @@ -577,7 +565,6 @@ describe('Multi-file store mutations', () => { prevId: 'lorem/orig', prevPath: 'lorem/orig', prevName: 'orig', - prevUrl: 'project/-/loren/orig', prevKey: 'lorem/orig', prevParentPath: 'lorem', }; @@ -602,7 +589,6 @@ describe('Multi-file store mutations', () => { prevId: undefined, prevPath: undefined, prevName: undefined, - prevUrl: undefined, prevKey: undefined, prevParentPath: undefined, }), |