2021-03-08 18:12:59 +05:30
|
|
|
import { GlDropdownItem } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2021-03-08 18:12:59 +05:30
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
|
|
|
import CanaryIngress from '~/environments/components/canary_ingress.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { CANARY_UPDATE_MODAL } from '~/environments/constants';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { rolloutStatus } from './graphql/mock_data';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
describe('/environments/components/canary_ingress.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const setWeightTo = (weightWrapper, x) =>
|
|
|
|
weightWrapper
|
2022-08-27 11:52:29 +05:30
|
|
|
.findAllComponents(GlDropdownItem)
|
2021-03-08 18:12:59 +05:30
|
|
|
.at(x / 5)
|
|
|
|
.vm.$emit('click');
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
const createComponent = (props = {}, options = {}) => {
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper = mount(CanaryIngress, {
|
|
|
|
propsData: {
|
|
|
|
canaryIngress: {
|
|
|
|
canary_weight: 60,
|
|
|
|
},
|
2022-04-04 11:22:00 +05:30
|
|
|
...props,
|
2021-03-08 18:12:59 +05:30
|
|
|
},
|
|
|
|
directives: {
|
2023-05-27 22:25:52 +05:30
|
|
|
GlModal: createMockDirective('gl-modal'),
|
2021-03-08 18:12:59 +05:30
|
|
|
},
|
2022-04-04 11:22:00 +05:30
|
|
|
...options,
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const options = stableWeightDropdown.findAllComponents(GlDropdownItem);
|
2021-03-08 18:12:59 +05:30
|
|
|
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
|
2022-08-27 11:52:29 +05:30
|
|
|
.findAllComponents(GlDropdownItem)
|
2021-03-08 18:12:59 +05:30
|
|
|
.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
|
2022-08-27 11:52:29 +05:30
|
|
|
.findAllComponents(GlDropdownItem)
|
2021-03-08 18:12:59 +05:30
|
|
|
.wrappers.forEach((w, i) => expect(w.text()).toBe((i * 5).toString()));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is set to open the change modal', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
canaryWeightDropdown
|
2022-08-27 11:52:29 +05:30
|
|
|
.findAllComponents(GlDropdownItem)
|
2022-04-04 11:22:00 +05:30
|
|
|
.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');
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|