Skip to content

Commit

Permalink
feat(app): Agrega @laboratoria/react
Browse files Browse the repository at this point in the history
  • Loading branch information
lupomontero authored and mfdebian committed Mar 2, 2023
1 parent 613b3fa commit 5c0b0a1
Show file tree
Hide file tree
Showing 19 changed files with 347 additions and 414 deletions.
146 changes: 145 additions & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"dependencies": {
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@laboratoria/react": "^3.0.0",
"@mui/icons-material": "^5.11.0",
"@mui/material": "^5.11.3",
"@mui/styles": "^5.11.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^13.2.1",
"firebase": "^9.17.1",
"highlight.js": "^11.7.0",
"react": "^17.0.2",
"react-ace": "^9.4.4",
Expand Down Expand Up @@ -94,4 +94,4 @@
"<rootDir>/src/lib/theme.js"
]
}
}
}
4 changes: 3 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<meta name="description" content="Curriculum del Bootcamp de Laboratoria (Web Dev + UX)" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Bitter:400,700|Open+Sans:400,400i,700" />
<link
href="https://fonts.googleapis.com/css2?family=Bitter:wght@100;200;400;500;700&family=Open+Sans:wght@300;400;500;700&display=swap"
rel="stylesheet">
<title>Laboratoria/bootcamp</title>
</head>

Expand Down
7 changes: 7 additions & 0 deletions src/__mocks__/@laboratoria/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const useApp = jest.fn();

export const themeConfig = {
palette: {
mint: {},
},
};
40 changes: 17 additions & 23 deletions src/components/App/App.spec.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
import { render, screen, waitFor } from '@testing-library/react';
import { createTheme, ThemeProvider, StyledEngineProvider, adaptV4Theme } from '@mui/material/styles';
import themeConfig from '../../lib/theme';
import app from '../../lib/app';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import { useApp, themeConfig } from '@laboratoria/react';
import App from '.';

jest.mock('../../lib/app');

describe('App', () => {
beforeEach(() => {
app.mockRestore();
});

it('should show loading when auth user is undefined', () => {
const { container } = render(<App />);
useApp.mockReturnValue({ auth: {} });
const { container } = render(
<ThemeProvider theme={createTheme(themeConfig)}>
<App />
</ThemeProvider>
);
const progress = container.querySelector('.MuiCircularProgress-root');
expect(progress instanceof HTMLDivElement).toBe(true);
expect(progress instanceof HTMLSpanElement).toBe(true);
});

it('should show spanish home by default', async () => {
app.useApp.mockImplementationOnce(() => ({
useApp.mockImplementation(() => ({
auth: { user: null },
}));
render(
<StyledEngineProvider injectFirst>
<ThemeProvider theme={createTheme(adaptV4Theme(themeConfig))}>
<App />
</ThemeProvider>
</StyledEngineProvider>
<ThemeProvider theme={createTheme(themeConfig)}>
<App />
</ThemeProvider>
);
await waitFor(() => screen.getByText('Desarrollo Web'));
});

it('should show portuguese home when navigator.language is pt-BR', async () => {
window.history.pushState({}, 'Test page', '/');
const spy = jest.spyOn(window.navigator, 'language', 'get').mockReturnValue('pt');
app.useApp.mockImplementationOnce(() => ({
useApp.mockImplementation(() => ({
auth: { user: null },
}));
render(
<StyledEngineProvider injectFirst>
<ThemeProvider theme={createTheme(adaptV4Theme(themeConfig))}>
<App />
</ThemeProvider>
</StyledEngineProvider>
<ThemeProvider theme={createTheme(themeConfig)}>
<App />
</ThemeProvider>
);
await waitFor(() => screen.getByText('Desenvolvimento Web'));
spy.mockRestore();
Expand Down
19 changes: 8 additions & 11 deletions src/components/App/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { useApp } from '../../lib/app';
import { useApp } from '@laboratoria/react';
import Loading from '../Loading';
import RoutesWithIntl from './RoutesWithIntl';
import './App.css';
Expand All @@ -10,18 +10,15 @@ const App = () => {
const [defaulLocale, setDefaulLocale] = useState();

useEffect(() => {
if (auth.user && !auth.profile) {
return;
}


const profileLocale = (auth.profile || {}).locale;
const userLang = auth.user?.lang;
setDefaulLocale(
['es-ES', 'pt-BR'].includes(profileLocale)
? profileLocale
: navigator.language.split('-')[0] === 'pt'
userLang === 'es'
? 'es-ES'
: userLang === 'pt'
? 'pt-BR'
: 'es-ES'
: navigator.language.split('-')[0] === 'pt'
? 'pt-BR'
: 'es-ES'
)
}, [auth]);

Expand Down
2 changes: 1 addition & 1 deletion src/components/SignIn/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Container from '@mui/material/Container';
import Grid from '@mui/material/Grid';
import TextField from '@mui/material/TextField';
import Loading from '../Loading';
import { useApp } from '../../lib/app';
import { useApp } from '@laboratoria/react';

const useStyles = makeStyles((theme) => ({
root: {
Expand Down
Loading

0 comments on commit 5c0b0a1

Please sign in to comment.