|
| 1 | +import reducer from '../src/reducer' |
| 2 | +import initialState from '../src/initialState' |
| 3 | + |
| 4 | +describe('i18n reducer', () => { |
| 5 | + it( 'should return the initial state', () => { |
| 6 | + expect( |
| 7 | + reducer( undefined, {} ) |
| 8 | + ).toEqual( initialState ) |
| 9 | + } ) |
| 10 | + |
| 11 | + it( 'should handle SET_CURRENT', () => { |
| 12 | + let newState = Object.assign( {}, initialState ) |
| 13 | + newState.currentLanguage = 'en-US' |
| 14 | + expect( |
| 15 | + reducer( initialState, { |
| 16 | + type: 'SET_CURRENT', |
| 17 | + data: 'en-US' |
| 18 | + } ) |
| 19 | + ).toEqual( |
| 20 | + newState |
| 21 | + ) |
| 22 | + } ) |
| 23 | + |
| 24 | + it( 'should handle SET_LANGUAGES', () => { |
| 25 | + |
| 26 | + let newState = Object.assign( {}, initialState ) |
| 27 | + newState.languages = [ |
| 28 | + { |
| 29 | + code: 'car-CAR', |
| 30 | + name: 'Птичий' |
| 31 | + }, |
| 32 | + { |
| 33 | + code: 'en-US', |
| 34 | + name: 'English (USA)' |
| 35 | + } |
| 36 | + ] |
| 37 | + expect( |
| 38 | + reducer( initialState, { |
| 39 | + type: 'SET_LANGUAGES', |
| 40 | + data: [ |
| 41 | + { |
| 42 | + code: 'car-CAR', |
| 43 | + name: 'Птичий' |
| 44 | + }, |
| 45 | + { |
| 46 | + code: 'en-US', |
| 47 | + name: 'English (USA)' |
| 48 | + } |
| 49 | + ] |
| 50 | + } ) |
| 51 | + ).toEqual( |
| 52 | + newState |
| 53 | + ) |
| 54 | + } ) |
| 55 | + |
| 56 | + it( 'should handle SET_DICTIONARIES', () => { |
| 57 | + |
| 58 | + let newState = Object.assign( {}, initialState ) |
| 59 | + newState.dictionaries = { |
| 60 | + 'car-CAR': { |
| 61 | + 'key_1': 'Первый дефолтный ключ птичьего языка для теста', |
| 62 | + 'key_2': [ '$Count', ' ', [ 'птичка', 'птички', 'птичек' ] ], |
| 63 | + }, |
| 64 | + 'en-US': { |
| 65 | + 'key_1': 'First default key', |
| 66 | + 'key_2': [ '$Count', ' ', [ 'thing', 'things' ] ], |
| 67 | + } |
| 68 | + } |
| 69 | + expect( |
| 70 | + reducer( initialState, { |
| 71 | + type: 'SET_DICTIONARIES', |
| 72 | + data: { |
| 73 | + 'car-CAR': { |
| 74 | + 'key_1': 'Первый дефолтный ключ птичьего языка для теста', |
| 75 | + 'key_2': [ '$Count', ' ', [ 'птичка', 'птички', 'птичек' ] ], |
| 76 | + }, |
| 77 | + 'en-US': { |
| 78 | + 'key_1': 'First default key', |
| 79 | + 'key_2': [ '$Count', ' ', [ 'thing', 'things' ] ], |
| 80 | + } |
| 81 | + } |
| 82 | + } ) |
| 83 | + ).toEqual( |
| 84 | + newState |
| 85 | + ) |
| 86 | + } ) |
| 87 | + |
| 88 | + it( 'should handle ADD_DICTIONARY', () => { |
| 89 | + |
| 90 | + let newState = Object.assign( {}, initialState ) |
| 91 | + newState.dictionaries[ 'new-NEW' ] = { |
| 92 | + 'new_key_1': 'First new default key', |
| 93 | + 'new_key_2': [ '$Count new', ' ', [ 'thing', 'things' ] ], |
| 94 | + } |
| 95 | + |
| 96 | + expect( |
| 97 | + reducer( initialState, { |
| 98 | + type: 'ADD_DICTIONARY', |
| 99 | + data: { |
| 100 | + languageCode: 'new-NEW', |
| 101 | + dictionary: { |
| 102 | + 'new_key_1': 'First new default key', |
| 103 | + 'new_key_2': [ '$Count new', ' ', [ 'thing', 'things' ] ], |
| 104 | + } |
| 105 | + } |
| 106 | + } ) |
| 107 | + ).toEqual( |
| 108 | + newState |
| 109 | + ) |
| 110 | + } ) |
| 111 | + |
| 112 | +}) |
0 commit comments