2021-05-21 12:10:27 +00:00
|
|
|
import { GlAlert, GlModal, GlToggle } from '@gitlab/ui';
|
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2021-02-01 15:08:56 +00:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-08-17 21:09:56 +00:00
|
|
|
import PagerDutySettingsForm from '~/incidents_settings/components/pagerduty_form.vue';
|
2020-07-16 15:09:38 +00:00
|
|
|
|
|
|
|
describe('Alert integration settings form', () => {
|
|
|
|
let wrapper;
|
|
|
|
const resetWebhookUrl = jest.fn();
|
|
|
|
const service = { updateSettings: jest.fn().mockResolvedValue(), resetWebhookUrl };
|
|
|
|
|
2021-05-21 12:10:27 +00:00
|
|
|
const findWebhookInput = () => wrapper.findByTestId('webhook-url');
|
|
|
|
const findFormToggle = () => wrapper.findComponent(GlToggle);
|
|
|
|
const findModal = () => wrapper.findComponent(GlModal);
|
|
|
|
const findAlert = () => wrapper.findComponent(GlAlert);
|
2020-07-16 15:09:38 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-05-21 12:10:27 +00:00
|
|
|
wrapper = shallowMountExtended(PagerDutySettingsForm, {
|
2020-07-16 15:09:38 +00:00
|
|
|
provide: {
|
|
|
|
service,
|
|
|
|
pagerDutySettings: {
|
|
|
|
active: true,
|
|
|
|
webhookUrl: 'pagerduty.webhook.com',
|
|
|
|
webhookUpdateEndpoint: 'webhook/update',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2021-05-21 12:10:27 +00:00
|
|
|
wrapper.destroy();
|
2020-07-16 15:09:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should match the default snapshot', () => {
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2021-05-21 12:10:27 +00:00
|
|
|
it('should call service `updateSettings` on toggle change', () => {
|
|
|
|
findFormToggle().vm.$emit('change', true);
|
2020-07-16 15:09:38 +00:00
|
|
|
expect(service.updateSettings).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({ pagerduty_active: wrapper.vm.active }),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Webhook reset', () => {
|
|
|
|
it('should make a call for webhook reset and reset form values', async () => {
|
|
|
|
const newWebhookUrl = 'new.webhook.url?token=token';
|
|
|
|
resetWebhookUrl.mockResolvedValueOnce({
|
|
|
|
data: { pagerduty_webhook_url: newWebhookUrl },
|
|
|
|
});
|
|
|
|
findModal().vm.$emit('ok');
|
|
|
|
await waitForPromises();
|
|
|
|
expect(resetWebhookUrl).toHaveBeenCalled();
|
|
|
|
expect(findWebhookInput().attributes('value')).toBe(newWebhookUrl);
|
|
|
|
expect(findAlert().attributes('variant')).toBe('success');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show error message and NOT reset webhook url', async () => {
|
|
|
|
resetWebhookUrl.mockRejectedValueOnce();
|
|
|
|
findModal().vm.$emit('ok');
|
|
|
|
await waitForPromises();
|
|
|
|
expect(findAlert().attributes('variant')).toBe('danger');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|