| 1 |
const popUpNotification = require( '../../resources/skins.vector.js/popupNotification.js' ); |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
let testId; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
let testMessage; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
let vectorPopupClass; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
let activeNotification; |
| 22 |
|
| 23 |
describe( 'Popup Notification', () => { |
| 24 |
beforeEach( () => { |
| 25 |
global.window.matchMedia = jest.fn( () => ( {} ) ); |
| 26 |
document.body.style = 'direction: ltr'; |
| 27 |
jest.spyOn( mw.loader, 'using' ) |
| 28 |
.mockImplementation( () => Promise.resolve() ); |
| 29 |
testId = 'test-id'; |
| 30 |
testMessage = 'test message'; |
| 31 |
vectorPopupClass = 'vector-popup-notification'; |
| 32 |
activeNotification = []; |
| 33 |
popUpNotification.hideAll(); |
| 34 |
} ); |
| 35 |
|
| 36 |
afterEach( () => { |
| 37 |
jest.resetModules(); |
| 38 |
} ); |
| 39 |
|
| 40 |
|
| 41 |
test( 'add', async () => { |
| 42 |
const popupWidget = await popUpNotification.add( |
| 43 |
document.body, |
| 44 |
testMessage, |
| 45 |
testId, |
| 46 |
[], |
| 47 |
4000, |
| 48 |
() => {} |
| 49 |
); |
| 50 |
activeNotification[ testId ] = popupWidget; |
| 51 |
expect( activeNotification[ testId ] ).toBeDefined(); |
| 52 |
expect( activeNotification[ testId ].$element ).toBeDefined(); |
| 53 |
expect( activeNotification[ testId ].$element[ 0 ].textContent ) |
| 54 |
.toContain( testMessage ); |
| 55 |
expect( activeNotification[ testId ].$element[ 0 ].classList |
| 56 |
.contains( vectorPopupClass ) ).toBe( true ); |
| 57 |
} ); |
| 58 |
|
| 59 |
|
| 60 |
test( 'hide', async () => { |
| 61 |
const popupWidget = await popUpNotification.add( |
| 62 |
document.body, |
| 63 |
testMessage, |
| 64 |
testId, |
| 65 |
[], |
| 66 |
4000, |
| 67 |
() => {} |
| 68 |
); |
| 69 |
activeNotification[ testId ] = popupWidget; |
| 70 |
expect( activeNotification[ testId ].visible ).toBe( false ); |
| 71 |
popUpNotification.show( activeNotification[ testId ] ); |
| 72 |
expect( activeNotification[ testId ].visible ).toBe( true ); |
| 73 |
popUpNotification.hide( activeNotification[ testId ] ); |
| 74 |
expect( activeNotification[ testId ].visible ).toBe( false ); |
| 75 |
} ); |
| 76 |
|
| 77 |
|
| 78 |
test( 'show', async () => { |
| 79 |
const popupWidget = await popUpNotification.add( |
| 80 |
document.body, |
| 81 |
testMessage, |
| 82 |
testId, |
| 83 |
[], |
| 84 |
4000, |
| 85 |
() => {} |
| 86 |
); |
| 87 |
activeNotification[ testId ] = popupWidget; |
| 88 |
expect( activeNotification[ testId ].visible ).toBe( false ); |
| 89 |
popUpNotification.show( activeNotification[ testId ] ); |
| 90 |
expect( activeNotification[ testId ].visible ).toBe( true ); |
| 91 |
} ); |
| 92 |
|
| 93 |
|
| 94 |
test( 'hideAll', async () => { |
| 95 |
const popupWidget = await popUpNotification.add( |
| 96 |
document.body, |
| 97 |
testMessage, |
| 98 |
testId, |
| 99 |
[], |
| 100 |
4000, |
| 101 |
() => {} |
| 102 |
); |
| 103 |
activeNotification[ testId ] = popupWidget; |
| 104 |
expect( activeNotification[ testId ].visible ).toBe( false ); |
| 105 |
popUpNotification.show( activeNotification[ testId ] ); |
| 106 |
expect( activeNotification[ testId ].visible ).toBe( true ); |
| 107 |
popUpNotification.hideAll(); |
| 108 |
expect( activeNotification[ testId ].visible ).toBe( false ); |
| 109 |
} ); |
| 110 |
} ); |