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

feat: breadcrumb #39

Merged
merged 3 commits into from
Apr 6, 2024
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
6 changes: 2 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const nextJest = require('next/jest')
const path = require('path')
// const path = require('path')

const createJestConfig = nextJest({
dir: './',
Expand All @@ -11,10 +11,8 @@ const customJestConfig = {
moduleDirectories: ['node_modules', '<rootDir>/'],
testEnvironment: 'jest-environment-jsdom',
moduleNameMapper: {
'^~/src/enums/medias$': path.resolve(__dirname, './src/enums/medias'),
'^~/src/(.*)$': '<rootDir>/src/$1',
},
}

module.exports = createJestConfig({ ...customJestConfig })

/** o/ font: https://fek.io/blog/add-jest-testing-framework-to-an-existing-next-js-app */
5 changes: 2 additions & 3 deletions pages/_app.page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { AppProps } from 'next/app'
import Head from 'next/head'

import GlobalStyle from '../src/styles/GlobalStyle'
import TextsStyle from '../src/styles/TextsStyle'
import GlobalStyle from '~/src/styles/GlobalStyle'
import TextsStyle from '~/src/styles/TextsStyle'

function MyApp({ Component, pageProps }: AppProps) {
return (
Expand Down
3 changes: 2 additions & 1 deletion pages/about/index.page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Layout from '../../src/layout/index'
import Layout from '~/src/layout'

import * as S from './styles'

const About = () => {
Expand Down
6 changes: 3 additions & 3 deletions pages/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { NextPage } from 'next'
import { useEffect } from 'react'
import { useGlitch } from 'react-powerglitch'
import Sound from 'react-sound'
import Equalizer from '~/src/components/Equalizer'
import { SoundClickButton, SoundGlitch } from '~/src/utils/Sounds'
import { settingsSound } from '~/src/utils/settingsHome'

import Equalizer from '../src/components/Equalizer'
import { SoundClickButton, SoundGlitch } from '../src/utils/Sounds'
import { settingsSound } from '../src/utils/settingsHome'
import * as S from './styles'

const Home: NextPage = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Equalizer/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Wrapper = styled.div`
`

export const Line = styled.div`
width: 6px;
width: var(--spacing-basic-small);
background-color: var(--white);
margin: 0 2px;
animation: equalizer 1.9s steps(20, end) infinite;
Expand Down
36 changes: 36 additions & 0 deletions src/layout/components/Breadcrumb/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { fireEvent, render, screen } from '@testing-library/react'

import Breadcrumb from '.'

jest.mock('next/router', () => ({
useRouter() {
return {
route: '/',
pathname: '',
query: '',
asPath: '/about/test/param',
push: jest.fn(),
}
},
}))

const useRouter = jest.spyOn(require('next/router'), 'useRouter')

beforeEach(() => {
render(<Breadcrumb />)
})

describe('<Breadcrumb />', () => {
it('should render params correctly', () => {
expect(screen.getByText('About')).toBeInTheDocument()
expect(screen.getByText('Test')).toBeInTheDocument()
expect(screen.getByText('Param')).toBeInTheDocument()
})

it('should redirect to link when param is clicked', () => {
fireEvent.click(screen.getByText('About'))

expect(useRouter).toHaveBeenCalled()
})
})
44 changes: 44 additions & 0 deletions src/layout/components/Breadcrumb/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useRouter } from 'next/router'
import React from 'react'

import * as S from './styles'

const Breadcrumb = () => {
const router = useRouter()

const params = router?.asPath.split('/')

const lastElement = params?.slice(-1)[0]

const goToPath = (index: number) => {
const path = '/' + params.slice(1, index + 1).join('/')
router.push(path)
}

return (
<S.Container>
<S.Icon onClick={() => router.push('/')} />
{params?.map((param, index) => {
const formatedLink = param.charAt(0).toUpperCase() + param.slice(1)

const isActualPath = param === lastElement

return (
<>
<S.Link
onClick={() => {
goToPath(index)
}}
isActualPath={isActualPath}
>
{formatedLink}
</S.Link>
{!isActualPath && <S.Simbol>{'>'}</S.Simbol>}
</>
)
})}
</S.Container>
)
}

export default Breadcrumb
27 changes: 27 additions & 0 deletions src/layout/components/Breadcrumb/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import HomeIcon from '@mui/icons-material/Home'
import styled from 'styled-components'

export const Container = styled.nav`
align-items: center;
display: flex;
`

export const Link = styled.a<{ isActualPath: boolean }>`
cursor: pointer;
color: ${({ isActualPath }) => isActualPath && 'var(--white)'};
`

export const Simbol = styled.p`
color: var(--green-white);
margin: 0 var(--spacing-basic-small);
`

export const Icon = styled(HomeIcon)`
color: var(--green-white);
cursor: pointer;
transition: 0.3s;

&:hover {
color: var(--white);
}
`
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import styled from 'styled-components'

import AnimationHoverLine from '../../styles/AnimationHoverLine'
import AnimationHoverLine from '~/src/styles/AnimationHoverLine'

export const Footer = styled.footer`
display: flex;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import styled from 'styled-components'

import AnimationHoverLine from '../../styles/AnimationHoverLine'
import AnimationHoverLine from '~/src/styles/AnimationHoverLine'

export const Header = styled.header`
display: flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react'
import Equalizer from '~/src/components/Equalizer'
import { SoundClickButton } from '~/src/utils/Sounds'

import { SoundClickButton } from '../../../utils/Sounds/index'
import Equalizer from '../../Equalizer'
import { navBarMock } from '../Navbar.mock'
import * as S from './styles'

Expand Down
12 changes: 8 additions & 4 deletions src/layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ReactNode } from 'react'

import Footer from '../components/Footer'
import Header from '../components/Header'
import DesktopNavbar from '../components/NavBar/Desktop'
import Breadcrumb from './components/Breadcrumb'
import Footer from './components/Footer'
import Header from './components/Header'
import DesktopNavbar from './components/NavBar/Desktop'
import * as S from './styles'

type LayoutProps = {
Expand All @@ -14,7 +15,10 @@ const Layout = ({ children }: LayoutProps) => (
<Header />
<S.WrapperContent>
<DesktopNavbar />
<S.Content>{children}</S.Content>
<S.Content>
<Breadcrumb />
{children}
</S.Content>
</S.WrapperContent>
<Footer />
</S.Container>
Expand Down
2 changes: 1 addition & 1 deletion src/layout/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from 'styled-components'

import { breakpoints } from './../utils/breakpoints'
import { breakpoints } from '../utils/breakpoints'

export const Container = styled.main`
color: var(--white);
Expand Down
Loading