|
|
@ -4,6 +4,7 @@ import { Carousel } from '../src/components/carousel'; |
|
|
|
import { defaultProps } from '../src/components/carousel/defaultProps'; |
|
|
|
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'; |
|
|
|
|
|
|
|
|
|
|
|
describe('<Carousel />', () => { |
|
|
|
describe('<Carousel />', () => { |
|
|
|
let mockGetPageX: jest.SpyInstance< |
|
|
|
let mockGetPageX: jest.SpyInstance< |
|
|
@ -301,4 +302,52 @@ describe('<Carousel />', () => { |
|
|
|
|
|
|
|
|
|
|
|
expect(button!.innerHTML).toEqual('1'); |
|
|
|
expect(button!.innerHTML).toEqual('1'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should invoke beforeChange when beforeChange prop is defined on slide', async () => { |
|
|
|
|
|
|
|
const onBeforeChange = (_: SlideDirection) => { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
const stub = jest.fn(onBeforeChange); |
|
|
|
|
|
|
|
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( |
|
|
|
|
|
|
|
<Carousel |
|
|
|
|
|
|
|
{...defaultProps} |
|
|
|
|
|
|
|
infinite={true} |
|
|
|
|
|
|
|
children={carouselItemNodes(4)} |
|
|
|
|
|
|
|
afterChange={stub} |
|
|
|
|
|
|
|
/>, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
const carousel = getByTestId('carousel'); |
|
|
|
|
|
|
|
const button = carousel.querySelector('button'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(button).not.toBeNull(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(button!); |
|
|
|
|
|
|
|
jest.runAllTimers(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(stub).toHaveBeenCalledTimes(1); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|