-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
251 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
import React from "react"; | ||
import { act } from "react-dom/test-utils"; | ||
|
||
import { render, unmountComponentAtNode } from "react-dom"; | ||
|
||
import { Provider } from "react-redux"; | ||
import store from "../redux/Store"; | ||
|
||
import Main from "./Main"; | ||
|
||
const tnoodleApi = require("../api/tnoodle.api"); | ||
|
||
let container = null; | ||
beforeEach(() => { | ||
// setup a DOM element as a render target | ||
container = document.createElement("div"); | ||
document.body.appendChild(container); | ||
}); | ||
|
||
afterEach(() => { | ||
// cleanup on exiting | ||
unmountComponentAtNode(container); | ||
container.remove(); | ||
container = null; | ||
}); | ||
|
||
it("There should be only 1 button of type submit", async () => { | ||
// Define mock objects | ||
const events = [ | ||
{ | ||
id: "333", | ||
name: "3x3x3", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "222", | ||
name: "2x2x2", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "444", | ||
name: "4x4x4", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "555", | ||
name: "5x5x5", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "666", | ||
name: "6x6x6", | ||
format_ids: ["m", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "777", | ||
name: "7x7x7", | ||
format_ids: ["m", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "333bf", | ||
name: "3x3x3 Blindfolded", | ||
format_ids: ["3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "333fm", | ||
name: "3x3x3 Fewest Moves", | ||
format_ids: ["m", "2", "1"], | ||
can_change_time_limit: false, | ||
is_timed_event: false, | ||
is_fewest_moves: true, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "333oh", | ||
name: "3x3x3 One-Handed", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "clock", | ||
name: "Clock", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "minx", | ||
name: "Megaminx", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "pyram", | ||
name: "Pyraminx", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "skewb", | ||
name: "Skewb", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "sq1", | ||
name: "Square-1", | ||
format_ids: ["a", "3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "444bf", | ||
name: "4x4x4 Blindfolded", | ||
format_ids: ["3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "555bf", | ||
name: "5x5x5 Blindfolded", | ||
format_ids: ["3", "2", "1"], | ||
can_change_time_limit: true, | ||
is_timed_event: true, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: false, | ||
}, | ||
{ | ||
id: "333mbf", | ||
name: "3x3x3 Multiple Blindfolded", | ||
format_ids: ["3", "2", "1"], | ||
can_change_time_limit: false, | ||
is_timed_event: false, | ||
is_fewest_moves: false, | ||
is_multiple_blindfolded: true, | ||
}, | ||
]; | ||
|
||
const formats = { | ||
1: { name: "Best of 1", shortName: "Bo1" }, | ||
2: { name: "Best of 2", shortName: "Bo2" }, | ||
3: { name: "Best of 3", shortName: "Bo3" }, | ||
a: { name: "Average of 5", shortName: "Ao5" }, | ||
m: { name: "Mean of 3", shortName: "Mo3" }, | ||
}; | ||
|
||
const languages = { | ||
da: "Danish", | ||
de: "German", | ||
en: "English", | ||
es: "Spanish", | ||
et: "Estonian", | ||
fi: "Finnish", | ||
fr: "French", | ||
hr: "Croatian", | ||
hu: "Hungarian", | ||
id: "Indonesian", | ||
it: "Italian", | ||
ja: "Japanese", | ||
ko: "Korean", | ||
pl: "Polish", | ||
pt: "Portuguese", | ||
"pt-BR": "Portuguese (Brazil)", | ||
ro: "Romanian", | ||
ru: "Russian", | ||
sl: "Slovenian", | ||
vi: "Vietnamese", | ||
"zh-CN": "Chinese (China)", | ||
"zh-TW": "Chinese (Taiwan)", | ||
}; | ||
|
||
// Turn on mocking behavior | ||
jest.spyOn(tnoodleApi, "fetchWcaEvents").mockImplementation(() => | ||
Promise.resolve(new Response(JSON.stringify(events))) | ||
); | ||
|
||
jest.spyOn(tnoodleApi, "fetchFormats").mockImplementation(() => | ||
Promise.resolve(new Response(JSON.stringify(formats))) | ||
); | ||
|
||
jest.spyOn( | ||
tnoodleApi, | ||
"fetchAvailableFmcTranslations" | ||
).mockImplementation(() => | ||
Promise.resolve(new Response(JSON.stringify(languages))) | ||
); | ||
|
||
// Render component | ||
await act(async () => { | ||
render( | ||
<Provider store={store}> | ||
<Main /> | ||
</Provider>, | ||
container | ||
); | ||
}); | ||
|
||
// There should be no warning | ||
const buttons = container.querySelectorAll("button"); | ||
expect(buttons).toBe(null); | ||
}); |