Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

feat(react18): updating to react18 and add test to render #13

Merged
merged 3 commits into from
May 3, 2022
Merged
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
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [["@babel/preset-env", "@babel/preset-react", { targets: { node: "current" } }]],
};
16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
cacheDirectory: ".jest-cache",
coverageDirectory: ".jest-coverage",
coveragePathIgnorePatterns: ["<rootDir>/packages/(?:.+?)/lib/"],
coverageReporters: ["html", "text"],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
testPathIgnorePatterns: ["<rootDir>/packages/(?:.+?)/lib/"],
moduleFileExtensions: ["ts", "js", "tsx", "json"],
};
29 changes: 12 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
{
"name": "aluraflix",
"name": "nerdflix",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"json-server": "^0.16.1",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"react-slick": "^0.26.1",
"styled-components": "^5.1.1",
"json-server": "^0.16.1"
"styled-components": "^5.1.1"
},
"scripts": {
"start": "node ./server.js",
"dev": "concurrently \"react-scripts start\" \"node ./server.js\"",
"start": "concurrently \"react-scripts start\" \"node ./server.js\"",
"server": "node ./server.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"server:static": "json-server --watch ./src/data/db.json --port 8080",
"server": "node ./server.js"
"server:static": "json-server --watch ./src/data/db.json --port 8080"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
11 changes: 6 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOM from 'react-dom/client';
import './index.css';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import Home from './pages/Home';
import CadastroVideo from './pages/cadastro/Video';
import CadastroCategoria from './pages/cadastro/Categoria';
import PageDefault from './components/PageDefault';


ReactDOM.render(
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<BrowserRouter>
<Switch>
<Route path="/" component={Home} exact />
Expand All @@ -28,6 +29,6 @@ ReactDOM.render(
)}
/>
</Switch>
</BrowserRouter>,
document.getElementById('root')
</BrowserRouter>
</React.StrictMode>
);
11 changes: 11 additions & 0 deletions src/pages/Home/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render } from '@testing-library/react';

import Home from "./../index";

it('should render Most Popular', async () => {
const { getByText, debug } = render(<Home />)

//debug()

expect(getByText('Password changed successfully')).toBeTruthy();
})
56 changes: 12 additions & 44 deletions src/pages/Home/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/* eslint-disable no-console */
import React, { useEffect, useState } from 'react';
// import dadosIniciais from '../../data/dados_iniciais.json';
import BannerMain from '../../components/BannerMain';
import Carousel from '../../components/Carousel';
import PageDefault from '../../components/PageDefault';
import categoriasRepository from '../../repositories/categorias';
import React, { useEffect, useState } from "react";
import BannerMain from "../../components/BannerMain";
import Carousel from "../../components/Carousel";
import PageDefault from "../../components/PageDefault";
import categoriasRepository from "../../repositories/categorias";

function Home() {
const Home = () => {
const [dadosIniciais, setDadosIniciais] = useState([]);

useEffect(() => {
// http://localhost:8080/categorias?_embed=videos
categoriasRepository.getAllWithVideos()
categoriasRepository
.getAllWithVideos()
.then((categoriasComVideos) => {
console.log(categoriasComVideos[0].videos[0]);
setDadosIniciais(categoriasComVideos);
Expand All @@ -23,7 +21,7 @@ function Home() {

return (
<PageDefault paddingAll={0}>
{dadosIniciais.length === 0 && (<div> Loading...</div>)}
{dadosIniciais.length === 0 && <div> Loading...</div>}

{dadosIniciais.map((categoria, indice) => {
if (indice === 0) {
Expand All @@ -34,45 +32,15 @@ function Home() {
url={dadosIniciais[0].videos[0].url}
videoDescription={dadosIniciais[0].videos[0].description}
/>
<Carousel
ignoreFirstVideo
category={dadosIniciais[0]}
/>
<Carousel ignoreFirstVideo category={dadosIniciais[0]} />
</div>
);
}

return (
<Carousel
key={categoria.id}
category={categoria}
/>
);
return <Carousel key={categoria.id} category={categoria} />;
})}

{/* <BannerMain
videoTitle={dadosIniciais.categorias[0].videos[0].titulo}
url={dadosIniciais.categorias[0].videos[0].url}
videoDescription="O que"
/>
<Carousel
ignoreFirstVideo
category={dadosIniciais.categorias[0]}
/>
<Carousel
category={dadosIniciais.categorias[1]}
/>
<Carousel
category={dadosIniciais.categorias[2]}
/>
<Carousel
category={dadosIniciais.categorias[3]}
/>
<Carousel
category={dadosIniciais.categorias[4]}
/> */}
</PageDefault>
);
}
};

export default Home;