Skip to content

Commit

Permalink
test: 单测修复
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Nov 17, 2023
1 parent 7e00b04 commit 356bfe8
Show file tree
Hide file tree
Showing 17 changed files with 736 additions and 228 deletions.
27 changes: 16 additions & 11 deletions packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
BaseEvent,
BaseTooltipOperatorMenuOptions,
HeaderCell,
TooltipOptions,
} from '../../../src';
import { PivotDataSet } from '../../../src/data-set';
import { PivotFacet } from '../../../src/facet';
Expand Down Expand Up @@ -908,22 +909,26 @@ describe('PivotSheet Tests', () => {
const groupDescText = isEnUS ? 'Group DESC' : '组内降序';
const groupNoneText = isEnUS ? 'No order' : '不排序';

expect(showTooltipWithInfoSpy).toHaveBeenLastCalledWith(
expect.anything(),
expect.anything(),
{
onlyShowOperator: true,
forceRender: true,
operator: {
menus: [
{ icon: 'groupAsc', key: 'asc', text: groupAscText },
{ icon: 'groupDesc', key: 'desc', text: groupDescText },
{ key: 'none', text: groupNoneText },
const options: TooltipOptions = {
onlyShowOperator: true,
forceRender: true,
operator: {
menu: {
items: [
{ icon: 'groupAsc', key: 'asc', label: groupAscText },
{ icon: 'groupDesc', key: 'desc', label: groupDescText },
{ key: 'none', label: groupNoneText },
],
onClick: expect.anything(),
defaultSelectedKeys: [],
},
},
};

expect(showTooltipWithInfoSpy).toHaveBeenLastCalledWith(
expect.anything(),
expect.anything(),
options,
);
sheet.destroy();
},
Expand Down
32 changes: 18 additions & 14 deletions packages/s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getContainer } from 'tests/util/helpers';
import * as dataCfg from 'tests/data/simple-table-data.json';
import { getContainer } from 'tests/util/helpers';
import { TableDataSet } from '../../../src/data-set';
import { TableFacet } from '../../../src/facet';
import type { GEvent } from '@/index';
import { TableSheet } from '@/sheet-type';
import { S2Event, setLang, type LangType, type S2Options } from '@/common';
import { Node } from '@/facet/layout/node';
import type { GEvent, TooltipOptions } from '@/index';
import { TableSheet } from '@/sheet-type';

describe('TableSheet Tests', () => {
let s2: TableSheet;
Expand Down Expand Up @@ -194,22 +194,26 @@ describe('TableSheet Tests', () => {
const groupDescText = isEnUS ? 'DESC' : '降序';
const groupNoneText = isEnUS ? 'No order' : '不排序';

expect(showTooltipWithInfoSpy).toHaveBeenLastCalledWith(
expect.anything(),
expect.anything(),
{
forceRender: true,
onlyShowOperator: true,
operator: {
menus: [
{ icon: 'groupAsc', key: 'asc', text: groupAscText },
{ icon: 'groupDesc', key: 'desc', text: groupDescText },
{ key: 'none', text: groupNoneText },
const options: TooltipOptions = {
onlyShowOperator: true,
forceRender: true,
operator: {
menu: {
items: [
{ icon: 'groupAsc', key: 'asc', label: groupAscText },
{ icon: 'groupDesc', key: 'desc', label: groupDescText },
{ key: 'none', label: groupNoneText },
],
onClick: expect.anything(),
defaultSelectedKeys: [],
},
},
};

expect(showTooltipWithInfoSpy).toHaveBeenLastCalledWith(
expect.anything(),
expect.anything(),
options,
);
sheet.destroy();
},
Expand Down
20 changes: 12 additions & 8 deletions packages/s2-core/__tests__/unit/utils/merge-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('merge test', () => {
});

test('should get safety options', () => {
// 加这个测试可以防止 本地跑demo 修改了默认配置 直接提交
// 加这个测试可以防止 本地跑 demo 修改了默认配置 直接提交
expect(omit(getSafetyOptions(null), ['devicePixelRatio']))
.toMatchInlineSnapshot(`
Object {
Expand Down Expand Up @@ -256,7 +256,9 @@ describe('merge test', () => {
"enable": false,
"operation": Object {
"hiddenColumns": false,
"menus": Array [],
"menu": Object {
"items": Array [],
},
"sort": false,
},
},
Expand Down Expand Up @@ -290,12 +292,14 @@ describe('merge test', () => {
"enable": false,
"operation": Object {
"hiddenColumns": false,
"menus": Array [
Object {
"key": "custom",
"text": "custom",
},
],
"menu": Object {
"items": Array [
Object {
"key": "custom",
"label": "custom",
},
],
},
"sort": false,
},
}
Expand Down
11 changes: 8 additions & 3 deletions packages/s2-core/__tests__/unit/utils/tooltip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
type TooltipSummaryOptions,
PivotSheet,
type S2DataConfig,
type S2Options,
} from '@/index';
import type { BaseFacet } from '@/facet/base-facet';
import type { BBox } from '@/engine';
Expand Down Expand Up @@ -312,16 +313,20 @@ describe('Tooltip Utils Tests', () => {
[type],
);

expect(tooltipOptions).toEqual({
const expectTooltipOptions: S2Options['tooltip'] = {
enable: true,
content: '',
operation: {
hiddenColumns: false,
sort: true,
tableSort: true,
menus: [{ key: 'menu-b', text: 'menu-b' }],
menu: {
items: [{ key: 'menu-b', label: 'menu-b' }],
},
},
});
};

expect(tooltipOptions).toEqual(expectTooltipOptions);
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`Pagination Tests should receive antd <Pagination/> component extra prop
class="antv-s2-pagination"
>
<ul
class="ant-pagination ant-pagination-mini"
class="ant-pagination ant-pagination-mini css-dev-only-do-not-override-1adbn6x"
>
<li
aria-disabled="false"
Expand Down Expand Up @@ -124,7 +124,7 @@ exports[`Pagination Tests should render locale text for { locale: 'en_US', page:
class="antv-s2-pagination"
>
<ul
class="ant-pagination ant-pagination-mini"
class="ant-pagination ant-pagination-mini css-dev-only-do-not-override-1adbn6x"
>
<li
aria-disabled="true"
Expand Down Expand Up @@ -217,7 +217,7 @@ exports[`Pagination Tests should render locale text for { locale: 'en_US', page:
>
<div
aria-label="Page Size"
class="ant-select ant-select-sm ant-pagination-options-size-changer ant-select-single ant-select-show-arrow"
class="ant-select ant-select-sm ant-pagination-options-size-changer css-dev-only-do-not-override-1adbn6x ant-select-single ant-select-show-arrow ant-select-show-search"
>
<div
class="ant-select-selector"
Expand All @@ -226,7 +226,6 @@ exports[`Pagination Tests should render locale text for { locale: 'en_US', page:
class="ant-select-selection-search"
>
<input
aria-activedescendant="rc_select_TEST_OR_SSR_list_0"
aria-autocomplete="list"
aria-controls="rc_select_TEST_OR_SSR_list"
aria-expanded="false"
Expand All @@ -236,11 +235,8 @@ exports[`Pagination Tests should render locale text for { locale: 'en_US', page:
autocomplete="off"
class="ant-select-selection-search-input"
id="rc_select_TEST_OR_SSR"
readonly=""
role="combobox"
style="opacity: 0;"
type="search"
unselectable="on"
value=""
/>
</span>
Expand Down Expand Up @@ -295,7 +291,7 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
class="antv-s2-pagination"
>
<ul
class="ant-pagination ant-pagination-mini"
class="ant-pagination ant-pagination-mini css-dev-only-do-not-override-1adbn6x"
>
<li
aria-disabled="true"
Expand Down Expand Up @@ -377,7 +373,7 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
>
<div
aria-label="页码"
class="ant-select ant-select-sm ant-pagination-options-size-changer ant-select-single ant-select-show-arrow"
class="ant-select ant-select-sm ant-pagination-options-size-changer css-dev-only-do-not-override-1adbn6x ant-select-single ant-select-show-arrow ant-select-show-search"
>
<div
class="ant-select-selector"
Expand All @@ -386,7 +382,6 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
class="ant-select-selection-search"
>
<input
aria-activedescendant="rc_select_TEST_OR_SSR_list_0"
aria-autocomplete="list"
aria-controls="rc_select_TEST_OR_SSR_list"
aria-expanded="false"
Expand All @@ -396,11 +391,8 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
autocomplete="off"
class="ant-select-selection-search-input"
id="rc_select_TEST_OR_SSR"
readonly=""
role="combobox"
style="opacity: 0;"
type="search"
unselectable="on"
value=""
/>
</span>
Expand Down Expand Up @@ -456,7 +448,7 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
class="antv-s2-pagination"
>
<ul
class="ant-pagination ant-pagination-mini"
class="ant-pagination ant-pagination-mini css-dev-only-do-not-override-1adbn6x"
>
<li
aria-disabled="true"
Expand Down Expand Up @@ -538,7 +530,7 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
>
<div
aria-label="页码"
class="ant-select ant-select-sm ant-pagination-options-size-changer ant-select-single ant-select-show-arrow"
class="ant-select ant-select-sm ant-pagination-options-size-changer css-dev-only-do-not-override-1adbn6x ant-select-single ant-select-show-arrow ant-select-show-search"
>
<div
class="ant-select-selector"
Expand All @@ -547,7 +539,6 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
class="ant-select-selection-search"
>
<input
aria-activedescendant="rc_select_TEST_OR_SSR_list_0"
aria-autocomplete="list"
aria-controls="rc_select_TEST_OR_SSR_list"
aria-expanded="false"
Expand All @@ -557,11 +548,8 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
autocomplete="off"
class="ant-select-selection-search-input"
id="rc_select_TEST_OR_SSR"
readonly=""
role="combobox"
style="opacity: 0;"
type="search"
unselectable="on"
value=""
/>
</span>
Expand Down Expand Up @@ -617,7 +605,7 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
class="antv-s2-pagination"
>
<ul
class="ant-pagination ant-pagination-mini"
class="ant-pagination ant-pagination-mini css-dev-only-do-not-override-1adbn6x"
>
<li
aria-disabled="true"
Expand Down Expand Up @@ -710,7 +698,7 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
>
<div
aria-label="页码"
class="ant-select ant-select-sm ant-pagination-options-size-changer ant-select-single ant-select-show-arrow"
class="ant-select ant-select-sm ant-pagination-options-size-changer css-dev-only-do-not-override-1adbn6x ant-select-single ant-select-show-arrow ant-select-show-search"
>
<div
class="ant-select-selector"
Expand All @@ -719,7 +707,6 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
class="ant-select-selection-search"
>
<input
aria-activedescendant="rc_select_TEST_OR_SSR_list_0"
aria-autocomplete="list"
aria-controls="rc_select_TEST_OR_SSR_list"
aria-expanded="false"
Expand All @@ -729,11 +716,8 @@ exports[`Pagination Tests should render locale text for { locale: 'zh_CN', page:
autocomplete="off"
class="ant-select-selection-search-input"
id="rc_select_TEST_OR_SSR"
readonly=""
role="combobox"
style="opacity: 0;"
type="search"
unselectable="on"
value=""
/>
</span>
Expand Down
Loading

0 comments on commit 356bfe8

Please sign in to comment.