|
| 1 | +/* @flow strict-local */ |
| 2 | + |
1 | 3 | import deepFreeze from 'deep-freeze';
|
2 | 4 |
|
3 | 5 | import alertWordsReducer from '../alertWordsReducer';
|
4 |
| -import { REGISTER_COMPLETE, EVENT_ALERT_WORDS } from '../../actionConstants'; |
| 6 | +import { EVENT_ALERT_WORDS } from '../../actionConstants'; |
| 7 | +import * as eg from '../../__tests__/lib/exampleData'; |
5 | 8 |
|
6 | 9 | describe('alertWordsReducer', () => {
|
7 | 10 | describe('REGISTER_COMPLETE', () => {
|
8 | 11 | test('when `alert_words` data is provided init state with it', () => {
|
9 |
| - const initialState = deepFreeze([]); |
10 |
| - const action = deepFreeze({ |
11 |
| - type: REGISTER_COMPLETE, |
12 |
| - data: { |
13 |
| - alert_words: ['word', '@mobile-core', 'alert'], |
14 |
| - }, |
15 |
| - }); |
16 |
| - const expectedState = ['word', '@mobile-core', 'alert']; |
17 |
| - |
18 |
| - const actualState = alertWordsReducer(initialState, action); |
19 |
| - |
20 |
| - expect(actualState).toEqual(expectedState); |
| 12 | + const prevState = deepFreeze([]); |
| 13 | + expect( |
| 14 | + alertWordsReducer( |
| 15 | + prevState, |
| 16 | + eg.mkActionRegisterComplete({ alert_words: ['word', '@mobile-core', 'alert'] }), |
| 17 | + ), |
| 18 | + ).toEqual(['word', '@mobile-core', 'alert']); |
21 | 19 | });
|
22 | 20 |
|
23 | 21 | // TODO(#5102): Delete; see comment on implementation.
|
24 | 22 | test('when no `alert_words` data is given reset state', () => {
|
25 |
| - const initialState = deepFreeze(['word']); |
26 |
| - const action = deepFreeze({ |
27 |
| - type: REGISTER_COMPLETE, |
28 |
| - data: {}, |
29 |
| - }); |
30 |
| - const expectedState = []; |
31 |
| - |
32 |
| - const actualState = alertWordsReducer(initialState, action); |
| 23 | + const prevState = deepFreeze(['word']); |
| 24 | + const actualState = alertWordsReducer( |
| 25 | + prevState, |
| 26 | + eg.mkActionRegisterComplete({ |
| 27 | + // Hmm, we should need a Flow suppression here. This property is |
| 28 | + // marked required in InitialData, and this explicit undefined is |
| 29 | + // meant to defy that; see TODO(#5102) above. |
| 30 | + // mkActionRegisterComplete is designed to accept input with this or |
| 31 | + // any property *omitted*… and I think, as a side effect of handling |
| 32 | + // that, Flow mistakenly accepts an explicit undefined here, so it |
| 33 | + // doesn't catch the resulting malformed InitialData. |
| 34 | + alert_words: undefined, |
| 35 | + }), |
| 36 | + ); |
33 | 37 |
|
34 |
| - expect(actualState).toEqual(expectedState); |
| 38 | + expect(actualState).toEqual([]); |
35 | 39 | });
|
36 | 40 | });
|
37 | 41 |
|
38 | 42 | describe('EVENT_ALERT_WORDS', () => {
|
39 | 43 | test('on first call adds new data', () => {
|
40 |
| - const initialState = deepFreeze([]); |
41 |
| - const action = deepFreeze({ |
42 |
| - type: EVENT_ALERT_WORDS, |
43 |
| - alert_words: ['word', '@mobile-core', 'alert'], |
44 |
| - }); |
45 |
| - const expectedState = ['word', '@mobile-core', 'alert']; |
46 |
| - |
47 |
| - const actualState = alertWordsReducer(initialState, action); |
48 |
| - |
49 |
| - expect(actualState).toEqual(expectedState); |
| 44 | + const prevState = deepFreeze([]); |
| 45 | + expect( |
| 46 | + alertWordsReducer( |
| 47 | + prevState, |
| 48 | + deepFreeze({ type: EVENT_ALERT_WORDS, alert_words: ['word', '@mobile-core', 'alert'] }), |
| 49 | + ), |
| 50 | + ).toEqual(['word', '@mobile-core', 'alert']); |
50 | 51 | });
|
51 | 52 |
|
52 | 53 | test('subsequent calls replace existing data', () => {
|
53 |
| - const initialState = deepFreeze(['word', '@mobile-core', 'alert']); |
54 |
| - const action = deepFreeze({ |
55 |
| - type: EVENT_ALERT_WORDS, |
56 |
| - alert_words: ['word', '@mobile-core', 'new alert'], |
57 |
| - }); |
58 |
| - const expectedState = ['word', '@mobile-core', 'new alert']; |
59 |
| - |
60 |
| - const actualState = alertWordsReducer(initialState, action); |
61 |
| - |
62 |
| - expect(actualState).toEqual(expectedState); |
| 54 | + const prevState = deepFreeze(['word', '@mobile-core', 'alert']); |
| 55 | + expect( |
| 56 | + alertWordsReducer( |
| 57 | + prevState, |
| 58 | + deepFreeze({ |
| 59 | + type: EVENT_ALERT_WORDS, |
| 60 | + alert_words: ['word', '@mobile-core', 'new alert'], |
| 61 | + }), |
| 62 | + ), |
| 63 | + ).toEqual(['word', '@mobile-core', 'new alert']); |
63 | 64 | });
|
64 | 65 | });
|
65 | 66 | });
|
0 commit comments