summaryrefslogtreecommitdiff
path: root/spec/frontend/integrations/edit/store/getters_spec.js
blob: 7d4532a10598d7e6322eb6ba15c95038775265fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import {
  currentKey,
  isInheriting,
  isDisabled,
  propsSource,
} from '~/integrations/edit/store/getters';
import createState from '~/integrations/edit/store/state';
import mutations from '~/integrations/edit/store/mutations';
import * as types from '~/integrations/edit/store/mutation_types';
import { mockIntegrationProps } from '../mock_data';

describe('Integration form store getters', () => {
  let state;
  const customState = { ...mockIntegrationProps, type: 'CustomState' };
  const defaultState = { ...mockIntegrationProps, type: 'DefaultState' };

  beforeEach(() => {
    state = createState({ customState });
  });

  describe('isInheriting', () => {
    describe('when defaultState is null', () => {
      it('returns false', () => {
        expect(isInheriting(state)).toBe(false);
      });
    });

    describe('when defaultState is an object', () => {
      beforeEach(() => {
        state.defaultState = defaultState;
      });

      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);
        });
      });
    });
  });

  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);
      },
    );
  });

  describe('propsSource', () => {
    beforeEach(() => {
      state.defaultState = defaultState;
    });

    it('equals defaultState if inheriting', () => {
      expect(propsSource(state, { isInheriting: true })).toEqual(defaultState);
    });

    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');
    });
  });
});