2022-08-13 15:12:31 +05:30
|
|
|
import timezoneMock from 'timezone-mock';
|
|
|
|
import {
|
|
|
|
displayAndLogError,
|
|
|
|
getEventIcon,
|
2022-10-11 01:57:18 +05:30
|
|
|
getUtcShiftedDate,
|
2023-04-23 21:23:45 +05:30
|
|
|
getPreviousEventTags,
|
2022-08-13 15:12:31 +05:30
|
|
|
} from '~/issues/show/components/incidents/utils';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { createAlert } from '~/alert';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { mockTimelineEventTags } from './mock_data';
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
jest.mock('~/alert');
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
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', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
['comment', 'issues', 'label', 'status'].forEach((name) => {
|
2022-08-13 15:12:31 +05:30
|
|
|
expect(getEventIcon(name)).toBe(name);
|
|
|
|
});
|
2022-07-23 23:45:48 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a default icon name', () => {
|
|
|
|
expect(getEventIcon('non-existent-icon-name')).toBe('comment');
|
|
|
|
});
|
|
|
|
});
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
describe('getUtcShiftedDate', () => {
|
2022-08-13 15:12:31 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
timezoneMock.register('US/Pacific');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
timezoneMock.unregister();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should shift the date by the timezone offset', () => {
|
|
|
|
const date = new Date();
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const shiftedDate = getUtcShiftedDate();
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
expect(shiftedDate > date).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
describe('getPreviousEventTags', () => {
|
|
|
|
it('should return an empty array, when passed object contains no tags', () => {
|
|
|
|
const nodes = [];
|
|
|
|
const previousTags = getPreviousEventTags(nodes);
|
|
|
|
|
|
|
|
expect(previousTags.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an array of strings, when passed object containing tags', () => {
|
|
|
|
const previousTags = getPreviousEventTags(mockTimelineEventTags.nodes);
|
|
|
|
expect(previousTags.length).toBe(2);
|
|
|
|
expect(previousTags).toContain(mockTimelineEventTags.nodes[0].name);
|
|
|
|
expect(previousTags).toContain(mockTimelineEventTags.nodes[1].name);
|
|
|
|
});
|
|
|
|
});
|
2022-07-23 23:45:48 +05:30
|
|
|
});
|