|
1 |
| -import masterState from '../masterState' |
| 1 | +import masterState from '../masterState'; |
2 | 2 | import {
|
3 | 3 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
4 | 4 | HookStateItem,
|
5 |
| - HookStates |
| 5 | + HookStates, |
6 | 6 | } from '../types/backendTypes';
|
7 | 7 |
|
8 | 8 | describe('Testing masterState functionality', () => {
|
9 |
| - let hookOne : HookStateItem = {state: 'A', component: 'counter1'}; |
10 |
| - let hookTwo : HookStateItem = {state: 'B', component: 'counter2'}; |
11 |
| - let allHooks : HookStates = [hookOne, hookTwo]; |
12 |
| - masterState.saveNew(hookOne.state, hookOne.component); |
13 |
| - masterState.saveNew(hookTwo.state, hookTwo.component); |
| 9 | + const hookOne : HookStateItem = { state: 'A', component: 'counter1' }; |
| 10 | + const hookTwo : HookStateItem = { state: 'B', component: 'counter2' }; |
| 11 | + const hookThree : HookStateItem = { state: 'C', component: 'counter3' }; |
| 12 | + const allHooks : HookStates = [hookOne, hookTwo]; |
14 | 13 |
|
15 |
| - describe('Save new', () => { |
16 |
| - masterState.saveNew(hookOne.state, hookOne.component); |
17 |
| - masterState.saveNew(hookTwo.state, hookTwo.component); |
18 |
| - }) |
| 14 | + describe('saveNew', () => { |
| 15 | + it('Should return the index of the saved component', () => { |
| 16 | + expect(masterState.saveNew(hookOne.state, hookOne.component)).toBe(0); |
| 17 | + expect(masterState.saveNew(hookTwo.state, hookTwo.component)).toBe(1); |
| 18 | + }); |
| 19 | + }); |
19 | 20 |
|
20 | 21 | describe('getComponentByIndex', () => {
|
21 |
| - it('should be able to get both hook states component', () => { |
| 22 | + it('Should return the component when given a valid index', () => { |
22 | 23 | expect(masterState.getComponentByIndex(0)).toEqual(hookOne.component);
|
23 | 24 | expect(masterState.getComponentByIndex(1)).toEqual(hookTwo.component);
|
24 |
| - }) |
25 |
| - }) |
| 25 | + }); |
| 26 | + it('Should return undefined when given an invalid index', () => { |
| 27 | + expect(masterState.getComponentByIndex(2)).toBe(undefined); |
| 28 | + }); |
| 29 | + }); |
26 | 30 |
|
27 | 31 | describe('getRecordByIndex', () => {
|
28 |
| - it('should be able to get both hook states', () => { |
| 32 | + it('Should return the record when given a valid index', () => { |
29 | 33 | expect(masterState.getRecordByIndex(0)).toEqual(hookOne);
|
30 | 34 | expect(masterState.getRecordByIndex(1)).toEqual(hookTwo);
|
31 |
| - }) |
32 |
| - }) |
| 35 | + }); |
| 36 | + it('Should return undefined when given an invalid index', () => { |
| 37 | + expect(masterState.getRecordByIndex(2)).toBe(undefined); |
| 38 | + }); |
| 39 | + }); |
33 | 40 |
|
34 |
| - |
35 |
| -}) |
| 41 | + describe('getComponentByIndexHooks', () => { |
| 42 | + it('Should return an array of components when given an a valid array of indices', () => { |
| 43 | + expect(masterState.getComponentByIndexHooks([0, 1])).toEqual([hookOne.component, hookTwo.component]); |
| 44 | + }); |
| 45 | + it('Should return an empty array when given an invalid array of indices', () => { |
| 46 | + expect(masterState.getComponentByIndexHooks([2])).toEqual([]); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe('clear', () => { |
| 51 | + it('Should return undefined', () => { |
| 52 | + expect(masterState.clear()).toBe(undefined); |
| 53 | + }); |
| 54 | + it('Should reset the componentActionRecord index', () => { |
| 55 | + expect(masterState.saveNew(hookThree.state, hookThree.component)).toBe(0); |
| 56 | + }); |
| 57 | + it('Should empty the componentActionRecord array', () => { |
| 58 | + expect(masterState.getComponentByIndex(0)).toEqual(hookThree.component); |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments