debian-mirror-gitlab/spec/frontend/environments/canary_update_modal_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

120 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-03-08 18:12:59 +05:30
import { GlAlert, GlModal } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2021-03-08 18:12:59 +05:30
import waitForPromises from 'helpers/wait_for_promises';
import CanaryUpdateModal from '~/environments/components/canary_update_modal.vue';
import updateCanaryIngress from '~/environments/graphql/mutations/update_canary_ingress.mutation.graphql';
describe('/environments/components/canary_update_modal.vue', () => {
let wrapper;
let modal;
let mutate;
2022-08-27 11:52:29 +05:30
const findAlert = () => wrapper.findComponent(GlAlert);
2021-03-08 18:12:59 +05:30
const createComponent = () => {
mutate = jest.fn().mockResolvedValue();
wrapper = mount(CanaryUpdateModal, {
propsData: {
environment: {
name: 'staging',
global_id: 'gid://environments/staging',
},
weight: 60,
visible: true,
},
mocks: {
$apollo: { mutate },
},
});
2022-08-27 11:52:29 +05:30
modal = wrapper.findComponent(GlModal);
2021-03-08 18:12:59 +05:30
};
beforeEach(() => {
createComponent();
});
it('should bind the modal props', () => {
expect(modal.props()).toMatchObject({
modalId: 'confirm-canary-change',
actionPrimary: {
text: 'Change ratio',
2023-05-27 22:25:52 +05:30
attributes: { variant: 'confirm' },
2021-03-08 18:12:59 +05:30
},
actionCancel: { text: 'Cancel' },
});
});
it('should display the new weights', () => {
expect(modal.text()).toContain('Stable: 40');
expect(modal.text()).toContain('Canary: 60');
});
it('should display the affected environment', () => {
expect(modal.text()).toContain(
'You are changing the ratio of the canary rollout for staging compared to the stable deployment to:',
);
});
it('should update the weight on primary action', () => {
modal.vm.$emit('primary');
expect(mutate).toHaveBeenCalledWith({
mutation: updateCanaryIngress,
variables: {
input: {
id: 'gid://environments/staging',
weight: 60,
},
},
});
});
it('should do nothing on cancel', () => {
modal.vm.$emit('secondary');
expect(mutate).not.toHaveBeenCalled();
});
it('should not display an error if there was not one', async () => {
mutate.mockResolvedValue({ data: { environmentsCanaryIngressUpdate: { errors: [] } } });
modal.vm.$emit('primary');
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-08 18:12:59 +05:30
expect(findAlert().exists()).toBe(false);
});
it('should display an error if there was one', async () => {
mutate.mockResolvedValue({ data: { environmentsCanaryIngressUpdate: { errors: ['error'] } } });
modal.vm.$emit('primary');
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-08 18:12:59 +05:30
expect(findAlert().text()).toBe('error');
});
it('should display a generic error if there was a top-level one', async () => {
mutate.mockRejectedValue();
modal.vm.$emit('primary');
await waitForPromises();
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-08 18:12:59 +05:30
expect(findAlert().text()).toBe('Something went wrong. Please try again later');
});
it('hides teh alert on dismiss', async () => {
mutate.mockResolvedValue({ data: { environmentsCanaryIngressUpdate: { errors: ['error'] } } });
modal.vm.$emit('primary');
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-08 18:12:59 +05:30
const alert = findAlert();
alert.vm.$emit('dismiss');
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-08 18:12:59 +05:30
expect(alert.exists()).toBe(false);
});
});