|
| 1 | +/** |
| 2 | + * External dependencies |
| 3 | + */ |
| 4 | +import deepFreeze from 'deep-freeze'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Internal dependencies |
| 8 | + */ |
| 9 | +import { widgetSavingLock } from '../reducer'; |
| 10 | + |
| 11 | +describe( 'state', () => { |
| 12 | + describe( 'widgetSavingLock', () => { |
| 13 | + it( 'returns empty object by default', () => { |
| 14 | + const state = widgetSavingLock( undefined, {} ); |
| 15 | + |
| 16 | + expect( state ).toEqual( {} ); |
| 17 | + } ); |
| 18 | + |
| 19 | + it( 'returns correct widget saving locks when locks added and removed', () => { |
| 20 | + let state = widgetSavingLock( undefined, { |
| 21 | + type: 'LOCK_WIDGET_SAVING', |
| 22 | + lockName: 'test-lock', |
| 23 | + } ); |
| 24 | + |
| 25 | + expect( state ).toEqual( { |
| 26 | + 'test-lock': true, |
| 27 | + } ); |
| 28 | + |
| 29 | + state = widgetSavingLock( deepFreeze( state ), { |
| 30 | + type: 'LOCK_WIDGET_SAVING', |
| 31 | + lockName: 'test-lock-2', |
| 32 | + } ); |
| 33 | + |
| 34 | + expect( state ).toEqual( { |
| 35 | + 'test-lock': true, |
| 36 | + 'test-lock-2': true, |
| 37 | + } ); |
| 38 | + |
| 39 | + state = widgetSavingLock( deepFreeze( state ), { |
| 40 | + type: 'UNLOCK_WIDGET_SAVING', |
| 41 | + lockName: 'test-lock', |
| 42 | + } ); |
| 43 | + |
| 44 | + expect( state ).toEqual( { |
| 45 | + 'test-lock-2': true, |
| 46 | + } ); |
| 47 | + |
| 48 | + state = widgetSavingLock( deepFreeze( state ), { |
| 49 | + type: 'UNLOCK_WIDGET_SAVING', |
| 50 | + lockName: 'test-lock-2', |
| 51 | + } ); |
| 52 | + |
| 53 | + expect( state ).toEqual( {} ); |
| 54 | + } ); |
| 55 | + } ); |
| 56 | +} ); |
0 commit comments