diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..854cb73a --- /dev/null +++ b/.babelrc @@ -0,0 +1,4 @@ +{ + "presets": ["next/babel"], + "plugins": [["styled-components", { "ssr": true }]] +} diff --git a/.editorconfig b/.editorconfig index 1d6092bd..f421b546 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,7 +5,7 @@ charset = utf-8 end_of_line = lf insert_final_newline = true indent_style = space -indent_size = 4 +indent_size = 2 trim_trailing_whitespace = true [Makefile] diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..8996d996 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules +.next +/*.js diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..4ba8cfa4 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,32 @@ + + +{ + "env": { + "browser": true, + "es2020": true, + "node": true + }, + "plugins": ["react", "@typescript-eslint", "prettier"], + "extends": [ + "prettier/prettier", + "plugin:react/recommended", + "standard", + "plugin:@typescript-eslint/recommended", + "plugin:import/typescript", + "prettier" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 12, + "sourceType": "module" + }, + "rules": { + "prettier/prettier": "error", + "react/prop-types": "off", + "arrow-parens": [2, "as-needed"], + "no-useless-constructor": "off" + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ec1856bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# local env files +.env +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..22fbdbe4 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +node_modules +yarn.lock +package-lock.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..2d936dd3 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "tabWidth": 2, + "semi": true, + "singleQuote": true, + "arrowParens": "avoid" +} diff --git a/README.md b/README.md index d52ee5cc..345964c9 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,111 @@ -# front-end-challenge - -> Desafio para os futuros front-end's do [@Personare](https://github.com/Personare) - -## Introdução - -A nossa Product Owner pensou em um produto fantástico para ser desenvolvido, e um dos desafios é criação de um jogo de Tarot. - -
- -**Então, essa é a sua missão!** - -Criar um jogo de Tarot, permitindo o sorteio de uma carta. - -E as especificações são: - -- Tela de apresentação exibindo todas as cartas com seu conteúdo visível, e com um botão para iniciar o jogo. -- Ao clicar no botão, as cartas deverão ser viradas - escondendo o conteúdo - e embaralhadas. -- Permitir que o usuário selecione apenas uma carta, clicando na mesma. -- Apresentar a carta selecionada, o nome da carta e uma descrição. (a descrição pode ser um lorem ipsum) - -OBS: As imagens e nomes das cartas estão listadas no arquivo [`tarot.json`](tarot.json), esse arquivo deve ser consumido via _http request_. A propriedade `image` de cada carta deve ser concatenada com a propriedade `imagesUrl`, para obter o endereço final da imagem. Utilize o valor da propriedade `imageBackCard` para obter a imagem do fundo da carta. - - -## Instruções - -1. Efetue o **fork** deste repositório e crie um branch com o seu nome. (ex: caue-alves). -2. Após finalizar o desafio, crie um **Pull Request**. -3. Aguarde algum contribuidor realizar o code review. - - -## Pré-requisitos - -- Aplicação feita em React -- Possuir testes -- Gerar versão de produção -- Criar micro commits ou commits por features - - Detalhar nos comentários dos commits as decisões tomadas. - - -## Diferenciais - -- Boa documentação -- Testes de componentes isolados - -## Dúvidas - -Se surgir alguma dúvida, consulte as [perguntas feitas anteriormente](https://github.com/Personare/front-end-challenge/labels/question). - -Caso não encontre a sua resposta, sinta-se à vontade para [abrir uma issue](https://github.com/Personare/front-end-challenge/issues/new) =] +# Front-End-Challenge Personare + +## Application + +My version of [@Personare Front-End-Challenge](https://github.com/Personare/front-end-challenge). It's a simple Tarot game. + +[Link](https://front-end-challenge-personare.vercel.app) of application deployment at [Vercel](https://vercel.com) + +## Tecnologies + +- ✅ NextJS +- ✅ ReactJS +- ✅ Typescript +- ✅ Styled-Components +- ✅ Jest +- ✅ React Testing Library +- ✅ Eslint +- ✅ Prettier + +## Directory Structure + +```shell +├── src/ +│ ├── components/ #Atomic design structure +│ │ ├── atoms/ +│ │ │ ├── index.tsx +│ │ │ ├── styles.ts +│ │ │ ├── index.spec.tsx +│ │ ├── molecules/ +│ │ ├── organisms/ +│ │ ├── templates/ +│ ├── data/ #JSON data files +│ │ ├── tarot.json +│ ├── hooks/ #Custom Hooks +│ │ ├── useOnClickOutside.ts +│ ├── pages/ #NextJS page structure +│ │ ├── api/ +│ │ │ ├── cards/ +│ │ │ │ ├── index.ts +│ │ ├── _app.tsx +│ │ ├── _document.tsx +│ │ ├── index.tsx +│ ├── styles/ #Global styles configuration +│ │ ├── global.ts +│ │ ├── variables.ts +│ ├── utils/ #Util functions +│ │ ├── shuffle.ts +``` + +## Setup + +```bash +git clone https://github.com/rodrigo-miranda18/front-end-challenge-personare.git +# or +git clone git@github.com:rodrigo-miranda18/front-end-challenge-personare.git + +# Clone project +``` + +```bash +cd front-end-challenge-personare && git checkout rodrigo-miranda + +# Go to project directory and switch branch +``` + +```bash +npm install +# or +yarn + +# To download dependencies +``` + +```bash +# Create a .env file in root of project and paste this environment variable + +BASE_URL=http://localhost:3000 +``` + +```bash +npm run build +# or +yarn build + +# To generate project build +``` + +```bash +npm start +# or +yarn start + +# Now just access http://localhost:3000 +``` + +```bash +# To run tests: + +npm run test +# or +yarn test +``` + +## Related Links + +[Personare](https://www.personare.com.br)    +[Atomic Design](https://bradfrost.com/blog/post/atomic-web-design)    +[NextJS](https://nextjs.org)    +[Jest](https://jestjs.io)    +[React Testing Library](https://testing-library.com/docs/react-testing-library/intro)    +[Styled Components](https://styled-components.com) diff --git a/jest.config.ts b/jest.config.ts new file mode 100644 index 00000000..6d450e14 --- /dev/null +++ b/jest.config.ts @@ -0,0 +1,218 @@ +/* + * For a detailed explanation regarding each configuration property and type check, visit: + * https://jestjs.io/docs/configuration + */ + +export default { + // All imported modules in your tests should be mocked automatically + // automock: false, + + // Stop running tests after `n` failures + // bail: 0, + + // The directory where Jest should store its cached dependency information + // cacheDirectory: "/tmp/jest_rs", + + // Automatically clear mock calls, instances, contexts and results before every test + clearMocks: true, + + // Indicates whether the coverage information should be collected while executing the test + // collectCoverage: false, + + // An array of glob patterns indicating a set of files for which coverage information should be collected + // collectCoverageFrom: undefined, + + // The directory where Jest should output its coverage files + // coverageDirectory: undefined, + + // An array of regexp pattern strings used to skip coverage collection + // coveragePathIgnorePatterns: [ + // "/node_modules/" + // ], + + // Indicates which provider should be used to instrument code for coverage + coverageProvider: 'v8', + + // A list of reporter names that Jest uses when writing coverage reports + // coverageReporters: [ + // "json", + // "text", + // "lcov", + // "clover" + // ], + + // An object that configures minimum threshold enforcement for coverage results + // coverageThreshold: undefined, + + // A path to a custom dependency extractor + // dependencyExtractor: undefined, + + // Make calling deprecated APIs throw helpful error messages + // errorOnDeprecated: false, + + // The default configuration for fake timers + // fakeTimers: { + // "enableGlobally": false + // }, + + // Force coverage collection from ignored files using an array of glob patterns + // forceCoverageMatch: [], + + // A path to a module which exports an async function that is triggered once before all test suites + // globalSetup: undefined, + + // A path to a module which exports an async function that is triggered once after all test suites + // globalTeardown: undefined, + + // A set of global variables that need to be available in all test environments + // globals: {}, + + // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. + // maxWorkers: "50%", + + // An array of directory names to be searched recursively up from the requiring module's location + moduleDirectories: ['node_modules', 'src'], + + // An array of file extensions your modules use + // moduleFileExtensions: [ + // "js", + // "mjs", + // "cjs", + // "jsx", + // "ts", + // "tsx", + // "json", + // "node" + // ], + + // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module + // moduleNameMapper: {}, + + // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader + // modulePathIgnorePatterns: [], + + // Activates notifications for test results + // notify: false, + + // An enum that specifies notification mode. Requires { notify: true } + // notifyMode: "failure-change", + + // A preset that is used as a base for Jest's configuration + // preset: undefined, + + // Run tests from one or more projects + // projects: undefined, + + // Use this configuration option to add custom reporters to Jest + // reporters: undefined, + + // Automatically reset mock state before every test + // resetMocks: false, + + // Reset the module registry before running each individual test + // resetModules: false, + + // A path to a custom resolver + // resolver: undefined, + + // Automatically restore mock state and implementation before every test + // restoreMocks: false, + + // The root directory that Jest should scan for tests and modules within + // rootDir: undefined, + + // A list of paths to directories that Jest should use to search for files in + // roots: [ + // "" + // ], + + // Allows you to use a custom runner instead of Jest's default test runner + // runner: "jest-runner", + + // The paths to modules that run some code to configure or set up the testing environment before each test + // setupFiles: [], + + // A list of paths to modules that run some code to configure or set up the testing framework before each test + // setupFilesAfterEnv: [], + + // The number of seconds after which a test is considered as slow and reported as such in the results. + // slowTestThreshold: 5, + + // A list of paths to snapshot serializer modules Jest should use for snapshot testing + // snapshotSerializers: [], + + // The test environment that will be used for testing + testEnvironment: 'jsdom', + + // Options that will be passed to the testEnvironment + // testEnvironmentOptions: {}, + + // Adds a location field to test results + // testLocationInResults: false, + + // The glob patterns Jest uses to detect test files + // testMatch: [ + // "**/__tests__/**/*.[jt]s?(x)", + // "**/?(*.)+(spec|test).[tj]s?(x)" + // ], + + // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped + // testPathIgnorePatterns: [ + // "/node_modules/" + // ], + + // The regexp pattern or array of patterns that Jest uses to detect test files + // testRegex: [], + + // This option allows the use of a custom results processor + // testResultsProcessor: undefined, + + // This option allows use of a custom test runner + // testRunner: "jest-circus/runner", + + // A map from regular expressions to paths to transformers + transform: { + '^.+\\.(t|j)sx?$': [ + '@swc/jest', + { + jsc: { + parser: { + syntax: 'typescript', + tsx: true, + decorators: true, + }, + keepClassNames: true, + transform: { + legacyDecorator: true, + decoratorMetadata: true, + react: { + runtime: 'automatic', + }, + }, + }, + module: { + type: 'es6', + noInterop: false, + }, + }, + ], + }, + + // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation + // transformIgnorePatterns: [ + // "/node_modules/", + // "\\.pnp\\.[^\\/]+$" + // ], + + // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them + // unmockedModulePathPatterns: undefined, + + // Indicates whether each individual test should be reported during the run + // verbose: undefined, + + // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode + // watchPathIgnorePatterns: [], + + // Whether to use watchman for file crawling + // watchman: true, +}; diff --git a/next-env.d.ts b/next-env.d.ts new file mode 100644 index 00000000..4f11a03d --- /dev/null +++ b/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/next.config.js b/next.config.js new file mode 100644 index 00000000..a843cbee --- /dev/null +++ b/next.config.js @@ -0,0 +1,6 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + reactStrictMode: true, +} + +module.exports = nextConfig diff --git a/package.json b/package.json new file mode 100644 index 00000000..fcc8f7aa --- /dev/null +++ b/package.json @@ -0,0 +1,49 @@ +{ + "name": "nextjs-with-typescript", + "version": "0.1.0", + "private": true, + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start", + "lint": "next lint", + "lint:fix": "next lint --fix", + "test": "jest", + "test:watch": "jest --watchAll" + }, + "dependencies": { + "next": "12.1.6", + "react": "18.1.0", + "react-dom": "18.1.0", + "styled-components": "^5.3.5" + }, + "devDependencies": { + "@swc/core": "^1.2.187", + "@swc/jest": "^0.2.21", + "@testing-library/jest-dom": "^5.16.4", + "@testing-library/react": "^13.2.0", + "@testing-library/user-event": "^14.2.0", + "@types/jest": "^27.5.1", + "@types/node": "17.0.35", + "@types/react": "18.0.9", + "@types/react-dom": "18.0.4", + "@types/styled-components": "^5.1.24", + "@typescript-eslint/eslint-plugin": "^5.16.0", + "@typescript-eslint/parser": "^5.16.0", + "babel-plugin-styled-components": "^2.0.7", + "eslint": "8.12.0", + "eslint-config-next": "12.1.1", + "eslint-config-prettier": "^8.5.0", + "eslint-config-standard": "^16.0.3", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-prettier": "^4.0.0", + "eslint-plugin-promise": "^6.0.0", + "eslint-plugin-react": "^7.29.4", + "eslint-plugin-standard": "^5.0.0", + "jest": "^28.1.0", + "jest-environment-jsdom": "^28.1.0", + "prettier": "^2.6.1", + "ts-node": "^10.7.0", + "typescript": "4.6.4" + } +} diff --git a/public/assets/favicon.ico b/public/assets/favicon.ico new file mode 100644 index 00000000..4aca81cd Binary files /dev/null and b/public/assets/favicon.ico differ diff --git a/src/components/atoms/Button/index.spec.tsx b/src/components/atoms/Button/index.spec.tsx new file mode 100644 index 00000000..ff627025 --- /dev/null +++ b/src/components/atoms/Button/index.spec.tsx @@ -0,0 +1,34 @@ +import React from 'react'; + +import { render, screen, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom'; + +import Button from '.'; + +describe('Button component', () => { + it('should render button', () => { + render(