debian-mirror-gitlab/spec/frontend/ide/stores/mutations/project_spec.js

51 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-09-04 21:01:54 +05:30
import mutations from '~/ide/stores/mutations/project';
import state from '~/ide/stores/state';
describe('Multi-file store branch mutations', () => {
let localState;
2022-01-26 12:08:38 +05:30
const nonExistentProj = 'nonexistent';
const existingProj = 'abcproject';
2019-09-04 21:01:54 +05:30
beforeEach(() => {
localState = state();
2022-01-26 12:08:38 +05:30
localState.projects = { [existingProj]: { empty_repo: true } };
2019-09-04 21:01:54 +05:30
});
describe('TOGGLE_EMPTY_STATE', () => {
it('sets empty_repo for project to passed value', () => {
2022-01-26 12:08:38 +05:30
mutations.TOGGLE_EMPTY_STATE(localState, { projectPath: existingProj, value: false });
2019-09-04 21:01:54 +05:30
2022-01-26 12:08:38 +05:30
expect(localState.projects[existingProj].empty_repo).toBe(false);
2019-09-04 21:01:54 +05:30
2022-01-26 12:08:38 +05:30
mutations.TOGGLE_EMPTY_STATE(localState, { projectPath: existingProj, value: true });
2019-09-04 21:01:54 +05:30
2022-01-26 12:08:38 +05:30
expect(localState.projects[existingProj].empty_repo).toBe(true);
});
});
describe('UPDATE_PROJECT', () => {
it.each`
desc | projectPath | props | expectedProps
${'extends existing project with the passed props'} | ${existingProj} | ${{ foo1: 'bar' }} | ${{ foo1: 'bar' }}
${'overrides existing props on the exsiting project'} | ${existingProj} | ${{ empty_repo: false }} | ${{ empty_repo: false }}
${'does nothing if the project does not exist'} | ${nonExistentProj} | ${{ foo2: 'bar' }} | ${undefined}
${'does nothing if project is not passed'} | ${undefined} | ${{ foo3: 'bar' }} | ${undefined}
${'does nothing if the props are not passed'} | ${existingProj} | ${undefined} | ${{}}
${'does nothing if the props are empty'} | ${existingProj} | ${{}} | ${{}}
`('$desc', ({ projectPath, props, expectedProps } = {}) => {
const origProject = localState.projects[projectPath];
mutations.UPDATE_PROJECT(localState, { projectPath, props });
if (!expectedProps) {
expect(localState.projects[projectPath]).toBeUndefined();
} else {
expect(localState.projects[projectPath]).toEqual({
...origProject,
...expectedProps,
});
}
2019-09-04 21:01:54 +05:30
});
});
});