debian-mirror-gitlab/spec/frontend/issues/show/components/incidents/utils_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-08-13 15:12:31 +05:30
import timezoneMock from 'timezone-mock';
import {
displayAndLogError,
getEventIcon,
getUtcShiftedDateNow,
} 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-13 15:12:31 +05:30
['comment', 'issues', 'status'].forEach((name) => {
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
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);
});
});
2022-07-23 23:45:48 +05:30
});