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

canary_ingress_spec.js « environments « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1d0d9385bfe6355a67a7b35ab177897184857dbc (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
import { mountExtended, extendedWrapper } from 'helpers/vue_test_utils_helper';
import { createMockDirective } from 'helpers/vue_mock_directive';
import CanaryIngress from '~/environments/components/canary_ingress.vue';
import { rolloutStatus } from './graphql/mock_data';

jest.mock('lodash/uniqueId', () => {
  return jest.fn((input) => input);
});

describe('/environments/components/canary_ingress.vue', () => {
  let wrapper;

  const setWeightTo = (weightWrapper, x) => {
    weightWrapper.vm.$emit('select', x);
  };

  const createComponent = (props = {}, options = {}) => {
    wrapper = mountExtended(CanaryIngress, {
      propsData: {
        canaryIngress: {
          canary_weight: 60,
        },
        ...props,
      },
      directives: {
        GlModal: createMockDirective('gl-modal'),
      },
      ...options,
    });
  };

  beforeEach(() => {
    createComponent();
  });

  describe('stable weight', () => {
    let stableWeightDropdown;

    beforeEach(() => {
      stableWeightDropdown = extendedWrapper(wrapper.find('#stable-weight-'));
    });

    it('displays the current stable weight', () => {
      expect(stableWeightDropdown.props('selected')).toBe(40);
    });

    it('emits a change with the new canary weight', () => {
      setWeightTo(stableWeightDropdown, 15);

      expect(wrapper.emitted('change')).toContainEqual([85]);
    });

    it('lists options from 0 to 100 in increments of 5', () => {
      const options = stableWeightDropdown.props('items');
      expect(options).toHaveLength(21);
      options.forEach((option, i) => expect(option.text).toBe((i * 5).toString()));
    });
  });

  describe('canary weight', () => {
    let canaryWeightDropdown;

    beforeEach(() => {
      canaryWeightDropdown = wrapper.find('#canary-weight-');
    });

    it('displays the current canary weight', () => {
      expect(canaryWeightDropdown.props('selected')).toBe(60);
    });

    it('emits a change with the new canary weight', () => {
      setWeightTo(canaryWeightDropdown, 15);

      expect(wrapper.emitted('change')).toContainEqual([15]);
    });

    it('lists options from 0 to 100 in increments of 5', () => {
      const options = canaryWeightDropdown.props('items');
      expect(options).toHaveLength(21);
      options.forEach((option, i) => expect(option.text).toBe((i * 5).toString()));
    });
  });

  describe('graphql', () => {
    beforeEach(() => {
      createComponent({
        graphql: true,
        canaryIngress: rolloutStatus.canaryIngress,
      });
    });

    it('shows the correct weight', () => {
      const canaryWeightDropdown = wrapper.find('#canary-weight-');
      expect(canaryWeightDropdown.props('selected')).toBe(50);
    });
  });
});