From 67750d9d558ce919e4428228c4321b2afcea84f7 Mon Sep 17 00:00:00 2001 From: Alexandre Henrique Afonso Campos Date: Sat, 19 Sep 2020 15:23:17 -0300 Subject: [PATCH] Test for sparable information --- .../src/main/components/Interceptor.jsx | 1 - tnoodle-ui/src/test/App.test.js | 89 +++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/tnoodle-ui/src/main/components/Interceptor.jsx b/tnoodle-ui/src/main/components/Interceptor.jsx index 20ae164e1..2504696c5 100644 --- a/tnoodle-ui/src/main/components/Interceptor.jsx +++ b/tnoodle-ui/src/main/components/Interceptor.jsx @@ -14,7 +14,6 @@ class Interceptor extends Component { fetchIntercept.register({ request: function (...request) { // TODO set loading - console.log(request[0]); return request; }, diff --git a/tnoodle-ui/src/test/App.test.js b/tnoodle-ui/src/test/App.test.js index c6e310a13..053c4f78c 100644 --- a/tnoodle-ui/src/test/App.test.js +++ b/tnoodle-ui/src/test/App.test.js @@ -385,3 +385,92 @@ it("Online user", async () => { tnoodleApi.fetchBestMbldAttempt.mockRestore(); tnoodleApi.fetchSuggestedFmcTranslations.mockRestore(); }); + +it("Comfort features should not block zip generation", async () => { + const store = createStore(Reducer); + + // Allow downloads + global.URL.createObjectURL = jest.fn(); + + jest.spyOn(wcaApi, "isLogged").mockImplementation(() => true); + + jest.spyOn( + wcaApi, + "getUpcomingManageableCompetitions" + ).mockImplementation(() => Promise.resolve(competitions)); + + jest.spyOn(wcaApi, "fetchMe").mockImplementation(() => Promise.resolve(me)); + + jest.spyOn( + wcaApi, + "getCompetitionJson" + ).mockImplementation((competitionId) => + Promise.resolve(wcifs[competitionId]) + ); + + // Comfort features + jest.spyOn(tnoodleApi, "fetchBestMbldAttempt").mockImplementation(() => + Promise.resolve(undefined) + ); + + jest.spyOn( + tnoodleApi, + "fetchSuggestedFmcTranslations" + ).mockImplementation(() => Promise.resolve(undefined)); + + // Render component + await act(async () => { + render( + + + , + container + ); + }); + + let competitionButtons = Array.from( + container.querySelectorAll("ul button") + ); + + let scrambleButton = container.querySelector("form button"); + + // Click competitions + for (let i = 0; i < competitionButtons.length; i++) { + await act(async () => { + competitionButtons[i].dispatchEvent( + new MouseEvent("click", { bubbles: true }) + ); + }); + + // Round changes from previous tests also changes defaultWcif + // to avoid empty rounds, we try to change rounds here + // It should have effect just on in Manual Selection + fireEvent.change(container.querySelector("select"), { + target: { value: 1 }, + }); + + await act(async () => { + scrambleButton.dispatchEvent( + new MouseEvent("click", { bubbles: true }) + ); + }); + + await act(async () => { + scrambleButton.dispatchEvent( + new MouseEvent("click", { bubbles: true }) + ); + }); + } + + expect(tnoodleApi.fetchZip).toHaveBeenCalledTimes( + competitionButtons.length + ); + + global.URL.createObjectURL.mockRestore(); + wcaApi.isLogged.mockRestore(); + wcaApi.getUpcomingManageableCompetitions.mockRestore(); + wcaApi.fetchMe.mockRestore(); + wcaApi.getCompetitionJson.mockRestore(); + tnoodleApi.fetchBestMbldAttempt.mockRestore(); + tnoodleApi.fetchSuggestedFmcTranslations.mockRestore(); +});