forked from deriv-com/deriv-app
-
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.
chore: compare accounts carousel unit test (deriv-com#17306)
- Loading branch information
1 parent
071e190
commit 082db10
Showing
8 changed files
with
204 additions
and
252 deletions.
There are no files selected for viewing
116 changes: 0 additions & 116 deletions
116
packages/wallets/docs/examples/FlowProvider/AccountFlow/AccountFlow.tsx
This file was deleted.
Oops, something went wrong.
116 changes: 0 additions & 116 deletions
116
packages/wallets/docs/examples/FlowProvider/AccountFlow/VerificationFlow.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/wallets/docs/examples/FlowProvider/AccountFlow/index.ts
This file was deleted.
Oops, something went wrong.
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
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
98 changes: 98 additions & 0 deletions
98
...eatures/cfd/components/CompareAccountsCarousel/__tests__/CompareAccountsCarousel.spec.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,98 @@ | ||
import React from 'react'; | ||
import useEmblaCarousel from 'embla-carousel-react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import CompareAccountsCarousel from '../CompareAccountsCarousel'; | ||
|
||
const mockScrollPrev = jest.fn(); | ||
const mockScrollNext = jest.fn(); | ||
const mockUseEmblaCarousel = useEmblaCarousel as jest.MockedFunction<typeof useEmblaCarousel>; | ||
|
||
jest.mock('embla-carousel-react', () => { | ||
return jest.fn(() => [ | ||
jest.fn(), | ||
{ | ||
canScrollNext: jest.fn(() => false), | ||
canScrollPrev: jest.fn(() => true), | ||
on: jest.fn(), | ||
scrollNext: mockScrollNext, | ||
scrollPrev: mockScrollPrev, | ||
}, | ||
]); | ||
}); | ||
|
||
jest.mock('../CompareAccountsCarouselButton', () => { | ||
return jest.fn(({ isNext, onClick }: { isNext: boolean; onClick: () => void }) => ( | ||
<button | ||
data-testid={ | ||
isNext ? 'dt_compare_accounts_carousel_next_button' : 'dt_compare_accounts_carousel_prev_button' | ||
} | ||
onClick={onClick} | ||
> | ||
{isNext ? 'Next' : 'Prev'} | ||
</button> | ||
)); | ||
}); | ||
|
||
describe('CompareAccountsCarousel', () => { | ||
const defaultProps = { | ||
children: <div>Test Child</div>, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders children correctly', () => { | ||
render(<CompareAccountsCarousel {...defaultProps} />); | ||
|
||
expect(screen.getByText('Test Child')).toBeInTheDocument(); | ||
}); | ||
|
||
it('initializes Embla Carousel with correct default options', () => { | ||
render(<CompareAccountsCarousel {...defaultProps} />); | ||
|
||
expect(useEmblaCarousel).toHaveBeenCalledWith({ | ||
align: 0, | ||
containScroll: 'trimSnaps', | ||
direction: 'ltr', | ||
}); | ||
}); | ||
|
||
it('initializes Embla Carousel with RTL direction when isRtl is true', () => { | ||
render(<CompareAccountsCarousel {...defaultProps} isRtl={true} />); | ||
|
||
expect(useEmblaCarousel).toHaveBeenCalledWith({ | ||
align: 0, | ||
containScroll: 'trimSnaps', | ||
direction: 'rtl', | ||
}); | ||
}); | ||
|
||
it('calls scrollPrev when prev button is clicked', () => { | ||
render(<CompareAccountsCarousel {...defaultProps} />); | ||
|
||
userEvent.click(screen.getByTestId('dt_compare_accounts_carousel_prev_button')); | ||
|
||
expect(mockScrollPrev).toHaveBeenCalled(); | ||
}); | ||
|
||
it('calls scrollNext when next button is clicked', () => { | ||
render(<CompareAccountsCarousel {...defaultProps} />); | ||
|
||
userEvent.click(screen.getByTestId('dt_compare_accounts_carousel_next_button')); | ||
|
||
expect(mockScrollNext).toHaveBeenCalled(); | ||
}); | ||
|
||
it('disables buttons when emblaApi is undefined', () => { | ||
mockUseEmblaCarousel.mockReturnValue([jest.fn(), undefined]); | ||
render(<CompareAccountsCarousel {...defaultProps} />); | ||
|
||
userEvent.click(screen.getByTestId('dt_compare_accounts_carousel_prev_button')); | ||
expect(mockScrollPrev).not.toHaveBeenCalled(); | ||
|
||
userEvent.click(screen.getByTestId('dt_compare_accounts_carousel_next_button')); | ||
expect(mockScrollNext).not.toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.