1
- import SlotMachine , { Direction } from '../../lib/slot-machine' ;
1
+ import SlotMachine from '../../lib' ;
2
+ import { Direction } from '../../lib/types' ;
2
3
import { getVisibleTile , render } from '../setup' ;
3
4
4
5
describe ( 'Getters' , ( ) => {
@@ -17,36 +18,22 @@ describe('Getters', () => {
17
18
} ) ;
18
19
const tile = getVisibleTile ( machine ) ;
19
20
20
- expect ( machine . visibleTile ) . toBe ( index ) ;
21
21
expect ( machine . active ) . toBe ( index ) ;
22
- expect ( tile ?. innerHTML ) . toBe ( text ) ;
22
+ expect ( tile ?. element ?. innerHTML ) . toBe ( text ) ;
23
23
} ) ;
24
24
} ) ;
25
25
} ) ;
26
26
27
- describe ( 'random' , ( ) => {
28
- it ( `gets random index between min and max tiles length` , ( ) => {
29
- machine = render ( ) ;
30
-
31
- for ( let i = 0 ; i < 1000 ; i ++ ) {
32
- const random = machine . random ;
33
-
34
- expect ( random ) . toBeGreaterThanOrEqual ( 0 ) ;
35
- expect ( random ) . toBeLessThanOrEqual ( 2 ) ;
36
- }
37
- } ) ;
38
- } ) ;
39
-
40
27
describe ( 'custom' , ( ) => {
41
28
it ( `receives active element when calling randomize` , ( ) => {
42
29
const randomize = jest . fn ( ) . mockReturnValue ( 1 ) ;
43
30
44
31
machine = render ( {
45
32
randomize,
46
33
} ) ;
34
+ machine . shuffle ( 2 ) ;
47
35
48
- expect ( machine . custom ) . toBeGreaterThanOrEqual ( 0 ) ;
49
- expect ( randomize ) . toHaveBeenCalledWith ( machine . active ) ;
36
+ expect ( randomize ) . toHaveBeenCalledWith ( machine . active , 3 ) ;
50
37
} ) ;
51
38
52
39
it ( `gets custom element from randomize function` , ( ) => {
@@ -56,60 +43,32 @@ describe('Getters', () => {
56
43
machine = render ( {
57
44
randomize,
58
45
} ) ;
46
+ machine . shuffle ( 2 ) ;
59
47
60
- expect ( machine . custom ) . toBe ( index ) ;
61
48
expect ( randomize ) . toHaveBeenCalled ( ) ;
62
49
} ) ;
63
-
64
- [ - 1 , 9 ] . forEach ( ( index ) => {
65
- it ( `sets 0 when custom element is out of bounds: ${ index } ` , ( ) => {
66
- const randomize = jest . fn ( ) . mockReturnValue ( index ) ;
67
-
68
- machine = render ( {
69
- randomize,
70
- } ) ;
71
-
72
- expect ( machine . custom ) . toBe ( 0 ) ;
73
- expect ( randomize ) . toHaveBeenCalled ( ) ;
74
- } ) ;
75
- } ) ;
76
-
77
- it ( `gets random element` , ( ) => {
78
- machine = render ( ) ;
79
-
80
- for ( let i = 0 ; i < 1000 ; i ++ ) {
81
- const custom = machine . custom ;
82
-
83
- expect ( custom ) . toBeGreaterThanOrEqual ( 0 ) ;
84
- expect ( custom ) . toBeLessThanOrEqual ( 2 ) ;
85
- }
86
- } ) ;
87
50
} ) ;
88
51
89
52
describe ( 'Direction' , ( ) => {
90
53
[
91
54
{
92
55
direction : 'up' as Direction ,
93
56
result : {
94
- key : 'up' ,
95
57
initial : - 20 ,
96
- first : 0 ,
97
- last : - 80 ,
98
- to : - 60 ,
99
- firstToLast : - 80 ,
100
- lastToFirst : 0 ,
58
+ from : - 60 ,
59
+ to : 0 ,
60
+ nextReset : 0 ,
61
+ prevReset : - 80 ,
101
62
} ,
102
63
} ,
103
64
{
104
65
direction : 'down' as Direction ,
105
66
result : {
106
- key : 'down' ,
107
67
initial : - 20 ,
108
- first : - 80 ,
109
- last : 0 ,
110
- to : - 20 ,
111
- firstToLast : - 80 ,
112
- lastToFirst : 0 ,
68
+ from : - 20 ,
69
+ to : - 80 ,
70
+ nextReset : 0 ,
71
+ prevReset : - 80 ,
113
72
} ,
114
73
} ,
115
74
] . forEach ( ( testCase ) => {
@@ -160,48 +119,4 @@ describe('Getters', () => {
160
119
expect ( machine . prevIndex ) . toBe ( 1 ) ;
161
120
} ) ;
162
121
} ) ;
163
-
164
- describe ( 'visible' , ( ) => {
165
- it ( 'is visible' , ( ) => {
166
- machine = render ( ) ;
167
-
168
- expect ( machine . visible ) . toBeTruthy ( ) ;
169
- } ) ;
170
-
171
- it . skip ( 'is not visible when "top" is out of bounds' , ( ) => {
172
- machine = render ( ) ;
173
-
174
- machine . element . style . position = 'absolute' ;
175
- machine . element . style . top = '-100px' ;
176
-
177
- expect ( machine . visible ) . toBeFalsy ( ) ;
178
- } ) ;
179
-
180
- it . skip ( 'is not visible when "bottom" is out of bounds' , ( ) => {
181
- machine = render ( ) ;
182
-
183
- machine . element . style . position = 'absolute' ;
184
- machine . element . style . bottom = '-100px' ;
185
-
186
- expect ( machine . visible ) . toBeFalsy ( ) ;
187
- } ) ;
188
-
189
- it . skip ( 'is not visible when "left" is out of bounds' , ( ) => {
190
- machine = render ( ) ;
191
-
192
- machine . element . style . position = 'absolute' ;
193
- machine . element . style . left = '-100px' ;
194
-
195
- expect ( machine . visible ) . toBeFalsy ( ) ;
196
- } ) ;
197
-
198
- it . skip ( 'is not visible when "right" is out of bounds' , ( ) => {
199
- machine = render ( ) ;
200
-
201
- machine . element . style . position = 'absolute' ;
202
- machine . element . style . right = '-100px' ;
203
-
204
- expect ( machine . visible ) . toBeFalsy ( ) ;
205
- } ) ;
206
- } ) ;
207
122
} ) ;
0 commit comments