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,
|
2022-08-13 15:12:31 +05:30
|
|
|
} from '~/issues/show/components/incidents/utils';
|
2022-07-23 23:45:48 +05:30
|
|
|
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', () => {
|
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);
|
|
|
|
});
|
|
|
|
});
|
2022-07-23 23:45:48 +05:30
|
|
|
});
|