Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ci_group_variables_spec.js « components « ci_variable_list « ci « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b364f098a3adffb1b49298049c728d9446dc732c (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
102
103
104
105
106
107
108
109
110
111
112
113
import { shallowMount } from '@vue/test-utils';
import { TYPENAME_GROUP } from '~/graphql_shared/constants';
import { convertToGraphQLId } from '~/graphql_shared/utils';

import ciGroupVariables from '~/ci/ci_variable_list/components/ci_group_variables.vue';
import ciVariableShared from '~/ci/ci_variable_list/components/ci_variable_shared.vue';
import {
  ADD_MUTATION_ACTION,
  DELETE_MUTATION_ACTION,
  UPDATE_MUTATION_ACTION,
} from '~/ci/ci_variable_list/constants';
import getGroupEnvironments from '~/ci/ci_variable_list/graphql/queries/group_environments.query.graphql';
import getGroupVariables from '~/ci/ci_variable_list/graphql/queries/group_variables.query.graphql';
import addGroupVariable from '~/ci/ci_variable_list/graphql/mutations/group_add_variable.mutation.graphql';
import deleteGroupVariable from '~/ci/ci_variable_list/graphql/mutations/group_delete_variable.mutation.graphql';
import updateGroupVariable from '~/ci/ci_variable_list/graphql/mutations/group_update_variable.mutation.graphql';

const mockProvide = {
  groupPath: '/group',
  groupId: 12,
};

describe('Ci Group Variable wrapper', () => {
  let wrapper;

  const findCiShared = () => wrapper.findComponent(ciVariableShared);

  const createComponent = ({ featureFlags } = {}) => {
    wrapper = shallowMount(ciGroupVariables, {
      provide: {
        ...mockProvide,
        glFeatures: {
          ciGroupEnvScopeGraphql: false,
          groupScopedCiVariables: false,
          ...featureFlags,
        },
      },
    });
  };

  describe('Props', () => {
    beforeEach(() => {
      createComponent();
    });

    it('are passed down the correctly to ci_variable_shared', () => {
      expect(findCiShared().props()).toEqual({
        id: convertToGraphQLId(TYPENAME_GROUP, mockProvide.groupId),
        areScopedVariablesAvailable: false,
        componentName: 'GroupVariables',
        entity: 'group',
        fullPath: mockProvide.groupPath,
        hideEnvironmentScope: false,
        mutationData: {
          [ADD_MUTATION_ACTION]: addGroupVariable,
          [UPDATE_MUTATION_ACTION]: updateGroupVariable,
          [DELETE_MUTATION_ACTION]: deleteGroupVariable,
        },
        queryData: {
          ciVariables: {
            lookup: expect.any(Function),
            query: getGroupVariables,
          },
        },
        refetchAfterMutation: false,
      });
    });
  });

  describe('groupScopedCiVariables feature flag', () => {
    describe('When enabled', () => {
      beforeEach(() => {
        createComponent({ featureFlags: { groupScopedCiVariables: true } });
      });

      it('Passes down `true` to variable shared component', () => {
        expect(findCiShared().props('areScopedVariablesAvailable')).toBe(true);
      });
    });

    describe('When disabled', () => {
      beforeEach(() => {
        createComponent();
      });

      it('Passes down `false` to variable shared component', () => {
        expect(findCiShared().props('areScopedVariablesAvailable')).toBe(false);
      });
    });
  });

  describe('ciGroupEnvScopeGraphql feature flag', () => {
    describe('When enabled', () => {
      beforeEach(() => {
        createComponent({ featureFlags: { ciGroupEnvScopeGraphql: true } });
      });

      it('Passes down environments query to variable shared component', () => {
        expect(findCiShared().props('queryData').environments.query).toBe(getGroupEnvironments);
      });
    });

    describe('When disabled', () => {
      beforeEach(() => {
        createComponent();
      });

      it('Does not pass down environments query to variable shared component', () => {
        expect(findCiShared().props('queryData').environments).toBe(undefined);
      });
    });
  });
});