Skip to content

Commit

Permalink
Add mock for wcifs
Browse files Browse the repository at this point in the history
  • Loading branch information
campos20 committed Sep 17, 2020
1 parent 83a1d86 commit 31e8ee2
Show file tree
Hide file tree
Showing 3 changed files with 1,015 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tnoodle-ui/src/main/components/Interceptor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Interceptor extends Component {
fetchIntercept.register({
request: function (...request) {
// TODO set loading
console.log(request);
console.log(request[0]);
return request;
},

Expand Down
73 changes: 72 additions & 1 deletion tnoodle-ui/src/test/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Reducer } from "../main/redux/Reducers";
import App from "../App";

import { version, formats, events, languages } from "./mock/tnoodle.api.mock";
import { scrambleProgram } from "./mock/wca.api.mock";
import { scrambleProgram, competitions, me, wcifs } from "./mock/wca.api.mock";

import _ from "lodash";

Expand Down Expand Up @@ -266,3 +266,74 @@ it("Remove 333, add FMC and MBLD", async () => {
laguageKeys.sort()
);
});

it("Online user", async () => {
Object.keys(wcifs).forEach((key) => {
wcifs[key].events.forEach((event) =>
event.rounds.forEach((round) => {
if (round.extensions == null) {
console.log(round);
}
})
);
});

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])
);

jest.spyOn(tnoodleApi, "fetchBestMbldAttempt").mockImplementation(() =>
Promise.resolve(
JSON.stringify({ solved: 70, attempted: 70, time: 3012 })
)
);

jest.spyOn(
tnoodleApi,
"fetchSuggestedFmcTranslations"
).mockImplementation(() =>
Promise.resolve(JSON.stringify(["de", "es", "pt-BR"]))
);

const store = createStore(Reducer);

// Render component
await act(async () => {
render(
<Provider store={store}>
<App />
</Provider>,
container
);
});

let competitionButtons = Array.from(
container.querySelectorAll("ul button")
);

// Skip Manual Selection, click the other buttons
competitionButtons.slice(1, competitionButtons.length).forEach((button) => {
// Select current competition
fireEvent.click(button);
});

//competition;

wcaApi.isLogged.mockRestore();
wcaApi.getUpcomingManageableCompetitions.mockRestore();
wcaApi.fetchMe.mockRestore();
tnoodleApi.fetchBestMbldAttempt.mockRestore();
tnoodleApi.fetchSuggestedFmcTranslations.mockRestore();
});

0 comments on commit 31e8ee2

Please sign in to comment.