diff options
Diffstat (limited to 'spec/frontend/ide/stores/getters_spec.js')
-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)); + }, + ); + }); }); |