|
|
@ -5,6 +5,7 @@ import { defaultProps } from '../src/components/carousel/defaultProps'; |
|
|
|
import { carouselItemNodes, dynamicCarouselItemNodes } from './__fixtures__/nodes'; |
|
|
|
import { carouselItemNodes, dynamicCarouselItemNodes } from './__fixtures__/nodes'; |
|
|
|
import * as helpers from '../src/helpers'; |
|
|
|
import * as helpers from '../src/helpers'; |
|
|
|
import { SlideDirection } from '../src/types/carousel'; |
|
|
|
import { SlideDirection } from '../src/types/carousel'; |
|
|
|
|
|
|
|
import * as hooks from '../src/hooks'; |
|
|
|
|
|
|
|
|
|
|
|
describe('<Carousel />', () => { |
|
|
|
describe('<Carousel />', () => { |
|
|
|
let mockGetPageX: jest.SpyInstance< |
|
|
|
let mockGetPageX: jest.SpyInstance< |
|
|
@ -303,51 +304,30 @@ describe('<Carousel />', () => { |
|
|
|
expect(button!.innerHTML).toEqual('1'); |
|
|
|
expect(button!.innerHTML).toEqual('1'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should invoke beforeChange when beforeChange prop is defined on slide', async () => { |
|
|
|
it('should slide to right when click right button', async () => { |
|
|
|
const onBeforeChange = (_: SlideDirection) => { |
|
|
|
const paginationCallback = jest.fn(); |
|
|
|
return; |
|
|
|
const mockUsePrevious = jest |
|
|
|
}; |
|
|
|
.spyOn(hooks, 'usePrevious') |
|
|
|
const stub = jest.fn(onBeforeChange); |
|
|
|
.mockImplementation(() => carouselItemNodes(2)); |
|
|
|
const { getByTestId } = render( |
|
|
|
|
|
|
|
<Carousel |
|
|
|
|
|
|
|
{...defaultProps} |
|
|
|
|
|
|
|
infinite={true} |
|
|
|
|
|
|
|
children={carouselItemNodes(4)} |
|
|
|
|
|
|
|
beforeChange={stub} |
|
|
|
|
|
|
|
/>, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
const carousel = getByTestId('carousel'); |
|
|
|
|
|
|
|
const button = carousel.querySelector('button'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(button).not.toBeNull(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(button!); |
|
|
|
|
|
|
|
jest.runAllTimers(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(stub).toHaveBeenCalledTimes(1); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should invoke afterChange when afterChange prop is defined on slide', async () => { |
|
|
|
|
|
|
|
const onAfterChange = (_: SlideDirection) => { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
const stub = jest.fn(onAfterChange); |
|
|
|
|
|
|
|
const { getByTestId } = render( |
|
|
|
const { getByTestId } = render( |
|
|
|
<Carousel |
|
|
|
<Carousel |
|
|
|
{...defaultProps} |
|
|
|
{...defaultProps} |
|
|
|
infinite={true} |
|
|
|
infinite={true} |
|
|
|
children={carouselItemNodes(4)} |
|
|
|
children={carouselItemNodes(4)} |
|
|
|
afterChange={stub} |
|
|
|
pageCount={2} |
|
|
|
|
|
|
|
paginationCallback={paginationCallback} |
|
|
|
/>, |
|
|
|
/>, |
|
|
|
); |
|
|
|
); |
|
|
|
const carousel = getByTestId('carousel'); |
|
|
|
const carousel = getByTestId('carousel'); |
|
|
|
const button = carousel.querySelector('button'); |
|
|
|
const button = carousel.querySelectorAll('button')[1]; |
|
|
|
|
|
|
|
|
|
|
|
expect(button).not.toBeNull(); |
|
|
|
expect(button).not.toBeNull(); |
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(button!); |
|
|
|
fireEvent.click(button!); |
|
|
|
jest.runAllTimers(); |
|
|
|
jest.runAllTimers(); |
|
|
|
|
|
|
|
|
|
|
|
expect(stub).toHaveBeenCalledTimes(1); |
|
|
|
expect(paginationCallback).toHaveBeenCalledTimes(1); |
|
|
|
|
|
|
|
expect(mockUsePrevious).toBeCalled(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|