diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2019-03-23 19:52:35 +0300 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2019-03-23 19:53:46 +0300 |
commit | 514ee63826e47229bfd03bdbb740f2dd1eae1d03 (patch) | |
tree | 3f0d96a4402e8aa54c375084cc4c5e6cf546824b /spec/javascripts/ide | |
parent | 6d330015dfdb1979a0773c87c53b84cc86b28a6d (diff) |
Move some tests from Karma to Jest
Diffstat (limited to 'spec/javascripts/ide')
12 files changed, 0 insertions, 626 deletions
diff --git a/spec/javascripts/ide/lib/common/disposable_spec.js b/spec/javascripts/ide/lib/common/disposable_spec.js deleted file mode 100644 index af12ca15369..00000000000 --- a/spec/javascripts/ide/lib/common/disposable_spec.js +++ /dev/null @@ -1,44 +0,0 @@ -import Disposable from '~/ide/lib/common/disposable'; - -describe('Multi-file editor library disposable class', () => { - let instance; - let disposableClass; - - beforeEach(() => { - instance = new Disposable(); - - disposableClass = { - dispose: jasmine.createSpy('dispose'), - }; - }); - - afterEach(() => { - instance.dispose(); - }); - - describe('add', () => { - it('adds disposable classes', () => { - instance.add(disposableClass); - - expect(instance.disposers.size).toBe(1); - }); - }); - - describe('dispose', () => { - beforeEach(() => { - instance.add(disposableClass); - }); - - it('calls dispose on all cached disposers', () => { - instance.dispose(); - - expect(disposableClass.dispose).toHaveBeenCalled(); - }); - - it('clears cached disposers', () => { - instance.dispose(); - - expect(instance.disposers.size).toBe(0); - }); - }); -}); diff --git a/spec/javascripts/ide/lib/diff/diff_spec.js b/spec/javascripts/ide/lib/diff/diff_spec.js deleted file mode 100644 index 57f3ac3d365..00000000000 --- a/spec/javascripts/ide/lib/diff/diff_spec.js +++ /dev/null @@ -1,80 +0,0 @@ -import { computeDiff } from '~/ide/lib/diff/diff'; - -describe('Multi-file editor library diff calculator', () => { - describe('computeDiff', () => { - it('returns empty array if no changes', () => { - const diff = computeDiff('123', '123'); - - expect(diff).toEqual([]); - }); - - describe('modified', () => { - it('', () => { - const diff = computeDiff('123', '1234')[0]; - - expect(diff.added).toBeTruthy(); - expect(diff.modified).toBeTruthy(); - expect(diff.removed).toBeUndefined(); - }); - - it('', () => { - const diff = computeDiff('123\n123\n123', '123\n1234\n123')[0]; - - expect(diff.added).toBeTruthy(); - expect(diff.modified).toBeTruthy(); - expect(diff.removed).toBeUndefined(); - expect(diff.lineNumber).toBe(2); - }); - }); - - describe('added', () => { - it('', () => { - const diff = computeDiff('123', '123\n123')[0]; - - expect(diff.added).toBeTruthy(); - expect(diff.modified).toBeUndefined(); - expect(diff.removed).toBeUndefined(); - }); - - it('', () => { - const diff = computeDiff('123\n123\n123', '123\n123\n1234\n123')[0]; - - expect(diff.added).toBeTruthy(); - expect(diff.modified).toBeUndefined(); - expect(diff.removed).toBeUndefined(); - expect(diff.lineNumber).toBe(3); - }); - }); - - describe('removed', () => { - it('', () => { - const diff = computeDiff('123', '')[0]; - - expect(diff.added).toBeUndefined(); - expect(diff.modified).toBeUndefined(); - expect(diff.removed).toBeTruthy(); - }); - - it('', () => { - const diff = computeDiff('123\n123\n123', '123\n123')[0]; - - expect(diff.added).toBeUndefined(); - expect(diff.modified).toBeTruthy(); - expect(diff.removed).toBeTruthy(); - expect(diff.lineNumber).toBe(2); - }); - }); - - it('includes line number of change', () => { - const diff = computeDiff('123', '')[0]; - - expect(diff.lineNumber).toBe(1); - }); - - it('includes end line number of change', () => { - const diff = computeDiff('123', '')[0]; - - expect(diff.endLineNumber).toBe(1); - }); - }); -}); diff --git a/spec/javascripts/ide/lib/editor_options_spec.js b/spec/javascripts/ide/lib/editor_options_spec.js deleted file mode 100644 index d149a883166..00000000000 --- a/spec/javascripts/ide/lib/editor_options_spec.js +++ /dev/null @@ -1,11 +0,0 @@ -import editorOptions from '~/ide/lib/editor_options'; - -describe('Multi-file editor library editor options', () => { - it('returns an array', () => { - expect(editorOptions).toEqual(jasmine.any(Array)); - }); - - it('contains readOnly option', () => { - expect(editorOptions[0].readOnly).toBeDefined(); - }); -}); diff --git a/spec/javascripts/ide/lib/files_spec.js b/spec/javascripts/ide/lib/files_spec.js deleted file mode 100644 index fe791aa2b74..00000000000 --- a/spec/javascripts/ide/lib/files_spec.js +++ /dev/null @@ -1,77 +0,0 @@ -import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils'; -import { decorateFiles, splitParent } from '~/ide/lib/files'; -import { decorateData } from '~/ide/stores/utils'; - -const TEST_BRANCH_ID = 'lorem-ipsum'; -const TEST_PROJECT_ID = 10; - -const createEntries = paths => { - const createEntry = (acc, { path, type, children }) => { - // Sometimes we need to end the url with a '/' - const createUrl = base => (type === 'tree' ? `${base}/` : base); - - const { name, parent } = splitParent(path); - const parentEntry = acc[parent]; - - acc[path] = { - ...decorateData({ - projectId: TEST_PROJECT_ID, - branchId: TEST_BRANCH_ID, - id: path, - name, - path, - url: createUrl(`/${TEST_PROJECT_ID}/${type}/${TEST_BRANCH_ID}/-/${path}`), - type, - previewMode: viewerInformationForPath(path), - parentPath: parent, - parentTreeUrl: parentEntry - ? parentEntry.url - : createUrl(`/${TEST_PROJECT_ID}/${type}/${TEST_BRANCH_ID}`), - }), - tree: children.map(childName => jasmine.objectContaining({ name: childName })), - }; - - return acc; - }; - - const entries = paths.reduce(createEntry, {}); - - // Wrap entries in jasmine.objectContaining. - // We couldn't do this earlier because we still need to select properties from parent entries. - return Object.keys(entries).reduce((acc, key) => { - acc[key] = jasmine.objectContaining(entries[key]); - - return acc; - }, {}); -}; - -describe('IDE lib decorate files', () => { - it('creates entries and treeList', () => { - const data = ['app/assets/apples/foo.js', 'app/bugs.js', 'README.md']; - const expectedEntries = createEntries([ - { path: 'app', type: 'tree', children: ['assets', 'bugs.js'] }, - { path: 'app/assets', type: 'tree', children: ['apples'] }, - { path: 'app/assets/apples', type: 'tree', children: ['foo.js'] }, - { path: 'app/assets/apples/foo.js', type: 'blob', children: [] }, - { path: 'app/bugs.js', type: 'blob', children: [] }, - { path: 'README.md', type: 'blob', children: [] }, - ]); - - const { entries, treeList } = decorateFiles({ - data, - branchId: TEST_BRANCH_ID, - projectId: TEST_PROJECT_ID, - }); - - // Here we test the keys and then each key/value individually because `expect(entries).toEqual(expectedEntries)` - // was taking a very long time for some reason. Probably due to large objects and nested `jasmine.objectContaining`. - const entryKeys = Object.keys(entries); - - expect(entryKeys).toEqual(Object.keys(expectedEntries)); - entryKeys.forEach(key => { - expect(entries[key]).toEqual(expectedEntries[key]); - }); - - expect(treeList).toEqual([expectedEntries.app, expectedEntries['README.md']]); - }); -}); diff --git a/spec/javascripts/ide/stores/modules/commit/mutations_spec.js b/spec/javascripts/ide/stores/modules/commit/mutations_spec.js deleted file mode 100644 index 5de7a281d34..00000000000 --- a/spec/javascripts/ide/stores/modules/commit/mutations_spec.js +++ /dev/null @@ -1,42 +0,0 @@ -import commitState from '~/ide/stores/modules/commit/state'; -import mutations from '~/ide/stores/modules/commit/mutations'; - -describe('IDE commit module mutations', () => { - let state; - - beforeEach(() => { - state = commitState(); - }); - - describe('UPDATE_COMMIT_MESSAGE', () => { - it('updates commitMessage', () => { - mutations.UPDATE_COMMIT_MESSAGE(state, 'testing'); - - expect(state.commitMessage).toBe('testing'); - }); - }); - - describe('UPDATE_COMMIT_ACTION', () => { - it('updates commitAction', () => { - mutations.UPDATE_COMMIT_ACTION(state, 'testing'); - - expect(state.commitAction).toBe('testing'); - }); - }); - - describe('UPDATE_NEW_BRANCH_NAME', () => { - it('updates newBranchName', () => { - mutations.UPDATE_NEW_BRANCH_NAME(state, 'testing'); - - expect(state.newBranchName).toBe('testing'); - }); - }); - - describe('UPDATE_LOADING', () => { - it('updates submitCommitLoading', () => { - mutations.UPDATE_LOADING(state, true); - - expect(state.submitCommitLoading).toBeTruthy(); - }); - }); -}); diff --git a/spec/javascripts/ide/stores/modules/file_templates/getters_spec.js b/spec/javascripts/ide/stores/modules/file_templates/getters_spec.js deleted file mode 100644 index 17cb457881f..00000000000 --- a/spec/javascripts/ide/stores/modules/file_templates/getters_spec.js +++ /dev/null @@ -1,59 +0,0 @@ -import createState from '~/ide/stores/state'; -import { activityBarViews } from '~/ide/constants'; -import * as getters from '~/ide/stores/modules/file_templates/getters'; - -describe('IDE file templates getters', () => { - describe('templateTypes', () => { - it('returns list of template types', () => { - expect(getters.templateTypes().length).toBe(4); - }); - }); - - describe('showFileTemplatesBar', () => { - let rootState; - - beforeEach(() => { - rootState = createState(); - }); - - it('returns true if template is found and currentActivityView is edit', () => { - rootState.currentActivityView = activityBarViews.edit; - - expect( - getters.showFileTemplatesBar( - null, - { - templateTypes: getters.templateTypes(), - }, - rootState, - )('LICENSE'), - ).toBe(true); - }); - - it('returns false if template is found and currentActivityView is not edit', () => { - rootState.currentActivityView = activityBarViews.commit; - - expect( - getters.showFileTemplatesBar( - null, - { - templateTypes: getters.templateTypes(), - }, - rootState, - )('LICENSE'), - ).toBe(false); - }); - - it('returns undefined if not found', () => { - expect( - getters.showFileTemplatesBar( - null, - { - templateTypes: getters.templateTypes(), - }, - rootState, - )('test'), - ).toBe(undefined); - }); - }); -}); diff --git a/spec/javascripts/ide/stores/modules/file_templates/mutations_spec.js b/spec/javascripts/ide/stores/modules/file_templates/mutations_spec.js deleted file mode 100644 index 8e0e3ae99a1..00000000000 --- a/spec/javascripts/ide/stores/modules/file_templates/mutations_spec.js +++ /dev/null @@ -1,69 +0,0 @@ -import createState from '~/ide/stores/modules/file_templates/state'; -import * as types from '~/ide/stores/modules/file_templates/mutation_types'; -import mutations from '~/ide/stores/modules/file_templates/mutations'; - -describe('IDE file templates mutations', () => { - let state; - - beforeEach(() => { - state = createState(); - }); - - describe(types.REQUEST_TEMPLATE_TYPES, () => { - it('sets isLoading', () => { - mutations[types.REQUEST_TEMPLATE_TYPES](state); - - expect(state.isLoading).toBe(true); - }); - }); - - describe(types.RECEIVE_TEMPLATE_TYPES_ERROR, () => { - it('sets isLoading', () => { - state.isLoading = true; - - mutations[types.RECEIVE_TEMPLATE_TYPES_ERROR](state); - - expect(state.isLoading).toBe(false); - }); - }); - - describe(types.RECEIVE_TEMPLATE_TYPES_SUCCESS, () => { - it('sets isLoading to false', () => { - state.isLoading = true; - - mutations[types.RECEIVE_TEMPLATE_TYPES_SUCCESS](state, []); - - expect(state.isLoading).toBe(false); - }); - - it('sets templates', () => { - mutations[types.RECEIVE_TEMPLATE_TYPES_SUCCESS](state, ['test']); - - expect(state.templates).toEqual(['test']); - }); - }); - - describe(types.SET_SELECTED_TEMPLATE_TYPE, () => { - it('sets selectedTemplateType', () => { - mutations[types.SET_SELECTED_TEMPLATE_TYPE](state, 'type'); - - expect(state.selectedTemplateType).toBe('type'); - }); - - it('clears templates', () => { - state.templates = ['test']; - - mutations[types.SET_SELECTED_TEMPLATE_TYPE](state, 'type'); - - expect(state.templates).toEqual([]); - }); - }); - - describe(types.SET_UPDATE_SUCCESS, () => { - it('sets updateSuccess', () => { - mutations[types.SET_UPDATE_SUCCESS](state, true); - - expect(state.updateSuccess).toBe(true); - }); - }); -}); diff --git a/spec/javascripts/ide/stores/modules/pane/getters_spec.js b/spec/javascripts/ide/stores/modules/pane/getters_spec.js deleted file mode 100644 index 8a213323de0..00000000000 --- a/spec/javascripts/ide/stores/modules/pane/getters_spec.js +++ /dev/null @@ -1,55 +0,0 @@ -import * as getters from '~/ide/stores/modules/pane/getters'; -import state from '~/ide/stores/modules/pane/state'; - -describe('IDE pane module getters', () => { - const TEST_VIEW = 'test-view'; - const TEST_KEEP_ALIVE_VIEWS = { - [TEST_VIEW]: true, - }; - - describe('isActiveView', () => { - it('returns true if given view matches currentView', () => { - const result = getters.isActiveView({ currentView: 'A' })('A'); - - expect(result).toBe(true); - }); - - it('returns false if given view does not match currentView', () => { - const result = getters.isActiveView({ currentView: 'A' })('B'); - - expect(result).toBe(false); - }); - }); - - describe('isAliveView', () => { - it('returns true if given view is in keepAliveViews', () => { - const result = getters.isAliveView({ keepAliveViews: TEST_KEEP_ALIVE_VIEWS }, {})(TEST_VIEW); - - expect(result).toBe(true); - }); - - it('returns true if given view is active view and open', () => { - const result = getters.isAliveView( - { ...state(), isOpen: true }, - { isActiveView: () => true }, - )(TEST_VIEW); - - expect(result).toBe(true); - }); - - it('returns false if given view is active view and closed', () => { - const result = getters.isAliveView(state(), { isActiveView: () => true })(TEST_VIEW); - - expect(result).toBe(false); - }); - - it('returns false if given view is not activeView', () => { - const result = getters.isAliveView( - { ...state(), isOpen: true }, - { isActiveView: () => false }, - )(TEST_VIEW); - - expect(result).toBe(false); - }); - }); -}); diff --git a/spec/javascripts/ide/stores/modules/pane/mutations_spec.js b/spec/javascripts/ide/stores/modules/pane/mutations_spec.js deleted file mode 100644 index b5fcd35912e..00000000000 --- a/spec/javascripts/ide/stores/modules/pane/mutations_spec.js +++ /dev/null @@ -1,42 +0,0 @@ -import state from '~/ide/stores/modules/pane/state'; -import mutations from '~/ide/stores/modules/pane/mutations'; -import * as types from '~/ide/stores/modules/pane/mutation_types'; - -describe('IDE pane module mutations', () => { - const TEST_VIEW = 'test-view'; - let mockedState; - - beforeEach(() => { - mockedState = state(); - }); - - describe('SET_OPEN', () => { - it('sets isOpen', () => { - mockedState.isOpen = false; - - mutations[types.SET_OPEN](mockedState, true); - - expect(mockedState.isOpen).toBe(true); - }); - }); - - describe('SET_CURRENT_VIEW', () => { - it('sets currentView', () => { - mockedState.currentView = null; - - mutations[types.SET_CURRENT_VIEW](mockedState, TEST_VIEW); - - expect(mockedState.currentView).toEqual(TEST_VIEW); - }); - }); - - describe('KEEP_ALIVE_VIEW', () => { - it('adds entry to keepAliveViews', () => { - mutations[types.KEEP_ALIVE_VIEW](mockedState, TEST_VIEW); - - expect(mockedState.keepAliveViews).toEqual({ - [TEST_VIEW]: true, - }); - }); - }); -}); diff --git a/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js b/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js deleted file mode 100644 index 4514896b5ea..00000000000 --- a/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js +++ /dev/null @@ -1,40 +0,0 @@ -import * as getters from '~/ide/stores/modules/pipelines/getters'; -import state from '~/ide/stores/modules/pipelines/state'; - -describe('IDE pipeline getters', () => { - let mockedState; - - beforeEach(() => { - mockedState = state(); - }); - - describe('hasLatestPipeline', () => { - it('returns false when loading is true', () => { - mockedState.isLoadingPipeline = true; - - expect(getters.hasLatestPipeline(mockedState)).toBe(false); - }); - - it('returns false when pipelines is null', () => { - mockedState.latestPipeline = null; - - expect(getters.hasLatestPipeline(mockedState)).toBe(false); - }); - - it('returns false when loading is true & pipelines is null', () => { - mockedState.latestPipeline = null; - mockedState.isLoadingPipeline = true; - - expect(getters.hasLatestPipeline(mockedState)).toBe(false); - }); - - it('returns true when loading is false & pipelines is an object', () => { - mockedState.latestPipeline = { - id: 1, - }; - mockedState.isLoadingPipeline = false; - - expect(getters.hasLatestPipeline(mockedState)).toBe(true); - }); - }); -}); diff --git a/spec/javascripts/ide/stores/mutations/branch_spec.js b/spec/javascripts/ide/stores/mutations/branch_spec.js deleted file mode 100644 index 29eb859ddaf..00000000000 --- a/spec/javascripts/ide/stores/mutations/branch_spec.js +++ /dev/null @@ -1,40 +0,0 @@ -import mutations from '~/ide/stores/mutations/branch'; -import state from '~/ide/stores/state'; - -describe('Multi-file store branch mutations', () => { - let localState; - - beforeEach(() => { - localState = state(); - }); - - describe('SET_CURRENT_BRANCH', () => { - it('sets currentBranch', () => { - mutations.SET_CURRENT_BRANCH(localState, 'master'); - - expect(localState.currentBranchId).toBe('master'); - }); - }); - - describe('SET_BRANCH_COMMIT', () => { - it('sets the last commit on current project', () => { - localState.projects = { - Example: { - branches: { - master: {}, - }, - }, - }; - - mutations.SET_BRANCH_COMMIT(localState, { - projectId: 'Example', - branchId: 'master', - commit: { - title: 'Example commit', - }, - }); - - expect(localState.projects.Example.branches.master.commit.title).toBe('Example commit'); - }); - }); -}); diff --git a/spec/javascripts/ide/stores/mutations/merge_request_spec.js b/spec/javascripts/ide/stores/mutations/merge_request_spec.js deleted file mode 100644 index e30ca22022f..00000000000 --- a/spec/javascripts/ide/stores/mutations/merge_request_spec.js +++ /dev/null @@ -1,67 +0,0 @@ -import mutations from '~/ide/stores/mutations/merge_request'; -import state from '~/ide/stores/state'; - -describe('IDE store merge request mutations', () => { - let localState; - - beforeEach(() => { - localState = state(); - localState.projects = { abcproject: { mergeRequests: {} } }; - - mutations.SET_MERGE_REQUEST(localState, { - projectPath: 'abcproject', - mergeRequestId: 1, - mergeRequest: { - title: 'mr', - }, - }); - }); - - describe('SET_CURRENT_MERGE_REQUEST', () => { - it('sets current merge request', () => { - mutations.SET_CURRENT_MERGE_REQUEST(localState, 2); - - expect(localState.currentMergeRequestId).toBe(2); - }); - }); - - describe('SET_MERGE_REQUEST', () => { - it('setsmerge request data', () => { - const newMr = localState.projects.abcproject.mergeRequests[1]; - - expect(newMr.title).toBe('mr'); - expect(newMr.active).toBeTruthy(); - }); - }); - - describe('SET_MERGE_REQUEST_CHANGES', () => { - it('sets merge request changes', () => { - mutations.SET_MERGE_REQUEST_CHANGES(localState, { - projectPath: 'abcproject', - mergeRequestId: 1, - changes: { - diff: 'abc', - }, - }); - - const newMr = localState.projects.abcproject.mergeRequests[1]; - - expect(newMr.changes.diff).toBe('abc'); - }); - }); - - describe('SET_MERGE_REQUEST_VERSIONS', () => { - it('sets merge request versions', () => { - mutations.SET_MERGE_REQUEST_VERSIONS(localState, { - projectPath: 'abcproject', - mergeRequestId: 1, - versions: [{ id: 123 }], - }); - - const newMr = localState.projects.abcproject.mergeRequests[1]; - - expect(newMr.versions.length).toBe(1); - expect(newMr.versions[0].id).toBe(123); - }); - }); -}); |