debian-mirror-gitlab/spec/frontend/issues/show/components/incidents/utils_spec.js
2022-10-11 01:57:18 +05:30

54 lines
1.3 KiB
JavaScript

import timezoneMock from 'timezone-mock';
import {
displayAndLogError,
getEventIcon,
getUtcShiftedDate,
} 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', 'label', 'status'].forEach((name) => {
expect(getEventIcon(name)).toBe(name);
});
});
it('should return a default icon name', () => {
expect(getEventIcon('non-existent-icon-name')).toBe('comment');
});
});
describe('getUtcShiftedDate', () => {
beforeEach(() => {
timezoneMock.register('US/Pacific');
});
afterEach(() => {
timezoneMock.unregister();
});
it('should shift the date by the timezone offset', () => {
const date = new Date();
const shiftedDate = getUtcShiftedDate();
expect(shiftedDate > date).toBe(true);
});
});
});