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

utils_spec.js « incidents « components « show « issues « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0da0114c6541adb14f61d1bd117ac35692b3487d (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
import timezoneMock from 'timezone-mock';
import {
  displayAndLogError,
  getEventIcon,
  getUtcShiftedDateNow,
} from '~/issues/show/components/incidents/utils';
import { createAlert } from '~/flash';

jest.mock('~/flash');

describe('incident utils', () => {
  describe('display and log error', () => {
    it('displays and logs an error', () => {
      const error = new Error('test');
      displayAndLogError(error);

      expect(createAlert).toHaveBeenCalledWith({
        message: 'Something went wrong while fetching incident timeline events.',
        captureError: true,
        error,
      });
    });
  });

  describe('get event icon', () => {
    it('should display a matching event icon name', () => {
      ['comment', 'issues', 'status'].forEach((name) => {
        expect(getEventIcon(name)).toBe(name);
      });
    });

    it('should return a default icon name', () => {
      expect(getEventIcon('non-existent-icon-name')).toBe('comment');
    });
  });

  describe('getUtcShiftedDateNow', () => {
    beforeEach(() => {
      timezoneMock.register('US/Pacific');
    });

    afterEach(() => {
      timezoneMock.unregister();
    });

    it('should shift the date by the timezone offset', () => {
      const date = new Date();

      const shiftedDate = getUtcShiftedDateNow();

      expect(shiftedDate > date).toBe(true);
    });
  });
});