Welcome to mirror list, hosted at ThFree Co, Russian Federation.

alerts_form_spec.js « components « incidents_settings « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2a27347e40eee3241eaaa01f28cf30453d80523b (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
import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import AlertsSettingsForm from '~/incidents_settings/components/alerts_form.vue';
import { ERROR_MSG } from '~/incidents_settings/constants';
import createFlash from '~/flash';
import { refreshCurrentPage } from '~/lib/utils/url_utility';
import waitForPromises from 'helpers/wait_for_promises';

jest.mock('~/flash');
jest.mock('~/lib/utils/url_utility');

describe('Alert integration settings form', () => {
  let wrapper;

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

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

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

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

  describe('form', () => {
    let mock;

    beforeEach(() => {
      mock = new MockAdapter(axios);
    });

    afterEach(() => {
      mock.restore();
    });

    it('should refresh the page on successful submit', () => {
      mock.onPatch().reply(200);
      findForm().trigger('submit');
      return waitForPromises().then(() => {
        expect(refreshCurrentPage).toHaveBeenCalled();
      });
    });

    it('should display a flah message on unsuccessful submit', () => {
      mock.onPatch().reply(400);
      findForm().trigger('submit');
      return waitForPromises().then(() => {
        expect(createFlash).toHaveBeenCalledWith(expect.stringContaining(ERROR_MSG), 'alert');
      });
    });
  });
});