Skip to content

Commit

Permalink
test: 单测修复
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Nov 10, 2023
1 parent 1a1eda9 commit 14ac702
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ exports[`Pagination Tests should render locale text for { locale: 'en_US', page:
</button>
</li>
<li
class="ant-pagination-item ant-pagination-item-1 ant-pagination-item-active"
class="ant-pagination-item ant-pagination-item-1 ant-pagination-item-disabled"
tabindex="0"
title="1"
>
Expand All @@ -170,24 +170,13 @@ exports[`Pagination Tests should render locale text for { locale: 'en_US', page:
</a>
</li>
<li
class="ant-pagination-item ant-pagination-item-2"
tabindex="0"
title="2"
>
<a
rel="nofollow"
>
2
</a>
</li>
<li
aria-disabled="false"
class="ant-pagination-next"
tabindex="0"
aria-disabled="true"
class="ant-pagination-next ant-pagination-disabled"
title="Next Page"
>
<button
class="ant-pagination-item-link"
disabled=""
tabindex="-1"
type="button"
>
Expand Down Expand Up @@ -282,10 +271,10 @@ exports[`Pagination Tests should render locale text for { locale: 'en_US', page:
</ul>
<span
class="antv-s2-pagination-count"
title="Total2"
title="Total0"
>
Total
2
-
</span>
</div>
`;
Expand Down
89 changes: 45 additions & 44 deletions packages/s2-react/__tests__/spreadsheet/adaptive-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';
import { act } from 'react-dom/test-utils';
import * as mockDataConfig from 'tests/data/simple-data.json';
import { getContainer, renderComponent, sleep } from 'tests/util/helpers';
import { waitFor } from '@testing-library/react';
import { SheetComponent } from '@/components/sheets';
import type { SheetComponentsProps } from '@/components';

Expand Down Expand Up @@ -89,10 +90,10 @@ describe('SheetComponent adaptive Tests', () => {
test('should use container width when table first rendered', async () => {
renderComponent(<MainLayout adaptive containerWidth={400} />);

await sleep(1000);

expect(s2!.options.width).toEqual(400);
expect(s2!.container.getConfig().width).toEqual(400);
await waitFor(() => {
expect(s2!.options.width).toEqual(400);
expect(s2!.container.getConfig().width).toEqual(400);
});
});

test('should use option width and height when table first rendered, and disable adaptive', async () => {
Expand All @@ -104,12 +105,12 @@ describe('SheetComponent adaptive Tests', () => {
/>,
);

await sleep(1000);

expect(s2!.options.width).toEqual(s2Options.width);
expect(s2!.options.height).toEqual(s2Options.height);
expect(s2!.container.getConfig().width).toEqual(s2Options.width);
expect(s2!.container.getConfig().height).toEqual(s2Options.height);
await waitFor(() => {
expect(s2!.options.width).toEqual(s2Options.width);
expect(s2!.options.height).toEqual(s2Options.height);
expect(s2!.container.getConfig().width).toEqual(s2Options.width);
expect(s2!.container.getConfig().height).toEqual(s2Options.height);
});
});

test('should update table width and height when container resize', async () => {
Expand Down Expand Up @@ -139,12 +140,12 @@ describe('SheetComponent adaptive Tests', () => {
window.dispatchEvent(new Event('resize'));
});

await sleep(1000);

expect(s2!.options.width).toEqual(newContainerWidth);
expect(s2!.options.height).toEqual(newContainerHeight);
expect(s2!.container.getConfig().height).toEqual(newContainerHeight);
expect(s2!.container.getConfig().width).toEqual(newContainerWidth);
await waitFor(() => {
expect(s2!.options.width).toEqual(newContainerWidth);
expect(s2!.options.height).toEqual(newContainerHeight);
expect(s2!.container.getConfig().height).toEqual(newContainerHeight);
expect(s2!.container.getConfig().width).toEqual(newContainerWidth);
});
});

// https://github.com/antvis/S2/issues/792
Expand Down Expand Up @@ -172,19 +173,19 @@ describe('SheetComponent adaptive Tests', () => {
);
});

await sleep(1000);

const canvas = s2!.getCanvasElement();
await waitFor(() => {
const canvas = s2!.getCanvasElement();

// render by resized parent container
expect(s2!.options.width).toEqual(newContainerWidth);
expect(s2!.options.height).toEqual(newContainerHeight);
expect(s2!.container.getConfig().width).toEqual(newContainerWidth);
expect(s2!.container.getConfig().height).toEqual(newContainerHeight);
// render by resized parent container
expect(s2!.options.width).toEqual(newContainerWidth);
expect(s2!.options.height).toEqual(newContainerHeight);
expect(s2!.container.getConfig().width).toEqual(newContainerWidth);
expect(s2!.container.getConfig().height).toEqual(newContainerHeight);

// update canvas width
expect(canvas.style.width).toEqual(`${newContainerWidth}px`);
expect(canvas.style.height).toEqual(`${newContainerHeight}px`);
// update canvas width
expect(canvas.style.width).toEqual(`${newContainerWidth}px`);
expect(canvas.style.height).toEqual(`${newContainerHeight}px`);
});
});

test("should don't update canvas size when container resize but disable adaptive", async () => {
Expand All @@ -205,14 +206,14 @@ describe('SheetComponent adaptive Tests', () => {
);
});

await sleep(1000);

const canvas = s2!.getCanvasElement() as HTMLCanvasElement;
await waitFor(() => {
const canvas = s2!.getCanvasElement() as HTMLCanvasElement;

expect(s2!.options.width).toEqual(200);
expect(s2!.container.getConfig().width).toEqual(200);
expect(canvas.style.width).toEqual(`200px`);
expect(canvas.style.height).toEqual(`200px`);
expect(s2!.options.width).toEqual(200);
expect(s2!.container.getConfig().width).toEqual(200);
expect(canvas.style.width).toEqual(`200px`);
expect(canvas.style.height).toEqual(`200px`);
});
});

// canvas need to set "display: block", otherwise have `5px` difference with container
Expand All @@ -221,14 +222,14 @@ describe('SheetComponent adaptive Tests', () => {

renderComponent(<MainLayout adaptive containerId={containerId} />);

await sleep(1000);

const container = document.getElementById(containerId)!;
const canvas = s2!.getCanvasElement();
await waitFor(() => {
const container = document.getElementById(containerId)!;
const canvas = s2!.getCanvasElement();

const { height: containerHeight } = container.getBoundingClientRect();
const { height: containerHeight } = container.getBoundingClientRect();

expect(`${Math.round(containerHeight)}px`).toEqual(canvas.style.height);
expect(`${Math.round(containerHeight)}px`).toEqual(canvas.style.height);
});
});

// https://github.com/antvis/S2/issues/901
Expand Down Expand Up @@ -303,9 +304,9 @@ describe('SheetComponent adaptive Tests', () => {
window.dispatchEvent(new Event('resize'));
});

await sleep(1000);

expect(s2!.options.width).toEqual(newContainerWidth);
expect(s2!.container.getConfig().width).toEqual(newContainerWidth);
await waitFor(() => {
expect(s2!.options.width).toEqual(newContainerWidth);
expect(s2!.container.getConfig().width).toEqual(newContainerWidth);
});
});
});

0 comments on commit 14ac702

Please sign in to comment.