Skip to content

Commit

Permalink
ADM-662: [frontend] test: refact unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
neomgb committed Dec 18, 2023
1 parent 6aeea45 commit ce88770
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions frontend/__tests__/src/layouts/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,35 @@ describe('Header', () => {
)

it('should show project name', () => {
const { getByText } = render(
<BrowserRouter>
<Header />
</BrowserRouter>
)
const { getByText } = setup()

expect(getByText(PROJECT_NAME)).toBeInTheDocument()
})

it('should show version info when request succeed', async () => {
headerClient.getVersion = jest.fn().mockResolvedValueOnce('1.11')
const { getByText } = await act(async () => await setup())
const { getByText } = await act(async () => setup())

expect(getByText(/v1.11/)).toBeInTheDocument()
})

it('should show version info when request failed', async () => {
headerClient.getVersion = jest.fn().mockResolvedValueOnce('')
const { queryByText } = await act(async () => await setup())
const { queryByText } = await act(async () => setup())

expect(queryByText(/v/)).not.toBeInTheDocument()
})

it('should show project logo', () => {
const { getByRole } = render(
<BrowserRouter>
<Header />
</BrowserRouter>
)
const { getByRole } = setup()

const logoInstance = getByRole('img')
expect(logoInstance).toBeInTheDocument()
expect(logoInstance.getAttribute('alt')).toContain('logo')
})

it('should go to home page when click logo', () => {
const { getByText } = render(
<BrowserRouter>
<Header />
</BrowserRouter>
)
const { getByText } = setup()

fireEvent.click(getByText(PROJECT_NAME))

Expand Down

0 comments on commit ce88770

Please sign in to comment.