-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for actions and Card component
- Loading branch information
Elrey Belmonti
committed
Jul 13, 2020
1 parent
eca3823
commit f02aa9d
Showing
9 changed files
with
140 additions
and
11 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,16 @@ | ||
import { getTriangle, restTriangle } from "./index"; | ||
import { FIND_TRIANGLE, REST_TRIANGLE } from "../constants"; | ||
|
||
describe("actions", () => { | ||
it("getTriangle()", () => { | ||
const payload = { side1: "5", side2: "5", side3: "5" }; | ||
const expectedAction = { type: FIND_TRIANGLE, payload }; | ||
expect(getTriangle(payload)).toEqual(expectedAction); | ||
}); | ||
|
||
it("restTriangle()", () => { | ||
const payload = { side1: "", side2: "", side3: "" }; | ||
const expectedAction = { type: REST_TRIANGLE, payload }; | ||
expect(restTriangle(payload)).toEqual(expectedAction); | ||
}); | ||
}); |
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,22 @@ | ||
import React from "react"; | ||
import { render, screen } from "../../test-utils"; | ||
import Card from "./Card"; | ||
import { State, TType } from "../../types"; | ||
|
||
const data: State[] = [ | ||
{ type: "equilateral", side1: "5", side2: "5", side3: "5" }, | ||
{ type: "scalene", side1: "5", side2: "6", side3: "7" }, | ||
{ type: "isosceles", side1: "5", side2: "5", side3: "6" }, | ||
]; | ||
describe("<Card/>", () => { | ||
for (const index in data) { | ||
it("renders Card component", () => { | ||
render(<Card />, { | ||
initialState: data[index], | ||
}); | ||
const obj: TType = data[index].type as TType; | ||
const type: string = obj.slice(0, 1).toUpperCase() + obj.slice(1); | ||
expect(screen.getByText(type)).toBeInTheDocument(); | ||
}); | ||
} | ||
}); |
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
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,73 @@ | ||
import React, { ReactElement, ReactNode, ComponentType } from "react"; | ||
import { | ||
render as rtlRender, | ||
RenderResult, | ||
RenderOptions, | ||
} from "@testing-library/react"; | ||
import { createStore, Store } from "redux"; | ||
import { Provider } from "react-redux"; | ||
import { ThemeProvider } from "styled-components"; | ||
import { theme, GlobalStyles } from "./styles"; | ||
import rootReducer, { initialState as defaultState } from "./reducers"; | ||
import { State } from "./types"; | ||
|
||
type AllProvidersProps = { | ||
children: ReactElement | ReactElement[] | ReactNode; | ||
}; | ||
|
||
type OptionsType = { | ||
initialState?: Partial<State>; | ||
store?: Store; | ||
} & RenderOptions; | ||
|
||
const render = ( | ||
ui: ReactElement, | ||
{ | ||
initialState, | ||
store = createStore(rootReducer, { | ||
...defaultState, | ||
...initialState, | ||
}), | ||
...renderOptions | ||
}: OptionsType | ||
): RenderResult => { | ||
const Wrapper = ({ children }: AllProvidersProps): ReactElement => { | ||
return ( | ||
<Provider store={store}> | ||
<ThemeProvider theme={theme}> | ||
<GlobalStyles /> | ||
{children} | ||
</ThemeProvider> | ||
</Provider> | ||
); | ||
}; | ||
return rtlRender(ui, { | ||
wrapper: Wrapper as ComponentType, | ||
...renderOptions, | ||
}); | ||
}; | ||
|
||
// const Wrapper = ({ children }: AllProvidersProps): ReactElement => { | ||
// return ( | ||
// <Provider store={store}> | ||
// <ThemeProvider theme={theme}> | ||
// <GlobalStyles /> | ||
// {children} | ||
// </ThemeProvider> | ||
// </Provider> | ||
// ); | ||
// }; | ||
|
||
// const render = ( | ||
// ui: ReactElement, | ||
// state: State, | ||
// store: Store = createStore(reducer, state) | ||
// options?: RenderOptions = | ||
// ): RenderResult => | ||
// render(ui, { wrapper: Wrapper as ComponentType, ...options }); | ||
|
||
// re-export everything | ||
export * from "@testing-library/react"; | ||
|
||
// override render method | ||
export { render }; |
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 |
---|---|---|
|
@@ -1655,6 +1655,13 @@ | |
"@types/prop-types" "*" | ||
csstype "^2.2.0" | ||
|
||
"@types/redux-mock-store@^1.0.2": | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/@types/redux-mock-store/-/redux-mock-store-1.0.2.tgz#c27d5deadfb29d8514bdb0fc2cadae6feea1922d" | ||
integrity sha512-6LBtAQBN34i7SI5X+Qs4zpTEZO1tTDZ6sZ9fzFjYwTl3nLQXaBtwYdoV44CzNnyKu438xJ1lSIYyw0YMvunESw== | ||
dependencies: | ||
redux "^4.0.5" | ||
|
||
"@types/stack-utils@^1.0.1": | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" | ||
|
@@ -6800,6 +6807,11 @@ lodash._reinterpolate@^3.0.0: | |
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" | ||
integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0= | ||
|
||
lodash.isplainobject@^4.0.6: | ||
version "4.0.6" | ||
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" | ||
integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs= | ||
|
||
[email protected], lodash.memoize@^4.1.2: | ||
version "4.1.2" | ||
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" | ||
|
@@ -9115,6 +9127,13 @@ redent@^3.0.0: | |
indent-string "^4.0.0" | ||
strip-indent "^3.0.0" | ||
|
||
redux-mock-store@^1.5.4: | ||
version "1.5.4" | ||
resolved "https://registry.yarnpkg.com/redux-mock-store/-/redux-mock-store-1.5.4.tgz#90d02495fd918ddbaa96b83aef626287c9ab5872" | ||
integrity sha512-xmcA0O/tjCLXhh9Fuiq6pMrJCwFRaouA8436zcikdIpYWWCjU76CRk+i2bHx8EeiSiMGnB85/lZdU3wIJVXHTA== | ||
dependencies: | ||
lodash.isplainobject "^4.0.6" | ||
|
||
redux@^4.0.0, redux@^4.0.5: | ||
version "4.0.5" | ||
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f" | ||
|