diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 21:07:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 21:07:48 +0300 |
commit | e72386771751fb22245bc6604fef236a2ee130cb (patch) | |
tree | 7cf54bca933159cb177d3caa2f139f87d6d30391 /spec/frontend/ide | |
parent | c2b98d3dbd47ab92c79c702276fe9130d9a28036 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide')
-rw-r--r-- | spec/frontend/ide/stores/getters_spec.js | 92 |
1 files changed, 90 insertions, 2 deletions
diff --git a/spec/frontend/ide/stores/getters_spec.js b/spec/frontend/ide/stores/getters_spec.js index d196f6f79d5..21c5e886738 100644 --- a/spec/frontend/ide/stores/getters_spec.js +++ b/spec/frontend/ide/stores/getters_spec.js @@ -1,12 +1,14 @@ import * as getters from '~/ide/stores/getters'; -import state from '~/ide/stores/state'; +import { createStore } from '~/ide/stores'; import { file } from '../helpers'; describe('IDE store getters', () => { let localState; + let localStore; beforeEach(() => { - localState = state(); + localStore = createStore(); + localState = localStore.state; }); describe('activeFile', () => { @@ -310,4 +312,90 @@ describe('IDE store getters', () => { expect(getters.canPushToBranch({}, localGetters)).toBeFalsy(); }); }); + + describe('isFileDeletedAndReadded', () => { + const f = { ...file('sample'), content: 'sample', raw: 'sample' }; + + it.each([ + { + entry: { ...f, tempFile: true }, + staged: { ...f, deleted: true }, + output: true, + }, + { + entry: { ...f, content: 'changed' }, + staged: { ...f, content: 'changed' }, + output: false, + }, + { + entry: { ...f, content: 'changed' }, + output: false, + }, + ])( + 'checks staged and unstaged files to see if a file was deleted and readded (case %#)', + ({ entry, staged, output }) => { + Object.assign(localState, { + entries: { + [entry.path]: entry, + }, + stagedFiles: [], + }); + + if (staged) localState.stagedFiles.push(staged); + + expect(localStore.getters.isFileDeletedAndReadded(entry.path)).toBe(output); + }, + ); + }); + + describe('getDiffInfo', () => { + const f = { ...file('sample'), content: 'sample', raw: 'sample' }; + it.each([ + { + entry: { ...f, tempFile: true }, + staged: { ...f, deleted: true }, + output: { deleted: false, changed: false, tempFile: false }, + }, + { + entry: { ...f, tempFile: true, content: 'changed', raw: '' }, + staged: { ...f, deleted: true }, + output: { deleted: false, changed: true, tempFile: false }, + }, + { + entry: { ...f, content: 'changed' }, + output: { changed: true }, + }, + { + entry: { ...f, content: 'sample' }, + staged: { ...f, content: 'changed' }, + output: { changed: false }, + }, + { + entry: { ...f, deleted: true }, + output: { deleted: true, changed: false }, + }, + { + entry: { ...f, prevPath: 'old_path' }, + output: { renamed: true, changed: false }, + }, + { + entry: { ...f, prevPath: 'old_path', content: 'changed' }, + output: { renamed: true, changed: true }, + }, + ])( + 'compares changes in a file entry and returns a resulting diff info (case %#)', + ({ entry, staged, output }) => { + Object.assign(localState, { + entries: { + [entry.path]: entry, + }, + stagedFiles: [], + }); + + if (staged) localState.stagedFiles.push(staged); + + expect(localStore.getters.getDiffInfo(entry.path)).toEqual(expect.objectContaining(output)); + }, + ); + }); }); |