1
- import { ComponentAction , ComponentActionRecord } from '../models/masterState' ;
2
1
import componentActionRecord from '../models/masterState' ;
3
2
4
3
describe ( 'Master State unit tests' , ( ) => {
5
- describe ( 'ComponentAction and ComponentActionRecord type tests' , ( ) => {
6
- it ( 'ComponentAction should be an object with string keys and array values' , ( ) => {
7
- const componentAction : ComponentAction = {
8
- 'http://test.com' : [ 'action1' , 'action2' ] ,
9
- } ;
10
- expect ( componentAction ) . toEqual ( expect . any ( Object ) ) ;
11
- expect ( Object . keys ( componentAction ) ) . toEqual ( expect . arrayContaining ( [ 'http://test.com' ] ) ) ;
12
- expect ( Array . isArray ( componentAction [ 'http://test.com' ] ) ) . toBe ( true ) ;
13
- } ) ;
14
-
15
- it ( 'ComponentActionRecord should be an array of ComponentAction' , ( ) => {
16
- const componentActionRecord : ComponentActionRecord = [
17
- { 'http://test.com' : [ 'action1' , 'action2' ] } ,
18
- { 'http://test.com/2' : [ 'action3' , 'action4' ] } ,
19
- ] ;
20
- expect ( componentActionRecord ) . toEqual ( expect . any ( Array ) ) ;
21
- expect ( componentActionRecord . length ) . toBe ( 2 ) ;
22
- expect ( componentActionRecord [ 0 ] ) . toEqual (
23
- expect . objectContaining ( { 'http://test.com' : expect . any ( Array ) } ) ,
24
- ) ;
25
- expect ( componentActionRecord [ 1 ] ) . toEqual (
26
- expect . objectContaining ( { 'http://test.com/2' : expect . any ( Array ) } ) ,
27
- ) ;
28
- } ) ;
29
-
30
- it ( 'ComponentAction should be an object with string keys and array values' , ( ) => {
31
- const componentAction : ComponentAction = {
32
- 'http://test.com' : [ 'action1' , 'action2' ] ,
33
- } ;
34
- expect ( componentAction ) . toEqual ( expect . any ( Object ) ) ;
35
- expect ( Object . keys ( componentAction ) ) . toEqual ( expect . arrayContaining ( [ 'http://test.com' ] ) ) ;
36
- expect ( Array . isArray ( componentAction [ 'http://test.com' ] ) ) . toBe ( true ) ;
37
- } ) ;
38
-
39
- it ( 'ComponentActionRecord should be an array of ComponentActions' , ( ) => {
40
- const componentActionRecord : ComponentActionRecord = [
41
- { 'http://test.com' : [ 'action1' , 'action2' ] } ,
42
- { 'http://test.com/2' : [ 'action3' , 'action4' ] } ,
43
- ] ;
44
- expect ( componentActionRecord ) . toEqual ( expect . any ( Array ) ) ;
45
- expect ( componentActionRecord . length ) . toBe ( 2 ) ;
46
- expect ( componentActionRecord [ 0 ] ) . toEqual (
47
- expect . objectContaining ( { 'http://test.com' : expect . any ( Array ) } ) ,
48
- ) ;
49
- expect ( componentActionRecord [ 1 ] ) . toEqual (
50
- expect . objectContaining ( { 'http://test.com/2' : expect . any ( Array ) } ) ,
51
- ) ;
52
- } ) ;
53
- } ) ;
4
+ // describe('ComponentAction and ComponentActionRecord type tests', () => {
5
+ // it('ComponentAction should be an object with string keys and array values', () => {
6
+ // const componentAction: ComponentAction = {
7
+ // 'http://test.com': ['action1', 'action2'],
8
+ // };
9
+ // expect(componentAction).toEqual(expect.any(Object));
10
+ // expect(Object.keys(componentAction)).toEqual(expect.arrayContaining(['http://test.com']));
11
+ // expect(Array.isArray(componentAction['http://test.com'])).toBe(true);
12
+ // });
13
+
14
+ // it('ComponentActionRecord should be an array of ComponentAction', () => {
15
+ // const componentActionRecord: ComponentActionRecord = [
16
+ // { 'http://test.com': ['action1', 'action2'] },
17
+ // { 'http://test.com/2': ['action3', 'action4'] },
18
+ // ];
19
+ // expect(componentActionRecord).toEqual(expect.any(Array));
20
+ // expect(componentActionRecord.length).toBe(2);
21
+ // expect(componentActionRecord[0]).toEqual(
22
+ // expect.objectContaining({ 'http://test.com': expect.any(Array) }),
23
+ // );
24
+ // expect(componentActionRecord[1]).toEqual(
25
+ // expect.objectContaining({ 'http://test.com/2': expect.any(Array) }),
26
+ // );
27
+ // });
28
+
29
+ // it('ComponentAction should be an object with string keys and array values', () => {
30
+ // const componentAction: ComponentAction = {
31
+ // 'http://test.com': ['action1', 'action2'],
32
+ // };
33
+ // expect(componentAction).toEqual(expect.any(Object));
34
+ // expect(Object.keys(componentAction)).toEqual(expect.arrayContaining(['http://test.com']));
35
+ // expect(Array.isArray(componentAction['http://test.com'])).toBe(true);
36
+ // });
37
+
38
+ // it('ComponentActionRecord should be an array of ComponentActions', () => {
39
+ // const componentActionRecord: ComponentActionRecord = [
40
+ // { 'http://test.com': ['action1', 'action2'] },
41
+ // { 'http://test.com/2': ['action3', 'action4'] },
42
+ // ];
43
+ // expect(componentActionRecord).toEqual(expect.any(Array));
44
+ // expect(componentActionRecord.length).toBe(2);
45
+ // expect(componentActionRecord[0]).toEqual(
46
+ // expect.objectContaining({ 'http://test.com': expect.any(Array) }),
47
+ // );
48
+ // expect(componentActionRecord[1]).toEqual(
49
+ // expect.objectContaining({ 'http://test.com/2': expect.any(Array) }),
50
+ // );
51
+ // });
52
+ // });
54
53
55
54
describe ( 'componentActionRecord unit tests' , ( ) => {
56
55
const component1 = { state : 'dummy state' , props : { } } ;
57
56
const component2 = { state : 'dummy state2' , props : { } } ;
58
57
const component3 = { state : 'dummy state3' , props : { } } ;
59
-
58
+ let index1 , index2 , index3 ;
60
59
beforeEach ( ( ) => {
61
60
componentActionRecord . clear ( ) ;
62
- } ) ;
63
-
64
- describe ( 'saveNew' , ( ) => {
65
- it ( 'should add a new component to componentActionRecord and return its index' , ( ) => {
66
- const index1 = componentActionRecord . saveNew ( component1 ) ;
67
- const index2 = componentActionRecord . saveNew ( component2 ) ;
68
- const index3 = componentActionRecord . saveNew ( component3 ) ;
69
-
70
- expect ( index1 ) . toEqual ( 0 ) ;
71
- expect ( index2 ) . toEqual ( 1 ) ;
72
- expect ( index3 ) . toEqual ( 2 ) ;
73
- expect ( componentActionRecord . getAllComponents ( ) ) . toEqual ( [
74
- component1 ,
75
- component2 ,
76
- component3 ,
77
- ] ) ;
78
- } ) ;
61
+ index1 = componentActionRecord . saveNew ( component1 ) ;
62
+ index2 = componentActionRecord . saveNew ( component2 ) ;
63
+ index3 = componentActionRecord . saveNew ( component3 ) ;
79
64
} ) ;
80
65
81
66
describe ( 'clear' , ( ) => {
@@ -91,48 +76,53 @@ describe('Master State unit tests', () => {
91
76
} ) ;
92
77
} ) ;
93
78
79
+ describe ( 'saveNew' , ( ) => {
80
+ it ( 'should add a new component to componentActionRecord and return its index' , ( ) => {
81
+ expect ( index1 ) . toEqual ( 0 ) ;
82
+ expect ( index2 ) . toEqual ( 1 ) ;
83
+ expect ( index3 ) . toEqual ( 2 ) ;
84
+
85
+ expect ( componentActionRecord . getAllComponents ( ) ) . toHaveLength ( 3 ) ;
86
+
87
+ expect ( componentActionRecord . getAllComponents ( ) [ index1 ] ) . toBe ( component1 ) ;
88
+ expect ( componentActionRecord . getAllComponents ( ) [ index2 ] ) . toBe ( component2 ) ;
89
+ expect ( componentActionRecord . getAllComponents ( ) [ index3 ] ) . toBe ( component3 ) ;
90
+ } ) ;
91
+ } ) ;
92
+
94
93
describe ( 'getComponentByIndex' , ( ) => {
95
94
it ( 'should return the component at the specified index' , ( ) => {
96
- componentActionRecord . saveNew ( component1 ) ;
97
- componentActionRecord . saveNew ( component2 ) ;
98
-
99
- expect ( componentActionRecord . getComponentByIndex ( 0 ) ) . toEqual ( component1 ) ;
100
- expect ( componentActionRecord . getComponentByIndex ( 1 ) ) . toEqual ( component2 ) ;
95
+ expect ( componentActionRecord . getComponentByIndex ( index1 ) ) . toBe ( component1 ) ;
96
+ expect ( componentActionRecord . getComponentByIndex ( index2 ) ) . toBe ( component2 ) ;
97
+ expect ( componentActionRecord . getComponentByIndex ( index3 ) ) . toBe ( component3 ) ;
101
98
} ) ;
102
99
103
100
it ( 'should return undefined when passed an index that does not exist' , ( ) => {
104
- expect ( componentActionRecord . getComponentByIndex ( 0 ) ) . toBeUndefined ( ) ;
101
+ expect ( componentActionRecord . getComponentByIndex ( 3 ) ) . toBeUndefined ( ) ;
105
102
} ) ;
106
103
} ) ;
107
104
108
105
describe ( 'getComponentByIndexHooks' , ( ) => {
109
106
it ( 'should return the components at the specified indices' , ( ) => {
110
- componentActionRecord . saveNew ( component1 ) ;
111
- componentActionRecord . saveNew ( component2 ) ;
112
- componentActionRecord . saveNew ( component3 ) ;
113
-
114
- expect ( componentActionRecord . getComponentByIndexHooks ( [ 0 ] ) ) . toEqual ( [ component1 ] ) ;
115
- expect ( componentActionRecord . getComponentByIndexHooks ( [ 1 , 2 ] ) ) . toEqual ( [
107
+ expect ( componentActionRecord . getComponentByIndexHooks ( [ index1 ] ) ) . toContain ( component1 ) ;
108
+ expect ( componentActionRecord . getComponentByIndexHooks ( [ 0 , 1 , 2 ] ) ) . toEqual ( [
109
+ component1 ,
116
110
component2 ,
117
111
component3 ,
118
112
] ) ;
119
113
} ) ;
120
114
121
115
it ( 'should return undefined when passed an empty array' , ( ) => {
122
- expect ( componentActionRecord . getComponentByIndexHooks ( ) ) . toBeUndefined ( ) ;
116
+ expect ( componentActionRecord . getComponentByIndexHooks ( [ ] ) ) . toEqual ( [ ] ) ;
123
117
} ) ;
124
118
125
119
it ( 'should return undefined when passed an index that does not exist' , ( ) => {
126
- expect ( componentActionRecord . getComponentByIndexHooks ( [ 0 ] ) ) . toBeUndefined ( ) ;
120
+ expect ( componentActionRecord . getComponentByIndexHooks ( [ 3 ] ) ) . toEqual ( [ ] ) ;
127
121
} ) ;
128
122
} ) ;
129
123
130
124
describe ( 'getAllComponents' , ( ) => {
131
125
it ( 'should return all components in componentActionRecord' , ( ) => {
132
- componentActionRecord . saveNew ( component1 ) ;
133
- componentActionRecord . saveNew ( component2 ) ;
134
- componentActionRecord . saveNew ( component3 ) ;
135
-
136
126
expect ( componentActionRecord . getAllComponents ( ) ) . toEqual ( [
137
127
component1 ,
138
128
component2 ,
0 commit comments