Skip to content
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
48 changes: 5 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
# Getting Started with Create React App
# input-mask

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This app implements a mask for brazilian currency and points.

## Available Scripts
## How to run

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
- `yarn install` to install dependencies
- `yarn start` to run the app locally
38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

9 changes: 0 additions & 9 deletions src/App.test.tsx

This file was deleted.

31 changes: 0 additions & 31 deletions src/App.tsx

This file was deleted.

18 changes: 18 additions & 0 deletions src/components/Toast/Toast.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { render, screen } from "@testing-library/react";
import Toast from "./";

test("should show toast text and disappear after some seconds", async () => {
jest.useFakeTimers();
const turnOffFn = jest.fn();
const text = "example text";
render(<Toast text={text} turnOff={turnOffFn} />);

expect(turnOffFn).not.toBeCalled();

expect(screen.getByText(text)).toBeVisible();

// Fast-forward until all timers have been executed
jest.runAllTimers();

expect(turnOffFn).toBeCalled();
});
19 changes: 19 additions & 0 deletions src/components/Toast/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect } from "react";
import "./styles.css";

interface ToastProps {
text: string;
turnOff: () => void;
}

const Toast: React.FC<ToastProps> = ({ text, turnOff }) => {
useEffect(() => {
setTimeout(() => {
turnOff();
}, 4000);
}, []);

return <div className="toast">{text}</div>;
};

export default Toast;
13 changes: 13 additions & 0 deletions src/components/Toast/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.toast {
background-color: #007a47;
color: #fff;
border-radius: 16px;
position: fixed;
bottom: 4vh;
display: flex;
align-items: center;
justify-content: center;
width: 30%;
height: 2.5rem;
padding: 0.4em;
}
12 changes: 7 additions & 5 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
font-size: 16px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
input[type="radio"] {
width: 20px;
height: 20px;
margin: 0;
}
14 changes: 7 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./pages/App/App";
import reportWebVitals from "./reportWebVitals";

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
document.getElementById("root") as HTMLElement,
);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
</React.StrictMode>,
);

// If you want to start measuring performance in your app, pass a function
Expand Down
107 changes: 107 additions & 0 deletions src/pages/App/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
.wrapper {
position: relative;
width: 30%;
min-width: 200px;
height: 78px;
}

.suffix {
position: absolute;
top: 35px;
}

.App {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}

.form {
width: 50%;
height: 60vh;
display: flex;
align-items: center;
flex-direction: column;
gap: 4em;
}

.input {
border: none;
border-bottom: 1px solid #a3b5bf;
width: 100%;
height: 48px;
padding: 4px 8px;
}

.label {
font-size: 0.8rem;
color: #47484f;
}

.title {
font-size: 2rem;
margin: 0;
}

.radios-wrapper {
border: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 1.2em;
}

.radio-content {
display: flex;
align-items: center;
gap: 4px;
}

.radio-content__label {
font-size: 1rem;
}

.confirm-button {
margin-top: 16px;
width: 30%;
height: 48px;
padding: 0.5em;
border-radius: 8px;
border: 1px solid #012169;
background-color: #fff;
color: #012169;
cursor: pointer;
font-size: 1rem;
}

.confirm-button:disabled {
border: 1px solid #ccc;
color: #ccc;
}

.confirm-button:hover:not([disabled]) {
border-color: #106eb0;
color: #106eb0;
}

@media only screen and (max-width: 500px) {
.form {
width: 100%;
gap: 2em;
}

.wrapper {
width: 80%;
}

.title {
font-size: 1.6rem;
}

.confirm-button {
width: 80%;
margin-top: auto;
}
}
42 changes: 42 additions & 0 deletions src/pages/App/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import App from "./App";
import userEvent from "@testing-library/user-event";

describe("App", () => {
test("should show input value with money format", () => {
render(<App />);
const inputElement = screen.getByRole("textbox", {
name: /edit money/i,
});
userEvent.type(inputElement, "1000");
expect(screen.getByDisplayValue("R$ 10,00")).toBeVisible();
});

test("should show input value with points format", () => {
render(<App />);
const inputElement = screen.getByRole("textbox", {
name: /edit money/i,
});
const editPoints = screen.getByRole("radio", {
name: /edit points/i,
});
userEvent.click(editPoints);
userEvent.type(inputElement, "10");
expect(screen.getByDisplayValue("10")).toBeVisible();
expect(screen.getByText("pts")).toBeVisible();
});

test("should enable button only if input value is valid", () => {
render(<App />);

const confirmButton = screen.getByRole("button", { name: /confirmar/i });
expect(confirmButton).toBeDisabled();
const inputElement = screen.getByRole("textbox", {
name: /edit money/i,
});
userEvent.type(inputElement, "1000");
expect(screen.getByDisplayValue("R$ 10,00")).toBeVisible();
expect(confirmButton).not.toBeDisabled();
});
});
Loading