-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
48 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
ui/src/app/notifications/component/NotificationList.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { NotificationList } from './NotificationList'; | ||
import { NotificationContext } from '../hoc/Notifications'; | ||
|
||
jest.mock('../../i18n/hooks', () => ({ | ||
useTranslation: (value) => value | ||
})); | ||
|
||
describe('Notification List', () => { | ||
it('should render notifications', () => { | ||
const dispatch = jest.fn(); | ||
const state = { notifications: [{id: 'foo', body: 'foo', type: 'danger'}] }; | ||
render( | ||
<NotificationContext.Provider value={{ state, dispatch }}> | ||
<NotificationList /> | ||
</NotificationContext.Provider> | ||
); | ||
|
||
expect(screen.getByText('foo')).toBeInTheDocument(); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createNotificationAction, reducer, removeNotificationAction } from './Notifications'; | ||
|
||
describe('Notifications HOC', () => { | ||
describe('reducer', () => { | ||
it('should add a notification to its state list', () => { | ||
const state = reducer({ | ||
notifications: [] | ||
}, createNotificationAction('foo')); | ||
expect(state.notifications.length).toBe(1); | ||
}) | ||
|
||
it('should remove a notification to its state list', () => { | ||
const state = reducer({ | ||
notifications: [ | ||
{ | ||
id: 'foo' | ||
} | ||
] | ||
}, removeNotificationAction('foo')); | ||
|
||
expect(state.notifications.length).toBe(0); | ||
}) | ||
}); | ||
}); |