Skip to content

Commit 4d9a11f

Browse files
committed
Add test to ensure only one request is made to the changelog
1 parent ad503f4 commit 4d9a11f

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

cypress/e2e/game/misc.cy.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ describe("misc", () => {
228228
cy.get(".dialog .close").click();
229229
cy.contains("Changelog").should("not.exist");
230230
});
231-
231+
232232
it("should display an error message if the changelog cannot be retrieved", () => {
233233
cy.intercept("GET", "/CHANGELOG.html", { statusCode: 404 }).as("getChangelog");
234234
cy.contains("Changelog").should("not.exist");
@@ -237,5 +237,39 @@ describe("misc", () => {
237237
cy.wait("@getChangelog");
238238
cy.get(".dialog .changelog-error").should("be.visible");
239239
});
240+
241+
it("should only make one request to the changelog", () => {
242+
const interceptedRequests = [];
243+
244+
// Intercept network requests to /CHANGELOG.html
245+
cy.intercept("GET", "/CHANGELOG.html", (req) => {
246+
interceptedRequests.push(req); // Track all intercepted requests
247+
}).as("getChangelog");
248+
249+
// Initial state: no dialog visible
250+
cy.contains("Changelog").should("not.exist");
251+
252+
// First click: Request should be made
253+
cy.get("#changelog-link").click({ force: true });
254+
255+
cy.wait("@getChangelog").then(() => {
256+
expect(interceptedRequests).to.have.length(1); // Only one request should have been made
257+
});
258+
259+
cy.get(".dialog").contains("Changelog").should("be.visible");
260+
261+
// Close the dialog
262+
cy.get(".dialog .close").click();
263+
cy.contains("Changelog").should("not.exist");
264+
265+
// Second click: Request should not fire again
266+
cy.get("#changelog-link").click({ force: true });
267+
cy.get(".dialog").contains("Changelog").should("be.visible");
268+
269+
// Assert that only one request was made
270+
cy.then(() => {
271+
expect(interceptedRequests).to.have.length(1); // Still only one request
272+
});
273+
});
240274
});
241275
});

0 commit comments

Comments
 (0)