Skip to content

Commit d81864b

Browse files
committed
Implement theme tests
1 parent 85d0637 commit d81864b

File tree

1 file changed

+84
-11
lines changed

1 file changed

+84
-11
lines changed

cypress/e2e/game/theme.cy.ts

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import { GamePersistentState, GameState } from "../../../src/game";
44
import { Preferences } from "../../../src/preferences";
55

6-
// TODO: Implement these tests
7-
describe.skip("theme", () => {
6+
describe("theme", () => {
87
beforeEach(() => {
98
cy.clearBrowserCache();
109
cy.visit("/", {
@@ -23,11 +22,11 @@ describe.skip("theme", () => {
2322
};
2423
const persistentState: GamePersistentState = {
2524
highscore: 0,
26-
unlockables: {},
25+
unlockables: { classic: true },
2726
hasPlayedBefore: true,
2827
};
2928
const preferences: Preferences = {
30-
theme: "dark",
29+
theme: "standard",
3130
};
3231
window.localStorage.setItem("game-state", JSON.stringify(gameState));
3332
window.localStorage.setItem("persistent-state", JSON.stringify(persistentState));
@@ -39,23 +38,77 @@ describe.skip("theme", () => {
3938
it("should be able to select from any of the available themes", () => {
4039
cy.get(".settings-link").click();
4140

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+
});
4346

4447
cy.get(".setting.theme-switch").click();
4548

4649
cy.get("body").should("have.class", "light");
50+
cy.get("body").should("have.class", "tileset-light");
4751

4852
cy.get(".setting.theme-switch").click();
4953

5054
cy.get("body").should("have.class", "dark");
55+
cy.get("body").should("have.class", "tileset-dark");
5156

5257
cy.get(".setting.theme-switch").click();
5358

5459
cy.get("body").should("have.class", "classic");
60+
cy.get("body").should("have.class", "tileset-modern");
5561

5662
cy.get(".setting.theme-switch").click();
5763

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+
});
59112
});
60113

61114
it("should set the standard theme on page reload if it's enabled in local storage", () => {
@@ -70,7 +123,11 @@ describe.skip("theme", () => {
70123

71124
cy.reload();
72125

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+
});
74131
});
75132

76133
it("should set the light theme on page reload if it's enabled in local storage", () => {
@@ -134,17 +191,29 @@ describe.skip("theme", () => {
134191
// });
135192

136193
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+
});
138199

139200
window.localStorage.removeItem("preferences");
140201

141202
cy.reload();
142203

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+
});
144209
});
145210

146211
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+
});
148217

149218
window.localStorage.setItem(
150219
"preferences",
@@ -155,6 +224,10 @@ describe.skip("theme", () => {
155224

156225
cy.reload();
157226

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+
});
159232
});
160233
});

0 commit comments

Comments
 (0)