test: update

This commit is contained in:
Wanpan 2024-08-20 01:56:25 +08:00
parent 4d1c6ac775
commit b29c3b9781
4 changed files with 36 additions and 27 deletions

View File

@ -14,7 +14,7 @@ exports[`Splitter The mousemove should work fine. 1`] = `
>
<div
class="ant-splitter-panel"
style="flex-basis: calc(80% - 1px);"
style="flex-basis: calc(60% - 1px);"
>
0
</div>
@ -31,7 +31,7 @@ exports[`Splitter The mousemove should work fine. 1`] = `
</div>
<div
class="ant-splitter-panel"
style="flex-basis: calc(20% - 1px);"
style="flex-basis: calc(40% - 1px);"
>
1
</div>
@ -58,7 +58,7 @@ exports[`Splitter The mousemove should work fine. 1`] = `
>
<div
class="ant-splitter-panel"
style="flex-basis: calc(25% - 1px);"
style="flex-basis: calc(70% - 1px);"
>
0
</div>
@ -75,7 +75,7 @@ exports[`Splitter The mousemove should work fine. 1`] = `
</div>
<div
class="ant-splitter-panel"
style="flex-basis: calc(75% - 1px);"
style="flex-basis: calc(30% - 1px);"
>
1
</div>

View File

@ -278,15 +278,6 @@ describe('Splitter', () => {
expect(mockStart).toHaveBeenCalled();
expect(mockMoving).toHaveBeenCalledWith([60, 40], 0);
expect(mockEnd).toHaveBeenCalled();
// min
fireEvent.mouseDown(container?.querySelectorAll('.ant-splitter-bar')[0]!, {
clientX: 0,
clientY: 0,
});
fireEvent.mouseMove(document.documentElement, { clientX: 160 });
await waitFakeTimer();
fireEvent.mouseUp(document.documentElement);
expect(mockMoving).toHaveBeenLastCalledWith([80, 20], 0);
// layout vertical
fireEvent.mouseDown(container?.querySelectorAll('.ant-splitter-bar')[2]!, {
@ -298,16 +289,34 @@ describe('Splitter', () => {
await waitFakeTimer();
fireEvent.mouseUp(document.documentElement);
expect(mockMovingVertical).toHaveBeenCalledWith([70, 30], 0);
// max
fireEvent.mouseDown(container?.querySelectorAll('.ant-splitter-bar')[2]!, {
clientX: 0,
clientY: 0,
});
fireEvent.mouseMove(document.documentElement, { clientY: -200 });
await waitFakeTimer();
fireEvent.mouseUp(document.documentElement);
expect(mockMovingVertical).toHaveBeenLastCalledWith([25, 75], 0);
expect(container).toMatchSnapshot();
});
it('The min max should work fine.', async () => {
const mockMoving = jest.fn();
const { container } = render(
<SplitterDemo items={[{ min: 10 }, { max: 60 }, {}, {}]} onResize={mockMoving} />,
);
// min
fireEvent.mouseDown(container?.querySelectorAll('.ant-splitter-bar')[0]!, {
clientX: 0,
clientY: 0,
});
fireEvent.mouseMove(document.documentElement, { clientX: -160 }); // 40%
await waitFakeTimer();
fireEvent.mouseUp(document.documentElement);
expect(mockMoving).toHaveBeenNthCalledWith(1, [10, 40, 25, 25], 0);
// max
fireEvent.mouseDown(container?.querySelectorAll('.ant-splitter-bar')[1]!, {
clientX: 0,
clientY: 0,
});
fireEvent.mouseMove(document.documentElement, { clientX: 160 }); // 40%
await waitFakeTimer();
fireEvent.mouseUp(document.documentElement);
expect(mockMoving).toHaveBeenNthCalledWith(2, [10, 60, 5, 25], 1);
});
});

View File

@ -48,7 +48,7 @@ tag: 5.21.0
| max | 最大阈值 `1-100 \| '10%' \| '200px'` | `number \| string` | - | - |
| size | 受控面板大小 `1-100 \| '10%' \| '200px'` | `number \| string` | - | - |
| defaultSize | 初始面板大小 `1-100 \| '10%' \| '200px'` | `number \| string` | 50 | - |
| collapsible | 快速折叠 P | `boolean \| { prev?: boolean; next?: boolean }` | `false` | - |
| collapsible | 快速折叠 | `boolean \| { prev?: boolean; next?: boolean }` | `false` | - |
| resizable | 是否开启拖拽伸缩 | `boolean` | `true` | - |
## 主题变量Design Token

View File

@ -92,12 +92,12 @@ const useResize = ({
skipNext = true;
} else if (previousSize < 0) {
previousSize = 0;
} else if (previousSize > percentCount) {
previousSize = percentCount;
} else if (previousSize > previousMaxNumber) {
previousSize = previousMaxNumber;
nextSize = percentCount - previousSize;
skipNext = true;
} else if (previousSize > percentCount) {
previousSize = percentCount;
}
if (!skipNext) {
@ -106,11 +106,11 @@ const useResize = ({
previousSize = percentCount - nextSize;
} else if (nextSize < 0) {
nextSize = 0;
} else if (nextSize > percentCount) {
nextSize = percentCount;
} else if (nextSize > nextMaxNumber) {
nextSize = nextMaxNumber;
previousSize = percentCount - nextSize;
} else if (nextSize > percentCount) {
nextSize = percentCount;
}
}