summaryrefslogtreecommitdiff
path: root/spec/frontend/incidents_settings/components/alerts_form_spec.js
blob: 2516e8afdfacc6c54fc4e56630794bcc1fd170f9 (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
import { shallowMount } from '@vue/test-utils';
import AlertsSettingsForm from '~/incidents_settings/components/alerts_form.vue';

describe('Alert integration settings form', () => {
  let wrapper;
  const service = { updateSettings: jest.fn().mockResolvedValue() };

  const findForm = () => wrapper.find({ ref: 'settingsForm' });

  beforeEach(() => {
    wrapper = shallowMount(AlertsSettingsForm, {
      provide: {
        service,
        alertSettings: {
          issueTemplateKey: 'selecte_tmpl',
          createIssue: true,
          sendEmail: false,
          templates: [],
          autoCloseIncident: true,
        },
      },
    });
  });

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

  describe('default state', () => {
    it('should match the default snapshot', () => {
      expect(wrapper.element).toMatchSnapshot();
    });
  });

  describe('form', () => {
    it('should call service `updateSettings` on submit', () => {
      findForm().trigger('submit');
      expect(service.updateSettings).toHaveBeenCalledWith(
        expect.objectContaining({
          create_issue: wrapper.vm.createIssueEnabled,
          issue_template_key: wrapper.vm.issueTemplate,
          send_email: wrapper.vm.sendEmailEnabled,
          auto_close_incident: wrapper.vm.autoCloseIncident,
        }),
      );
    });
  });
});