Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fabio Mazuchi] Password Generator #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 3 additions & 29 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<html lang="pt">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Password Generator - Fábio Augusto Mazuchi</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
129 changes: 107 additions & 22 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,123 @@
.App {
text-align: center;
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

.App-logo {
height: 40vmin;
pointer-events: none;
main {
padding: 12px 3%;
margin: 20px auto;
width: 90%;
border-radius: 10px;
background-color: #0B112F;
display: flex;
flex-direction: column;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
main h1 {
color: white;
margin-bottom: 20px;
}

form {
display: flex;
flex-direction: column;
}

form button {
background-color: #1D223F;
border: 0;
width: 100%;
border-radius: 8px;
padding: 20px 0;
color: white;
font-size: 18px;
cursor: pointer;
margin-bottom: 20px;
text-transform: uppercase;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
.container {
background-color: #1D223F;
padding: 18px 3%;
display: flex;
margin-bottom: 12px;
border-radius: 8px;
flex-direction: column;
}

label {
display: flex;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
justify-content: space-between;
color: white;
}

.App-link {
color: #61dafb;
p {
margin: 4px;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
.generate {
background-image: linear-gradient(to left, rgb(94, 107, 218), rgb(122, 135, 253));
color: white;
text-align: center;
font-weight: bold;
margin-top: 10px;
font-size: 20px;
}

.generate p {
word-break: break-all;
}

.number p {
font-size: 14px;
color: #696B7F;
text-transform: uppercase;
}

.number span {
color: white;
}

.settings p {
font-size: 14px;
color: #696B7F;
text-transform: uppercase;
}

input[type=range] {
width: 80%;
height: 3px;
}

input[type=checkbox] {
display: none;
}

.check {
width: 60px;
height: 35px;
border-radius: 20px;
background-color: #6E7081;
padding: 4px;
cursor: pointer;
}

.check div {
height: 27px;
background-color: white;
width: 30px;
border-radius: 50%;
}

.select {
background-color: #5E6BDA;
padding-left: 26px;
}

@media screen and (min-width: 700px) {
main {
width: 60%;
}
}
20 changes: 5 additions & 15 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import logo from './logo.svg';
import './App.css';
import Form from './components/Form';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<main>
<h1>Password Generator</h1>
<Form />
</main>
</div>
);
}
Expand Down
35 changes: 31 additions & 4 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
beforeEach(() => {
render(<App />)
});

test('Verifica se existe o titulo "Password Generator"', () => {
const title = screen.getByRole('heading', { name: /password generator/i })
const tamanho = "Password Generator".length;
expect(title.innerHTML.length).toBe(tamanho);
expect(title).toBeInTheDocument();
});

test('Verifica se existe o botao com o texto "Click Generate"', () => {
const btn = screen.getByText(/click generate/i);
const tamanho = "Click Generate".length;
expect(btn.innerHTML.length).toBe(tamanho);
expect(btn).toBeInTheDocument();
});

test('Verifica se ao carregar a página existe o texto "GENERATE PASSWORD"', () => {
const textGenerate = screen.getByText(/generate password/i);
const tamanho = "GENERATE PASSWORD".length;
expect(textGenerate.innerHTML.length).toBe(tamanho);
expect(textGenerate).toBeInTheDocument();
});

test('Verifica se existe uma label com o texto "Include Uppercase"', () => {
const include = screen.getByLabelText(/include uppercase/i);
const tamanho = "Include Uppercase".length;
console.log(include.id);
expect(include.id.length).toBe(tamanho);
expect(include).toBeInTheDocument();
});
31 changes: 31 additions & 0 deletions src/components/Checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { Component } from "react";

class Checkbox extends Component {
render() {
const { textLabel, name, handleChange, checked } = this.props;
return (
<div className="container">
<label htmlFor={textLabel}>
{textLabel}
<input
onChange={handleChange}
name={name}
id={textLabel}
type="checkbox"
/>
{checked ? (
<div id={textLabel} className="check select">
<div></div>
</div>
) : (
<div id={textLabel} className="check">
<div></div>
</div>
)}
</label>
</div>
);
}
}

export default Checkbox;
95 changes: 95 additions & 0 deletions src/components/Form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React, { Component } from "react";
import Checkbox from "./Checkbox";
import Number from "./Number";
import { generatePass } from "../services/password";

class Form extends Component {
constructor() {
super();
this.state = {
upperCase: false,
lowerCase: false,
numbers: false,
symbols: false,
symbols: false,
length: 32,
password: "GENERATE PASSWORD",
};
this.handleChange = this.handleChange.bind(this);
this.getPass = this.getPass.bind(this);
this.addPass = this.addPass.bind(this);
}

handleChange({ target }) {
const { name } = target;
const value = target.type !== "checkbox" ? target.value : target.checked;
this.setState(
{
[name]: value,
},
() => this.getPass()
);
}

getPass() {
const { upperCase, symbols, numbers, length } = this.state;
return generatePass(upperCase, symbols, numbers, length);
}

addPass() {
this.setState({ password: this.getPass() });
localStorage.setItem("password", JSON.stringify(this.getPass()));
}

render() {
const { length, password, upperCase, lowerCase, symbols, numbers } =
this.state;
return (
<form>
<div>
<button onClick={this.addPass} type="button">
Click Generate
</button>
</div>
<section className="number">
<p>
Length: <span>{length}</span>
</p>
<Number name="length" handleChange={this.handleChange} />
</section>
<section className="settings">
<p>settings</p>
<Checkbox
handleChange={this.handleChange}
name="upperCase"
textLabel="Include Uppercase"
checked={upperCase}
/>
<Checkbox
handleChange={this.handleChange}
name="lowerCase"
textLabel="Include Lowercase"
checked={lowerCase}
/>
<Checkbox
handleChange={this.handleChange}
name="numbers"
textLabel="Include Numbers"
checked={numbers}
/>
<Checkbox
handleChange={this.handleChange}
name="symbols"
textLabel="Include Symbols"
checked={symbols}
/>
</section>
<section className="container generate">
<p>{password}</p>
</section>
</form>
);
}
}

export default Form;
Loading