Skip to content

Commit 825d46d

Browse files
author
Blessan Mathew
authored
Merge pull request #12 from blessenm/#11/startup-test
#11 wip
2 parents 694e829 + 1c4f639 commit 825d46d

File tree

9 files changed

+58
-29
lines changed

9 files changed

+58
-29
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"build": "react-scripts build",
2727
"test": "react-scripts test",
2828
"test:ci": "yarn run test --watchAll=false",
29+
"test:cov": "yarn run test --watchAll=false --coverage",
2930
"eject": "react-scripts eject",
3031
"format": "prettier --write"
3132
},

src/App.test.js

-9
This file was deleted.

src/App.css src/components/App.css

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
4+
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
5+
sans-serif;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
28
font-size: 16px;
39
background-color: #282c34;
410
color: #ffffff;

src/App.js src/components/App.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { useState, useEffect } from "react";
22
import "./App.css";
33

4-
import useFirebase from "./hooks/useFirebase";
4+
import useFirebase from "../hooks/useFirebase";
55

6-
import Login from "./components/Login";
7-
import Add from "./components/Add";
8-
import View from "./components/View";
6+
import Login from "./Login";
7+
import Add from "./Add";
8+
import View from "./View";
99

1010
function App() {
1111
const [words, setWords] = useState([]);

src/components/View.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22

3-
function View({ words }) {
3+
function View({ words = [] }) {
44
return (
55
<section className="wb-view">
66
{words.map(({ word, article, meaning, note, type }, index) => (

src/components/__tests__/App.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from "react";
2+
import { render, wait } from "@testing-library/react";
3+
import App from "../App";
4+
import useFirebase from "../../hooks/useFirebase";
5+
6+
jest.mock("../../hooks/useFirebase");
7+
8+
test("Login Page", async () => {
9+
useFirebase.mockReturnValue({
10+
user: null,
11+
getAllWords: () =>
12+
Promise.resolve([
13+
{ type: "noun", word: "Tisch", article: "Der", meaning: "Table" }
14+
])
15+
});
16+
17+
const { getByDisplayValue, getByPlaceholderText, getByText } = render(
18+
<App />
19+
);
20+
const usernameInput = getByDisplayValue(/blessanm86/i);
21+
const passwordInput = getByPlaceholderText(/password/i);
22+
const loginButton = getByText(/login/i);
23+
24+
expect(usernameInput).toBeInTheDocument();
25+
expect(passwordInput).toBeInTheDocument();
26+
expect(loginButton).toBeInTheDocument();
27+
expect(loginButton).toBeDisabled();
28+
29+
await wait();
30+
});

src/hooks/__tests__/useForm.js

+15
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,19 @@ describe("Hooks: useForm Tests", () => {
109109

110110
expect(result.current.isValid).toBe(true);
111111
});
112+
113+
test("Should return the isValue as false if any input has empty value", () => {
114+
const { result } = renderHook(() => useForm(INITIAL_STATE));
115+
116+
act(() => {
117+
result.current.change({
118+
target: {
119+
name: "password",
120+
value: ""
121+
}
122+
});
123+
});
124+
125+
expect(result.current.isValid).toBe(false);
126+
});
112127
});

src/index.css

-13
This file was deleted.

src/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from "react";
22
import ReactDOM from "react-dom";
3-
import "./index.css";
4-
import App from "./App";
3+
import App from "./components/App";
54
import * as serviceWorker from "./serviceWorker";
65

76
ReactDOM.render(<App />, document.getElementById("root"));

0 commit comments

Comments
 (0)