summaryrefslogtreecommitdiff
path: root/spec/frontend/error_tracking/store/list/actions_spec.js
blob: 2809bbe834e35f60984fad2d32bcbabb079ce2e4 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import * as actions from '~/error_tracking/store/list/actions';
import * as types from '~/error_tracking/store/list/mutation_types';
import { createAlert } from '~/flash';
import axios from '~/lib/utils/axios_utils';
import httpStatusCodes from '~/lib/utils/http_status';

jest.mock('~/flash.js');

describe('error tracking actions', () => {
  let mock;

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

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

  describe('startPolling', () => {
    it('should start polling for data', () => {
      const payload = { errors: [{ id: 1 }, { id: 2 }] };

      mock.onGet().reply(httpStatusCodes.OK, payload);
      return testAction(
        actions.startPolling,
        {},
        {},
        [
          { type: types.SET_LOADING, payload: true },
          { type: types.SET_PAGINATION, payload: payload.pagination },
          { type: types.SET_ERRORS, payload: payload.errors },
          { type: types.SET_LOADING, payload: false },
        ],
        [{ type: 'stopPolling' }],
      );
    });

    it('should show flash on API error', async () => {
      mock.onGet().reply(httpStatusCodes.BAD_REQUEST);

      await testAction(
        actions.startPolling,
        {},
        {},
        [
          { type: types.SET_LOADING, payload: true },
          { type: types.SET_LOADING, payload: false },
        ],
        [],
      );
      expect(createAlert).toHaveBeenCalledTimes(1);
    });
  });

  describe('restartPolling', () => {
    it('should restart polling', () => {
      testAction(
        actions.restartPolling,
        {},
        {},
        [
          { type: types.SET_ERRORS, payload: [] },
          { type: types.SET_LOADING, payload: true },
        ],
        [],
      );
    });
  });

  describe('searchByQuery', () => {
    it('should search by query', () => {
      const query = 'search';

      testAction(
        actions.searchByQuery,
        query,
        {},
        [
          { type: types.SET_CURSOR, payload: null },
          { type: types.SET_SEARCH_QUERY, payload: query },
          { type: types.ADD_RECENT_SEARCH, payload: query },
        ],
        [{ type: 'stopPolling' }, { type: 'startPolling' }],
      );
    });
  });

  describe('filterByStatus', () => {
    it('should search errors by status', () => {
      const status = 'ignored';

      testAction(
        actions.filterByStatus,
        status,
        {},
        [{ type: types.SET_STATUS_FILTER, payload: status }],
        [{ type: 'stopPolling' }, { type: 'startPolling' }],
      );
    });
  });

  describe('sortByField', () => {
    it('should search by query', () => {
      const field = 'frequency';

      testAction(
        actions.sortByField,
        field,
        {},
        [
          { type: types.SET_CURSOR, payload: null },
          { type: types.SET_SORT_FIELD, payload: field },
        ],
        [{ type: 'stopPolling' }, { type: 'startPolling' }],
      );
    });
  });

  describe('setEndpoint', () => {
    it('should set search endpoint', () => {
      const endpoint = 'https://sentry.io';

      testAction(
        actions.setEndpoint,
        { endpoint },
        {},
        [{ type: types.SET_ENDPOINT, payload: { endpoint } }],
        [],
      );
    });
  });

  describe('fetchPaginatedResults', () => {
    it('should start polling the selected page cursor', () => {
      const cursor = '1576637570000:1:1';
      testAction(
        actions.fetchPaginatedResults,
        cursor,
        {},
        [{ type: types.SET_CURSOR, payload: cursor }],
        [{ type: 'stopPolling' }, { type: 'startPolling' }],
      );
    });
  });
});