2019-01-21 21:13:09 +03:00
import React from 'react' ;
import { mount } from 'enzyme' ;
import { MemoryRouter } from 'react-router-dom' ;
import { I18nProvider } from '@lingui/react' ;
import NotificationListItem from '../../src/components/NotificationsList/NotificationListItem' ;
describe ( '<NotificationListItem />' , ( ) => {
let wrapper ;
afterEach ( ( ) => {
if ( wrapper ) {
wrapper . unmount ( ) ;
wrapper = null ;
}
} ) ;
test ( 'initially renders succesfully' , ( ) => {
wrapper = mount (
< I18nProvider >
< MemoryRouter >
< NotificationListItem / >
< / MemoryRouter >
< / I18nProvider >
) ;
expect ( wrapper . length ) . toBe ( 1 ) ;
} ) ;
test ( 'handles success click when toggle is on' , ( ) => {
2019-01-24 00:52:14 +03:00
const toggleNotification = jest . fn ( ) ;
2019-01-21 21:13:09 +03:00
wrapper = mount (
< I18nProvider >
< MemoryRouter >
< NotificationListItem
itemId = { 9000 }
successTurnedOn
2019-01-24 00:52:14 +03:00
toggleNotification = { toggleNotification }
2019-01-21 21:13:09 +03:00
/ >
< / MemoryRouter >
< / I18nProvider >
) ;
wrapper . find ( 'Switch' ) . first ( ) . find ( 'input' ) . simulate ( 'change' ) ;
2019-01-24 00:52:14 +03:00
expect ( toggleNotification ) . toHaveBeenCalledWith ( 9000 , true , 'success' ) ;
2019-01-21 21:13:09 +03:00
} ) ;
test ( 'handles success click when toggle is off' , ( ) => {
2019-01-24 00:52:14 +03:00
const toggleNotification = jest . fn ( ) ;
2019-01-21 21:13:09 +03:00
wrapper = mount (
< I18nProvider >
< MemoryRouter >
< NotificationListItem
itemId = { 9000 }
successTurnedOn = { false }
2019-01-24 00:52:14 +03:00
toggleNotification = { toggleNotification }
2019-01-21 21:13:09 +03:00
/ >
< / MemoryRouter >
< / I18nProvider >
) ;
wrapper . find ( 'Switch' ) . first ( ) . find ( 'input' ) . simulate ( 'change' ) ;
2019-01-24 00:52:14 +03:00
expect ( toggleNotification ) . toHaveBeenCalledWith ( 9000 , false , 'success' ) ;
2019-01-21 21:13:09 +03:00
} ) ;
test ( 'handles error click when toggle is on' , ( ) => {
2019-01-24 00:52:14 +03:00
const toggleNotification = jest . fn ( ) ;
2019-01-21 21:13:09 +03:00
wrapper = mount (
< I18nProvider >
< MemoryRouter >
< NotificationListItem
itemId = { 9000 }
errorTurnedOn
2019-01-24 00:52:14 +03:00
toggleNotification = { toggleNotification }
2019-01-21 21:13:09 +03:00
/ >
< / MemoryRouter >
< / I18nProvider >
) ;
wrapper . find ( 'Switch' ) . at ( 1 ) . find ( 'input' ) . simulate ( 'change' ) ;
2019-01-24 00:52:14 +03:00
expect ( toggleNotification ) . toHaveBeenCalledWith ( 9000 , true , 'error' ) ;
2019-01-21 21:13:09 +03:00
} ) ;
test ( 'handles error click when toggle is off' , ( ) => {
2019-01-24 00:52:14 +03:00
const toggleNotification = jest . fn ( ) ;
2019-01-21 21:13:09 +03:00
wrapper = mount (
< I18nProvider >
< MemoryRouter >
< NotificationListItem
itemId = { 9000 }
errorTurnedOn = { false }
2019-01-24 00:52:14 +03:00
toggleNotification = { toggleNotification }
2019-01-21 21:13:09 +03:00
/ >
< / MemoryRouter >
< / I18nProvider >
) ;
wrapper . find ( 'Switch' ) . at ( 1 ) . find ( 'input' ) . simulate ( 'change' ) ;
2019-01-24 00:52:14 +03:00
expect ( toggleNotification ) . toHaveBeenCalledWith ( 9000 , false , 'error' ) ;
2019-01-21 21:13:09 +03:00
} ) ;
} ) ;