debian-mirror-gitlab/spec/frontend/integrations/edit/store/getters_spec.js

102 lines
3 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import {
currentKey,
isInheriting,
isDisabled,
propsSource,
} from '~/integrations/edit/store/getters';
2020-07-28 23:09:34 +05:30
import createState from '~/integrations/edit/store/state';
2021-01-29 00:20:46 +05:30
import mutations from '~/integrations/edit/store/mutations';
import * as types from '~/integrations/edit/store/mutation_types';
2020-07-28 23:09:34 +05:30
import { mockIntegrationProps } from '../mock_data';
describe('Integration form store getters', () => {
let state;
const customState = { ...mockIntegrationProps, type: 'CustomState' };
2020-11-24 15:15:51 +05:30
const defaultState = { ...mockIntegrationProps, type: 'DefaultState' };
2020-07-28 23:09:34 +05:30
beforeEach(() => {
state = createState({ customState });
});
describe('isInheriting', () => {
2020-11-24 15:15:51 +05:30
describe('when defaultState is null', () => {
2020-07-28 23:09:34 +05:30
it('returns false', () => {
expect(isInheriting(state)).toBe(false);
});
});
2020-11-24 15:15:51 +05:30
describe('when defaultState is an object', () => {
2020-07-28 23:09:34 +05:30
beforeEach(() => {
2020-11-24 15:15:51 +05:30
state.defaultState = defaultState;
2020-07-28 23:09:34 +05:30
});
describe('when override is false', () => {
beforeEach(() => {
state.override = false;
});
it('returns false', () => {
expect(isInheriting(state)).toBe(true);
});
});
describe('when override is true', () => {
beforeEach(() => {
state.override = true;
});
it('returns true', () => {
expect(isInheriting(state)).toBe(false);
});
});
});
});
2021-01-29 00:20:46 +05:30
describe('isDisabled', () => {
it.each`
isSaving | isTesting | isResetting | expected
${false} | ${false} | ${false} | ${false}
${true} | ${false} | ${false} | ${true}
${false} | ${true} | ${false} | ${true}
${false} | ${false} | ${true} | ${true}
${false} | ${true} | ${true} | ${true}
${true} | ${false} | ${true} | ${true}
${true} | ${true} | ${false} | ${true}
${true} | ${true} | ${true} | ${true}
`(
'when isSaving = $isSaving, isTesting = $isTesting, isResetting = $isResetting then isDisabled = $expected',
({ isSaving, isTesting, isResetting, expected }) => {
mutations[types.SET_IS_SAVING](state, isSaving);
mutations[types.SET_IS_TESTING](state, isTesting);
mutations[types.SET_IS_RESETTING](state, isResetting);
expect(isDisabled(state)).toBe(expected);
},
);
});
2020-07-28 23:09:34 +05:30
describe('propsSource', () => {
beforeEach(() => {
2020-11-24 15:15:51 +05:30
state.defaultState = defaultState;
2020-07-28 23:09:34 +05:30
});
2020-11-24 15:15:51 +05:30
it('equals defaultState if inheriting', () => {
expect(propsSource(state, { isInheriting: true })).toEqual(defaultState);
2020-07-28 23:09:34 +05:30
});
it('equals customState if not inheriting', () => {
expect(propsSource(state, { isInheriting: false })).toEqual(customState);
});
});
describe('currentKey', () => {
it('equals `admin` if inheriting', () => {
expect(currentKey(state, { isInheriting: true })).toEqual('admin');
});
it('equals `custom` if not inheriting', () => {
expect(currentKey(state, { isInheriting: false })).toEqual('custom');
});
});
});