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

actions_spec.js « details « store « error_tracking « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 129760bb7057cbd2bd7f770d384a7a8d0c38c940 (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
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
import * as actions from '~/error_tracking/store/details/actions';
import * as types from '~/error_tracking/store/details/mutation_types';

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

let mock;

describe('Sentry error details store actions', () => {
  beforeEach(() => {
    mock = new MockAdapter(axios);
  });

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

  describe('startPollingDetails', () => {
    const endpoint = '123/details';
    it('should commit SET_ERROR with received response', done => {
      const payload = { error: { id: 1 } };
      mock.onGet().reply(200, payload);
      testAction(
        actions.startPollingDetails,
        { endpoint },
        {},
        [
          { type: types.SET_ERROR, payload: payload.error },
          { type: types.SET_LOADING, payload: false },
        ],
        [],
        () => {
          done();
        },
      );
    });

    it('should show flash on API error', done => {
      mock.onGet().reply(400);

      testAction(
        actions.startPollingDetails,
        { endpoint },
        {},
        [{ type: types.SET_LOADING, payload: false }],
        [],
        () => {
          expect(createFlash).toHaveBeenCalledTimes(1);
          done();
        },
      );
    });
  });

  describe('startPollingStacktrace', () => {
    const endpoint = '123/stacktrace';
    it('should commit SET_ERROR with received response', done => {
      const payload = { error: [1, 2, 3] };
      mock.onGet().reply(200, payload);
      testAction(
        actions.startPollingStacktrace,
        { endpoint },
        {},
        [
          { type: types.SET_STACKTRACE_DATA, payload: payload.error },
          { type: types.SET_LOADING_STACKTRACE, payload: false },
        ],
        [],
        () => {
          done();
        },
      );
    });

    it('should show flash on API error', done => {
      mock.onGet().reply(400);

      testAction(
        actions.startPollingStacktrace,
        { endpoint },
        {},
        [{ type: types.SET_LOADING_STACKTRACE, payload: false }],
        [],
        () => {
          expect(createFlash).toHaveBeenCalledTimes(1);
          done();
        },
      );
    });
  });
});