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: d58f9f9b8a2f0b196d3c144e0027df56978d28b9 (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
114
115
116
117
118
119
120
121
import { GlDropdownItem } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import CanaryIngress from '~/environments/components/canary_ingress.vue';
import { CANARY_UPDATE_MODAL } from '~/environments/constants';
import { rolloutStatus } from './graphql/mock_data';

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

  const setWeightTo = (weightWrapper, x) =>
    weightWrapper
      .findAll(GlDropdownItem)
      .at(x / 5)
      .vm.$emit('click');

  const createComponent = (props = {}, options = {}) => {
    wrapper = mount(CanaryIngress, {
      propsData: {
        canaryIngress: {
          canary_weight: 60,
        },
        ...props,
      },
      directives: {
        GlModal: createMockDirective(),
      },
      ...options,
    });
  };

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

  afterEach(() => {
    if (wrapper) {
      wrapper.destroy();
    }

    wrapper = null;
  });

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

    beforeEach(() => {
      stableWeightDropdown = wrapper.find('[data-testid="stable-weight"]');
    });

    it('displays the current stable weight', () => {
      expect(stableWeightDropdown.props('text')).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.findAll(GlDropdownItem);
      expect(options).toHaveLength(21);
      options.wrappers.forEach((w, i) => expect(w.text()).toBe((i * 5).toString()));
    });

    it('is set to open the change modal', () => {
      stableWeightDropdown
        .findAll(GlDropdownItem)
        .wrappers.forEach((w) =>
          expect(getBinding(w.element, 'gl-modal')).toMatchObject({ value: CANARY_UPDATE_MODAL }),
        );
    });
  });

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

    beforeEach(() => {
      canaryWeightDropdown = wrapper.find('[data-testid="canary-weight"]');
    });

    it('displays the current canary weight', () => {
      expect(canaryWeightDropdown.props('text')).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', () => {
      canaryWeightDropdown
        .findAll(GlDropdownItem)
        .wrappers.forEach((w, i) => expect(w.text()).toBe((i * 5).toString()));
    });

    it('is set to open the change modal', () => {
      canaryWeightDropdown
        .findAll(GlDropdownItem)
        .wrappers.forEach((w) =>
          expect(getBinding(w.element, 'gl-modal')).toMatchObject({ value: CANARY_UPDATE_MODAL }),
        );
    });
  });

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

    it('shows the correct weight', () => {
      const canaryWeightDropdown = wrapper.find('[data-testid="canary-weight"]');
      expect(canaryWeightDropdown.props('text')).toBe('50');
    });
  });
});