summaryrefslogtreecommitdiff
path: root/spec/frontend/error_tracking_settings/components/error_tracking_form_spec.js
blob: 23e57c4bbf102247839baa76783a0a49b1015239 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import Vuex from 'vuex';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import { GlButton, GlFormInput } from '@gitlab/ui';
import ErrorTrackingForm from '~/error_tracking_settings/components/error_tracking_form.vue';
import { defaultProps } from '../mock';

const localVue = createLocalVue();
localVue.use(Vuex);

describe('error tracking settings form', () => {
  let wrapper;

  function mountComponent() {
    wrapper = shallowMount(ErrorTrackingForm, {
      localVue,
      propsData: defaultProps,
    });
  }

  beforeEach(() => {
    mountComponent();
  });

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

  describe('an empty form', () => {
    it('is rendered', () => {
      expect(wrapper.findAll(GlFormInput).length).toBe(2);
      expect(wrapper.find(GlFormInput).attributes('id')).toBe('error-tracking-api-host');
      expect(
        wrapper
          .findAll(GlFormInput)
          .at(1)
          .attributes('id'),
      ).toBe('error-tracking-token');

      expect(wrapper.findAll(GlButton).exists()).toBe(true);
    });

    it('is rendered with labels and placeholders', () => {
      const pageText = wrapper.text();

      expect(pageText).toContain('Find your hostname in your Sentry account settings page');
      expect(pageText).toContain(
        "After adding your Auth Token, use the 'Connect' button to load projects",
      );

      expect(pageText).not.toContain('Connection has failed. Re-check Auth Token and try again');
      expect(
        wrapper
          .findAll(GlFormInput)
          .at(0)
          .attributes('placeholder'),
      ).toContain('https://mysentryserver.com');
    });
  });

  describe('after a successful connection', () => {
    beforeEach(() => {
      wrapper.setProps({ connectSuccessful: true });
    });

    it('shows the success checkmark', () => {
      expect(wrapper.find('.js-error-tracking-connect-success').isVisible()).toBe(true);
    });

    it('does not show an error', () => {
      expect(wrapper.text()).not.toContain(
        'Connection has failed. Re-check Auth Token and try again',
      );
    });
  });

  describe('after an unsuccessful connection', () => {
    beforeEach(() => {
      wrapper.setProps({ connectError: true });
    });

    it('does not show the check mark', () => {
      expect(wrapper.find('.js-error-tracking-connect-success').isVisible()).toBe(false);
    });

    it('shows an error', () => {
      expect(wrapper.text()).toContain('Connection has failed. Re-check Auth Token and try again');
    });
  });
});