Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jun 18, 2021
1 parent a9deae8 commit e1472c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { fc } from 'jest-fast-check';

import { ProviderList } from './ProviderList';

Expand Down
37 changes: 37 additions & 0 deletions ui/src/app/notifications/component/NotificationItem.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { render, screen } from '@testing-library/react';

import { NotificationItem } from './NotificationItem';
import { NotificationContext, Notifications } from '../hoc/Notifications';

jest.mock('../../i18n/hooks', () => ({
useTranslation: (value) => value
}));

describe('Notifcation Item', () => {
let context;
beforeEach(() => {
jest.useFakeTimers();

context = React.useContext(NotificationContext);
})

it('should change color based on type', () => {
render(<NotificationItem type="danger" body="foo" />, {wrapper: Notifications });
const el = screen.getByText('foo');
expect(el).toBeInTheDocument();
expect(el).toHaveClass('alert-danger')
});

it('should dispatch an event if provided a timeout', () => {

jest.spyOn(context, 'dispatch');

render(<NotificationItem type="danger" body="foo" timeout={5000} />, { wrapper: Notifications });
const el = screen.getByText('foo');

jest.runAllTimers();

expect(context.dispatch).toHaveBeenCalled();
});
})

0 comments on commit e1472c2

Please sign in to comment.