Completed
Push — master ( aa59a9...9ba8bc )
by Alejandro
27s queued 10s
created

test/settings/reducers/realTimeUpdates.test.js   A

Complexity

Total Complexity 7
Complexity/F 1

Size

Lines of Code 47
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 29
mnd 0
bc 0
fnc 7
dl 0
loc 47
rs 10
bpm 0
cpm 1
noi 4
c 0
b 0
f 0
1
import reducer, {
2
  LOAD_REAL_TIME_UPDATES,
3
  loadRealTimeUpdates,
4
  setRealTimeUpdates,
5
} from '../../../src/settings/reducers/realTimeUpdates';
6
7
describe('realTimeUpdatesReducer', () => {
8
  const SettingsServiceMock = {
9
    updateSettings: jest.fn(),
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
10
    loadSettings: jest.fn(),
11
  };
12
13
  afterEach(jest.clearAllMocks);
14
15
  describe('reducer', () => {
16
    it('returns realTimeUpdates when action is LOAD_REAL_TIME_UPDATES', () => {
17
      expect(reducer({}, { type: LOAD_REAL_TIME_UPDATES, enabled: true })).toEqual({ enabled: true });
18
    });
19
  });
20
21
  describe('loadRealTimeUpdates', () => {
22
    it.each([
0 ignored issues
show
Bug introduced by
The variable it seems to be never declared. If this is a global, consider adding a /** global: it */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
23
      [{}, true ],
24
      [{ realTimeUpdates: {} }, true ],
25
      [{ realTimeUpdates: { enabled: true } }, true ],
26
      [{ realTimeUpdates: { enabled: false } }, false ],
27
    ])('loads settings and returns LOAD_REAL_TIME_UPDATES action', (loadedSettings, expectedEnabled) => {
28
      SettingsServiceMock.loadSettings.mockReturnValue(loadedSettings);
29
30
      const result = loadRealTimeUpdates(SettingsServiceMock)();
31
32
      expect(result).toEqual({ type: LOAD_REAL_TIME_UPDATES, enabled: expectedEnabled });
33
      expect(SettingsServiceMock.loadSettings).toHaveBeenCalled();
34
    });
35
  });
36
37
  describe('setRealTimeUpdates', () => {
38
    it.each([[ true ], [ false ]])('updates settings with provided value and then loads updates again', (enabled) => {
0 ignored issues
show
Bug introduced by
The variable it seems to be never declared. If this is a global, consider adding a /** global: it */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
39
      const loadRealTimeUpdatesAction = jest.fn();
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
40
41
      setRealTimeUpdates(SettingsServiceMock, loadRealTimeUpdatesAction)(enabled);
42
43
      expect(SettingsServiceMock.updateSettings).toHaveBeenCalledWith({ realTimeUpdates: { enabled } });
44
      expect(loadRealTimeUpdatesAction).toHaveBeenCalled();
45
    });
46
  });
47
});
48