mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
feat: 轮播图事件补充&修改单测
This commit is contained in:
parent
1dc7f89262
commit
f150336a73
@ -2,7 +2,7 @@ import React = require('react');
|
||||
import {render, fireEvent} from '@testing-library/react';
|
||||
import '../../src/themes/default';
|
||||
import {render as amisRender} from '../../src/index';
|
||||
import {makeEnv} from '../helper';
|
||||
import {makeEnv, wait} from '../helper';
|
||||
|
||||
test('Renderer:carousel', async () => {
|
||||
const {container} = render(
|
||||
@ -44,5 +44,6 @@ test('Renderer:carousel', async () => {
|
||||
const rightArrow = document.querySelector('div.cxd-Carousel-rightArrow');
|
||||
fireEvent.click(rightArrow as HTMLDivElement);
|
||||
|
||||
await wait(500);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ exports[`Renderer:carousel 1`] = `
|
||||
class="cxd-Carousel-container"
|
||||
>
|
||||
<div
|
||||
class="cxd-Carousel-item fade in"
|
||||
class="cxd-Carousel-item fade out"
|
||||
>
|
||||
<div
|
||||
class="cxd-Image cxd-Image--original cxd-Carousel-image"
|
||||
@ -35,6 +35,19 @@ exports[`Renderer:carousel 1`] = `
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Carousel-item fade in"
|
||||
>
|
||||
<span
|
||||
class="cxd-Html"
|
||||
>
|
||||
<div
|
||||
style="width: 100%; height: 300px; background: #e3e3e3; text-align: center; line-height: 300px;"
|
||||
>
|
||||
carousel data
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Carousel-item fade out"
|
||||
>
|
||||
@ -56,10 +69,10 @@ exports[`Renderer:carousel 1`] = `
|
||||
class="cxd-Carousel-dotsControl"
|
||||
>
|
||||
<span
|
||||
class="cxd-Carousel-dot is-active"
|
||||
class="cxd-Carousel-dot"
|
||||
/>
|
||||
<span
|
||||
class="cxd-Carousel-dot"
|
||||
class="cxd-Carousel-dot is-active"
|
||||
/>
|
||||
<span
|
||||
class="cxd-Carousel-dot"
|
||||
|
@ -195,12 +195,12 @@ export class Carousel extends React.Component<CarouselProps, CarouselState> {
|
||||
doAction(action: Action, data: object, throwErrors: boolean): any {
|
||||
const actionType = action?.actionType as string;
|
||||
|
||||
!!~['next', 'prev'].indexOf(actionType) && this.autoSlide(actionType);
|
||||
|
||||
actionType === 'goto-image' && this.setState({
|
||||
current: (data as any).activeIndex,
|
||||
nextAnimation: ''
|
||||
});
|
||||
if (!!~['next', 'prev'].indexOf(actionType)) {
|
||||
this.autoSlide(actionType);
|
||||
}
|
||||
else if (actionType === 'goto-image') {
|
||||
this.changeSlide((data as any).activeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@autobind
|
||||
@ -303,7 +303,21 @@ export class Carousel extends React.Component<CarouselProps, CarouselState> {
|
||||
}
|
||||
|
||||
@autobind
|
||||
changeSlide(index: number) {
|
||||
async changeSlide(index: number) {
|
||||
const {current} = this.state;
|
||||
const {dispatchEvent, data} = this.props;
|
||||
|
||||
const rendererEvent = await dispatchEvent(
|
||||
'change',
|
||||
createObject(data, {
|
||||
activeIndex: index,
|
||||
prevIndex: current
|
||||
})
|
||||
);
|
||||
if (rendererEvent?.prevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
current: index
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user