Skip to content
Snippets Groups Projects
Commit 961351d8 authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Merge branch 'test-setup' into 'dev'

Test setup

See merge request !8
parents 38239a37 84c0b24b
No related branches found
No related tags found
2 merge requests!11Basic implementation of login page,!8Test setup
Pipeline #11483 failed
...@@ -6,6 +6,7 @@ stages: ...@@ -6,6 +6,7 @@ stages:
build: build:
stage: build stage: build
script: script:
- npm install --global yarn - npm install --force --global yarn
- yarn install - yarn install
- yarn test
- yarn build - yarn build
...@@ -38,7 +38,13 @@ yarn run ...@@ -38,7 +38,13 @@ yarn run
``` ```
## Useful resources ## Useful resources
[Typescript documentation react](https://www.typescriptlang.org/docs/handbook/react.html)
[MDN](https://developer.mozilla.org/en-US/)
[Documentazione material ui: framework css utilizzato](https://material-ui.com/)
[react calendar app](https://codesandbox.io/s/kkyvoj97pv?from-embed=&file=/src/index.js)
[codesandbox, utile per vedere altri progetti creati con framework](https://codesandbox.io/) [codesandbox, utile per vedere altri progetti creati con framework](https://codesandbox.io/)
[awesome css list](https://github.com/awesome-css-group/awesome-css)
[react calendar app](https://codesandbox.io/s/kkyvoj97pv?from-embed=&file=/src/index.js)
import React from 'react'; import React from 'react';
import { render, screen } from '@testing-library/react'; import { render, screen } from '@testing-library/react';
import App from './App'; import { App } from './App';
test('renders learn react link', () => { describe('<App />', () => {
render(<App />); it('renders without crashing', () => {
const linkElement = screen.getByText(/learn react/i); const wrapper = render(<App />);
expect(linkElement).toBeInTheDocument(); expect(wrapper.queryByTestId('App')).toBeTruthy();
});
}); });
import React from 'react'; import React from 'react';
import { Form } from './components/LoginForm/index'; import { LoginForm } from './components/LoginForm/LoginForm';
export const App: React.FC = () => ( export const App: React.FC = () => (
<div className="App"> <div className="App" data-testid="App">
<header className="App-header"> <header className="App-header">
<Form /> <LoginForm />
</header> </header>
</div> </div>
); );
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import { LoginForm } from './LoginForm';
describe('<LoginForm />', () => {
it('it should render form', () => {
const wrapper = render(<LoginForm />);
expect(wrapper.queryByTestId('LoginForm')).toBeTruthy();
});
});
...@@ -21,7 +21,7 @@ const useStyles = makeStyles((theme: Theme) => ...@@ -21,7 +21,7 @@ const useStyles = makeStyles((theme: Theme) =>
}), }),
); );
export const Form: React.FC = () => { export const LoginForm: React.FC = () => {
interface formData { interface formData {
email: string; email: string;
password: string; password: string;
...@@ -35,15 +35,6 @@ export const Form: React.FC = () => { ...@@ -35,15 +35,6 @@ export const Form: React.FC = () => {
}; };
const [formValues, setFormValues] = useState<formData>(defaultValues); const [formValues, setFormValues] = useState<formData>(defaultValues);
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: formValues.email,
password: formValues.password,
}),
};
const handleSubmit = (event: React.FormEvent): void => { const handleSubmit = (event: React.FormEvent): void => {
event.preventDefault(); event.preventDefault();
const errors: Array<string> = []; const errors: Array<string> = [];
...@@ -52,17 +43,17 @@ export const Form: React.FC = () => { ...@@ -52,17 +43,17 @@ export const Form: React.FC = () => {
console.log('Email address not valid'); console.log('Email address not valid');
} else { } else {
console.log(formValues); console.log(formValues);
fetch(
'https://jsonplaceholder.typicode.com/posts',
requestOptions,
).then((response) => response.json());
} }
}; };
const classes = useStyles(); const classes = useStyles();
return ( return (
<form className={classes.form} onSubmit={handleSubmit}> <form
className={classes.form}
onSubmit={handleSubmit}
data-testid="LoginForm"
>
<TextField <TextField
variant="outlined" variant="outlined"
margin="normal" margin="normal"
...@@ -96,6 +87,7 @@ export const Form: React.FC = () => { ...@@ -96,6 +87,7 @@ export const Form: React.FC = () => {
fullWidth fullWidth
variant="contained" variant="contained"
color="primary" color="primary"
data-testid="Submit"
className={classes.submit} className={classes.submit}
> >
Sign In Sign In
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment