3
3
import { GamePersistentState , GameState } from "../../../src/game" ;
4
4
import { Preferences } from "../../../src/preferences" ;
5
5
6
- // TODO: Implement these tests
7
- describe . skip ( "theme" , ( ) => {
6
+ describe ( "theme" , ( ) => {
8
7
beforeEach ( ( ) => {
9
8
cy . clearBrowserCache ( ) ;
10
9
cy . visit ( "/" , {
@@ -23,11 +22,11 @@ describe.skip("theme", () => {
23
22
} ;
24
23
const persistentState : GamePersistentState = {
25
24
highscore : 0 ,
26
- unlockables : { } ,
25
+ unlockables : { classic : true } ,
27
26
hasPlayedBefore : true ,
28
27
} ;
29
28
const preferences : Preferences = {
30
- theme : "dark " ,
29
+ theme : "standard " ,
31
30
} ;
32
31
window . localStorage . setItem ( "game-state" , JSON . stringify ( gameState ) ) ;
33
32
window . localStorage . setItem ( "persistent-state" , JSON . stringify ( persistentState ) ) ;
@@ -39,23 +38,77 @@ describe.skip("theme", () => {
39
38
it ( "should be able to select from any of the available themes" , ( ) => {
40
39
cy . get ( ".settings-link" ) . click ( ) ;
41
40
42
- cy . get ( "body" ) . should ( "have.class" , "" ) ;
41
+ cy . get ( "body" ) . should ( ( $el ) => {
42
+ const classList = $el [ 0 ] . classList ;
43
+ expect ( classList . length ) . to . equal ( 1 ) ;
44
+ expect ( classList . contains ( "tileset-standard" ) ) . to . be . true ;
45
+ } ) ;
43
46
44
47
cy . get ( ".setting.theme-switch" ) . click ( ) ;
45
48
46
49
cy . get ( "body" ) . should ( "have.class" , "light" ) ;
50
+ cy . get ( "body" ) . should ( "have.class" , "tileset-light" ) ;
47
51
48
52
cy . get ( ".setting.theme-switch" ) . click ( ) ;
49
53
50
54
cy . get ( "body" ) . should ( "have.class" , "dark" ) ;
55
+ cy . get ( "body" ) . should ( "have.class" , "tileset-dark" ) ;
51
56
52
57
cy . get ( ".setting.theme-switch" ) . click ( ) ;
53
58
54
59
cy . get ( "body" ) . should ( "have.class" , "classic" ) ;
60
+ cy . get ( "body" ) . should ( "have.class" , "tileset-modern" ) ;
55
61
56
62
cy . get ( ".setting.theme-switch" ) . click ( ) ;
57
63
58
- cy . get ( "body" ) . should ( "have.class" , "" ) ;
64
+ cy . get ( "body" ) . should ( ( $el ) => {
65
+ const classList = $el [ 0 ] . classList ;
66
+ expect ( classList . length ) . to . equal ( 1 ) ;
67
+ expect ( classList . contains ( "tileset-standard" ) ) . to . be . true ;
68
+ } ) ;
69
+ } ) ;
70
+
71
+ it ( "should not be able to select classic theme if it's locked" , ( ) => {
72
+ cy . visit ( "/" , {
73
+ onBeforeLoad : ( ) => {
74
+ const persistentState : GamePersistentState = {
75
+ highscore : 0 ,
76
+ unlockables : { } ,
77
+ hasPlayedBefore : true ,
78
+ } ;
79
+ const preferences : Preferences = {
80
+ theme : "standard" ,
81
+ } ;
82
+ window . localStorage . setItem ( "persistent-state" , JSON . stringify ( persistentState ) ) ;
83
+ window . localStorage . setItem ( "preferences" , JSON . stringify ( preferences ) ) ;
84
+ } ,
85
+ } ) ;
86
+
87
+ cy . get ( ".settings-link" ) . click ( ) ;
88
+
89
+ cy . get ( "body" ) . should ( ( $el ) => {
90
+ const classList = $el [ 0 ] . classList ;
91
+ expect ( classList . length ) . to . equal ( 1 ) ;
92
+ expect ( classList . contains ( "tileset-standard" ) ) . to . be . true ;
93
+ } ) ;
94
+
95
+ cy . get ( ".setting.theme-switch" ) . click ( ) ;
96
+
97
+ cy . get ( "body" ) . should ( "have.class" , "light" ) ;
98
+ cy . get ( "body" ) . should ( "have.class" , "tileset-light" ) ;
99
+
100
+ cy . get ( ".setting.theme-switch" ) . click ( ) ;
101
+
102
+ cy . get ( "body" ) . should ( "have.class" , "dark" ) ;
103
+ cy . get ( "body" ) . should ( "have.class" , "tileset-dark" ) ;
104
+
105
+ cy . get ( ".setting.theme-switch" ) . click ( ) ;
106
+
107
+ cy . get ( "body" ) . should ( ( $el ) => {
108
+ const classList = $el [ 0 ] . classList ;
109
+ expect ( classList . length ) . to . equal ( 1 ) ;
110
+ expect ( classList . contains ( "tileset-standard" ) ) . to . be . true ;
111
+ } ) ;
59
112
} ) ;
60
113
61
114
it ( "should set the standard theme on page reload if it's enabled in local storage" , ( ) => {
@@ -70,7 +123,11 @@ describe.skip("theme", () => {
70
123
71
124
cy . reload ( ) ;
72
125
73
- cy . get ( "body" ) . should ( "have.class" , "" ) ;
126
+ cy . get ( "body" ) . should ( ( $el ) => {
127
+ const classList = $el [ 0 ] . classList ;
128
+ expect ( classList . length ) . to . equal ( 1 ) ;
129
+ expect ( classList . contains ( "tileset-standard" ) ) . to . be . true ;
130
+ } ) ;
74
131
} ) ;
75
132
76
133
it ( "should set the light theme on page reload if it's enabled in local storage" , ( ) => {
@@ -134,17 +191,29 @@ describe.skip("theme", () => {
134
191
// });
135
192
136
193
it ( "should default to standard theme if no entry exists in local storage for theme" , ( ) => {
137
- cy . get ( "body" ) . should ( "have.class" , "" ) ;
194
+ cy . get ( "body" ) . should ( ( $el ) => {
195
+ const classList = $el [ 0 ] . classList ;
196
+ expect ( classList . length ) . to . equal ( 1 ) ;
197
+ expect ( classList . contains ( "tileset-standard" ) ) . to . be . true ;
198
+ } ) ;
138
199
139
200
window . localStorage . removeItem ( "preferences" ) ;
140
201
141
202
cy . reload ( ) ;
142
203
143
- cy . get ( "body" ) . should ( "have.class" , "" ) ;
204
+ cy . get ( "body" ) . should ( ( $el ) => {
205
+ const classList = $el [ 0 ] . classList ;
206
+ expect ( classList . length ) . to . equal ( 1 ) ;
207
+ expect ( classList . contains ( "tileset-standard" ) ) . to . be . true ;
208
+ } ) ;
144
209
} ) ;
145
210
146
211
it ( "should default to standard theme if theme is set to invalid value in local storage" , ( ) => {
147
- cy . get ( "body" ) . should ( "have.class" , "" ) ;
212
+ cy . get ( "body" ) . should ( ( $el ) => {
213
+ const classList = $el [ 0 ] . classList ;
214
+ expect ( classList . length ) . to . equal ( 1 ) ;
215
+ expect ( classList . contains ( "tileset-standard" ) ) . to . be . true ;
216
+ } ) ;
148
217
149
218
window . localStorage . setItem (
150
219
"preferences" ,
@@ -155,6 +224,10 @@ describe.skip("theme", () => {
155
224
156
225
cy . reload ( ) ;
157
226
158
- cy . get ( "body" ) . should ( "have.class" , "" ) ;
227
+ cy . get ( "body" ) . should ( ( $el ) => {
228
+ const classList = $el [ 0 ] . classList ;
229
+ expect ( classList . length ) . to . equal ( 1 ) ;
230
+ expect ( classList . contains ( "tileset-standard" ) ) . to . be . true ;
231
+ } ) ;
159
232
} ) ;
160
233
} ) ;
0 commit comments