Skip to content

Commit

Permalink
test(layout): add simple page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devshred committed Apr 27, 2024
1 parent b0ff016 commit d983551
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest'
import { render, screen } from '@testing-library/react'
import App from './App'

describe('Root/App Page', () => {
it('load page', () => {
render(<App />)

expect(
screen.getByText(
"Drag 'n' drop GPX- or FIT-files, or click to select files."
)
).toBeInTheDocument()
})
})
40 changes: 40 additions & 0 deletions src/pages/About.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, it, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import About from './About'

const mocks = vi.hoisted(() => ({ get: vi.fn() }))

vi.mock('axios', async (importActual) => {
const actual = await importActual<typeof import('axios')>()
const mockAxios = {
default: {
...actual.default,
create: vi.fn(() => ({
...actual.default.create(),
get: mocks.get,
})),
},
}
return mockAxios
})

describe('About Page', () => {
it('load page', () => {
render(<About />)
expect(
screen.getByText('An app dealing with GPS files.')
).toBeInTheDocument()
})

it('show version of backend', async () => {
const version = 'v1.2.3'
mocks.get.mockResolvedValueOnce({
data: { app: version, git: 'githash' },
})

render(<About />)

expect(await screen.findByText(version)).toBeInTheDocument()
expect(mocks.get).toHaveBeenCalled()
})
})
2 changes: 1 addition & 1 deletion src/pages/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const About = () => {

return (
<>
<h1 className='text-6xl mb-4'>GPS Tools</h1>
<h1 className='text-6xl mb-4'>GPS-Tools</h1>
<p className='mb-4 text-2xl font-light'>An app dealing with GPS files.</p>
<p className='text-lg'>
<a
Expand Down
10 changes: 10 additions & 0 deletions src/pages/Home.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, it } from 'vitest'
import { render, screen } from '@testing-library/react'
import Home from './Home'

describe('Home Page', () => {
it('load page', () => {
render(<Home />)
expect(screen.getByText('GPS-Tools')).toBeInTheDocument()
})
})
2 changes: 1 addition & 1 deletion src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FaAngleRight } from 'react-icons/fa6'

const Home = () => (
<div>
<h1 className='text-6xl mb-4'>GPS Tools</h1>
<h1 className='text-6xl mb-4'>GPS-Tools</h1>
<p className='mb-4 text-2xl font-light'>
First functionallity that can be used:{' '}
<a href='/merge' className='flex'>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Merge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UploadProvider } from '../context/UploadContext'

const Merge = () => (
<div>
<h1 className='text-6xl'>GPS-Tool</h1>
<h1 className='text-6xl'>GPS-Tools</h1>
<UploadProvider>
<Intro />
<UploadForm />
Expand Down

0 comments on commit d983551

Please sign in to comment.