Skip to content

Commit

Permalink
Merge branch 'main' into 337-user-can-view-their-rating
Browse files Browse the repository at this point in the history
  • Loading branch information
juli-txt committed Sep 11, 2024
2 parents 5b3bb6a + 5c01b75 commit 713cfd9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/components/Footer/Footer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ describe('Footer', () => {
fireEvent.click(button)
})

expect(navigate).toHaveBeenCalledTimes(4)
expect(navigate).toHaveBeenCalledTimes(3)
})
})
58 changes: 32 additions & 26 deletions src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Fragment, memo } from 'react'
import { Fragment, memo, useContext } from 'react'
import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'
import { Box, Container, Divider, Grid, Link, Typography } from '@common/components'
import { AuthContext } from '@services'

/**
* Sticks to the bottom of the page and is always visible.
Expand All @@ -17,11 +18,13 @@ const Footer = () => {
const navigate = useNavigate()
const { t } = useTranslation()

const { isAuth } = useContext(AuthContext)

const footerComponents = [
{ name: [t('pages.home')], link: '/' },
{ name: [t('pages.contact')], link: '/contact' },
{ name: [t('pages.imprint')], link: '/imprint' },
{ name: [t('pages.privacypolicy')], link: '/privacypolicy' }
{ name: [t('pages.home')], link: '/', isVisibleBeforeLogin: true },
{ name: [t('pages.contact')], link: '/contact', isVisibleBeforeLogin: false },
{ name: [t('pages.imprint')], link: '/imprint', isVisibleBeforeLogin: true },
{ name: [t('pages.privacypolicy')], link: '/privacypolicy', isVisibleBeforeLogin: true }
]

return (
Expand All @@ -42,27 +45,30 @@ const Footer = () => {
</Typography>
</Grid>
<Grid item xs={12} display="flex" width="100%" justifyContent="center">
{footerComponents.map((component) => (
<Fragment key={component.link}>
<Link
id={component.link.concat('-link').replaceAll(' ', '-')}
marginX="0.2em"
component="button"
variant="subtitle1"
color={'textSecondary'}
href={component.link}
underline="hover"
onClick={() => navigate(component.link)}>
{component.name}
</Link>
{footerComponents.indexOf(component) !== footerComponents.length - 1 && (
<Typography marginX="0.2em" color="textSecondary" variant="subtitle1">
{' '}
|{' '}
</Typography>
)}
</Fragment>
))}
{footerComponents.map(
(component) =>
(component.isVisibleBeforeLogin || isAuth) && (
<Fragment key={component.link}>
<Link
id={component.link.concat('-link').replaceAll(' ', '-')}
marginX="0.2em"
component="button"
variant="subtitle1"
color={'textSecondary'}
href={component.link}
underline="hover"
onClick={() => navigate(component.link)}>
{component.name}
</Link>
{footerComponents.indexOf(component) !== footerComponents.length - 1 && (
<Typography marginX="0.2em" color="textSecondary" variant="subtitle1">
{' '}
|{' '}
</Typography>
)}
</Fragment>
)
)}
</Grid>
</Grid>
</Container>
Expand Down
21 changes: 19 additions & 2 deletions src/pages/Contact/Contact.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { FormDataType, SnackbarContext, SnackbarContextType } from '@services'
import { getConfig } from '@shared'
import { useContact } from './Contact.hooks'

const { AuthContext } = jest.requireActual('@services')

/*jest.mock('react', () => ({
...jest.requireActual('react'),
useCallback: (a: any) => a
Expand Down Expand Up @@ -54,12 +56,25 @@ describe('Test Contactpage', () => {
const useContact = jest.fn(() => {
return { onSubmitHandler: submit }
})
test('Contactform gets displayed and functions normally', () => {
render(
<SnackbarContext.Provider value={mockSnackbarContext}>
<MemoryRouter>
<AuthContext.Provider value={{ isAuth: true }}>
<Contact />
</AuthContext.Provider>
</MemoryRouter>
</SnackbarContext.Provider>
)
})

test('not sending', () => {
render(
<SnackbarContext.Provider value={mockSnackbarContext}>
<MemoryRouter>
<Contact />
<AuthContext.Provider value={{ isAuth: true }}>
<Contact />
</AuthContext.Provider>
</MemoryRouter>
</SnackbarContext.Provider>
)
Expand All @@ -86,7 +101,9 @@ describe('Test Contactpage', () => {

render(
<MemoryRouter>
<Contact />
<AuthContext.Provider value={{ isAuth: true }}>
<Contact />
</AuthContext.Provider>
</MemoryRouter>
)
})
Expand Down
7 changes: 5 additions & 2 deletions src/pages/Contact/Contact.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react'
import { useState, useContext } from 'react'
import { ContactForm } from '@components'
import { AuthContext } from '@services'
import { ContactHookProps, ContactHookReturn, useContact as _useContact } from './Contact.hooks'

export type ContactProps = {
Expand All @@ -16,10 +17,12 @@ export type ContactProps = {
* @param props - Dependency injects {@link useContact} to control the sumbit on the page. Also displays a lodaing indicator when submitting.
* @category Pages
*/

export const Contact = ({ useContact = _useContact }: ContactProps) => {
const [isLoading, setIsLoading] = useState(false)
const { isAuth } = useContext(AuthContext)

const { onSubmitHandler } = useContact({ setIsLoading })
return <ContactForm onSubmit={onSubmitHandler} isLoading={isLoading} />
return <>{isAuth && <ContactForm onSubmit={onSubmitHandler} isLoading={isLoading} />}</>
}
export default Contact

0 comments on commit 713cfd9

Please sign in to comment.