-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
frontend/__tests__/common-app/components/header.component.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react' | ||
import React from 'react' | ||
import { HeaderComponent } from '../../../src/common-app/components' | ||
import { Direction, useScrollDirection } from '../../../src/common/hooks' | ||
import { describe, test, expect, vi, MockedFunction } from 'vitest' | ||
import '@testing-library/jest-dom' | ||
import { MemoryRouter } from 'react-router-dom' | ||
|
||
//vi.mock('../../../src/common/hooks/useScrollDirection.hook') | ||
//const mockUseScrollDirection = useScrollDirection as MockedFunction<typeof useScrollDirection> | ||
|
||
describe('Header Component', () => { | ||
test('renders component ', () => { | ||
render(<MemoryRouter><HeaderComponent /></MemoryRouter>) | ||
const header = screen.getByRole('banner') | ||
|
||
expect(header).toBeInTheDocument() | ||
}) | ||
|
||
test('Header is not visible when scrolling down', () => { | ||
render(<MemoryRouter><HeaderComponent /></MemoryRouter>) | ||
const header = screen.getByRole('banner') | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 100 } }) | ||
|
||
expect(header).toHaveClass('opacity-0') | ||
}) | ||
|
||
test('Header is visible when scrolling up', () => { | ||
render(<MemoryRouter><HeaderComponent /></MemoryRouter>) | ||
const header = screen.getByRole('banner') | ||
|
||
fireEvent.scroll(window, { target: { scrollY: -50 } }) | ||
|
||
expect(header).toHaveClass('opacity-1') | ||
}) | ||
|
||
test('Multiple scrolling actions', async () => { | ||
render(<MemoryRouter><HeaderComponent /></MemoryRouter>) | ||
const header = screen.getByRole('banner') | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 100 } }) | ||
expect(header).toHaveClass('opacity-0') | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 200 } }) | ||
expect(header).toHaveClass('opacity-0') | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 50 } }) | ||
expect(header).toHaveClass('opacity-1') | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 100 } }) | ||
expect(header).toHaveClass('opacity-0') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters