Skip to content

Commit

Permalink
test: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Jun 7, 2024
1 parent 59d5122 commit 65f38fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/Operations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { PreviewGroupContext } from './context';
import type { TransformType } from './hooks/useImageTransform';

type OperationType =
| 'switchPrev'
| 'switchNext'
| 'prev'
| 'next'
| 'flipY'
| 'flipX'
| 'rotateLeft'
Expand Down Expand Up @@ -126,8 +126,7 @@ const Operations: React.FC<OperationsProps> = props => {
return (
<div
key={type}
className={classnames(toolClassName, {
[`${prefixCls}-operations-operation-${type}`]: true,
className={classnames(toolClassName, `${prefixCls}-operations-operation-${type}`, {
[`${prefixCls}-operations-operation-disabled`]: !!disabled,
})}
onClick={onClick}
Expand All @@ -143,7 +142,7 @@ const Operations: React.FC<OperationsProps> = props => {
? renderOperation({
icon: left,
onClick: e => handleActive(e, -1),
type: 'switchPrev',
type: 'prev',
disabled: current === 0,
})
: undefined;
Expand All @@ -152,7 +151,7 @@ const Operations: React.FC<OperationsProps> = props => {
? renderOperation({
icon: right,
onClick: e => handleActive(e, 1),
type: 'switchNext',
type: 'next',
disabled: current === count - 1,
})
: undefined;
Expand Down
15 changes: 13 additions & 2 deletions tests/preview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,13 @@ describe('Preview', () => {
toolbarRender: (_, { icons, actions }) => {
return (
<>
{icons.prevIcon}
{icons.nextIcon}
<div id="left" onClick={() => actions.onActive(-1)}>
{icons.prevIcon}
Prev
</div>
<div id="right" onClick={() => actions.onActive(1)}>
{icons.nextIcon}
Next
</div>
</>
);
Expand All @@ -902,6 +904,15 @@ describe('Preview', () => {
/>,
);

// Origin Node
fireEvent.click(document.querySelector('.rc-image-preview-operations-operation-prev'));
expect(onChange).toHaveBeenCalledWith(0, 1);

fireEvent.click(document.querySelector('.rc-image-preview-operations-operation-next'));
expect(onChange).toHaveBeenCalledWith(2, 1);

// Customize
onChange.mockReset();
fireEvent.click(document.getElementById('left'));
expect(onChange).toHaveBeenCalledWith(0, 1);

Expand Down

0 comments on commit 65f38fb

Please sign in to comment.