summaryrefslogtreecommitdiff
path: root/spec/frontend/error_tracking/components/error_tracking_actions_spec.js
blob: 7ed4e5f6b055bfbb6c3e766b961141190a4b2cf0 (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
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import ErrorTrackingActions from '~/error_tracking/components/error_tracking_actions.vue';

describe('Error Tracking Actions', () => {
  let wrapper;

  function mountComponent(props) {
    wrapper = shallowMount(ErrorTrackingActions, {
      propsData: {
        error: {
          id: '1',
          title: 'PG::ConnectionBad: FATAL',
          type: 'error',
          userCount: 0,
          count: '52',
          firstSeen: '2019-05-30T07:21:46Z',
          lastSeen: '2019-11-06T03:21:39Z',
          status: 'unresolved',
        },
        ...props,
      },
      stubs: { GlButton },
    });
  }

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

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

  const findButtons = () => wrapper.findAll(GlButton);

  describe('when error status is unresolved', () => {
    it('renders the correct actions buttons to allow ignore and resolve', async () => {
      expect(findButtons().exists()).toBe(true);

      await nextTick();
      expect(findButtons().at(0).attributes('title')).toBe('Ignore');
      expect(findButtons().at(1).attributes('title')).toBe('Resolve');
    });
  });

  describe('when error status is ignored', () => {
    beforeEach(() => {
      mountComponent({ error: { status: 'ignored' } });
    });

    it('renders the correct action button to undo ignore', async () => {
      expect(findButtons().exists()).toBe(true);

      await nextTick();
      expect(findButtons().at(0).attributes('title')).toBe('Undo Ignore');
    });
  });

  describe('when error status is resolved', () => {
    beforeEach(() => {
      mountComponent({ error: { status: 'resolved' } });
    });

    it('renders the correct action button to undo unresolve', async () => {
      expect(findButtons().exists()).toBe(true);

      await nextTick();
      expect(findButtons().at(1).attributes('title')).toBe('Unresolve');
    });
  });
});