Skip to content

Commit

Permalink
Merge pull request #237 from actiontech/test/DMS-841
Browse files Browse the repository at this point in the history
[test]:(useOpPermission, SideMenu) Supplementary testing coverage
  • Loading branch information
anny1021 authored Feb 29, 2024
2 parents f02b177 + 91b141b commit cdeadb1
Show file tree
Hide file tree
Showing 14 changed files with 4,014 additions and 5 deletions.
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module.exports = {
'packages/shared/api/common/**',
'!packages/**/index.type.ts',
'!packages/**/index.enum.ts',
'!packages/sqle/src/page/AuditPlan/**'
'!packages/sqle/src/page/AuditPlan/**',
'!packages/shared/lib/hooks/usePrompt/index.tsx'
],
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
reporters: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test useManagerPermission should render options when use generateOpPermissionSelectOptions 1`] = `
<body>
<div />
<div>
<div
class="ant-select css-dev-only-do-not-override-txh9fw ant-select-single ant-select-show-arrow"
data-testid="testId"
>
<div
class="ant-select-selector"
>
<span
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"
aria-haspopup="listbox"
aria-owns="rc_select_TEST_OR_SSR_list"
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>
<span
class="ant-select-selection-item"
title="test opPermission 1"
>
test opPermission 1
</span>
</div>
<span
aria-hidden="true"
class="ant-select-arrow"
style="user-select: none;"
unselectable="on"
>
<span
aria-label="down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
aria-hidden="true"
data-icon="down"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"
/>
</svg>
</span>
</span>
</div>
</div>
</body>
`;

exports[`test useManagerPermission should render options when use generateOpPermissionSelectOptions 2`] = `
<body>
<div />
<div>
<div
class="ant-select css-dev-only-do-not-override-txh9fw ant-select-single ant-select-show-arrow ant-select-open"
data-testid="testId"
>
<div
class="ant-select-selector"
>
<span
class="ant-select-selection-search"
>
<input
aria-activedescendant="rc_select_TEST_OR_SSR_list_-1"
aria-autocomplete="list"
aria-controls="rc_select_TEST_OR_SSR_list"
aria-expanded="true"
aria-haspopup="listbox"
aria-owns="rc_select_TEST_OR_SSR_list"
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>
<span
class="ant-select-selection-item"
title="test opPermission 1"
>
test opPermission 1
</span>
</div>
<span
aria-hidden="true"
class="ant-select-arrow"
style="user-select: none;"
unselectable="on"
>
<span
aria-label="down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
aria-hidden="true"
data-icon="down"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"
/>
</svg>
</span>
</span>
</div>
</div>
<div>
<div
class="ant-select-dropdown ant-slide-up-appear ant-slide-up-appear-prepare ant-slide-up css-dev-only-do-not-override-txh9fw ant-select-dropdown-empty ant-select-dropdown-placement-bottomLeft"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: 0; width: 0px;"
>
<div>
<div
class="ant-select-item-empty"
id="rc_select_TEST_OR_SSR_list"
role="listbox"
>
<div
class="css-dev-only-do-not-override-txh9fw ant-empty ant-empty-normal ant-empty-small"
>
<div
class="ant-empty-image"
>
<svg
height="41"
viewBox="0 0 64 41"
width="64"
xmlns="http://www.w3.org/2000/svg"
>
<g
fill="none"
fill-rule="evenodd"
transform="translate(0 1)"
>
<ellipse
cx="32"
cy="33"
fill="#f5f5f5"
rx="32"
ry="7"
/>
<g
fill-rule="nonzero"
stroke="#d9d9d9"
>
<path
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
/>
<path
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
fill="#fafafa"
/>
</g>
</g>
</svg>
</div>
<div
class="ant-empty-description"
>
No data
</div>
</div>
</div>
</div>
</div>
</div>
</body>
`;
6 changes: 4 additions & 2 deletions packages/base/src/hooks/useOpPermission/index.data.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { StringDictionary } from '@actiontech/shared/lib/types/common.type';
import { t } from '../../locale';
import { ListMemberRoleWithOpRangeOpRangeTypeEnum } from '@actiontech/shared/lib/api/base/service/common.enum';

const rangeTypeDictionary: StringDictionary = {
const rangeTypeDictionary: Record<
keyof typeof ListMemberRoleWithOpRangeOpRangeTypeEnum,
string
> = {
[ListMemberRoleWithOpRangeOpRangeTypeEnum.global]: t(
'dmsUserCenter.role.opPermissionList.rangeTypeDictionary.global'
),
Expand Down
30 changes: 29 additions & 1 deletion packages/base/src/hooks/useOpPermission/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { cleanup, act, renderHook } from '@testing-library/react';
import {
cleanup,
act,
renderHook,
render,
fireEvent,
screen
} from '@testing-library/react';
import useOpPermission from '.';
import userCenter from '../../testUtils/mockApi/userCenter';
import { opPermissionList } from '../../testUtils/mockApi/userCenter/data';
import {
createSpyErrorResponse,
createSpyFailResponse
} from '@actiontech/shared/lib/testUtil/mockApi';
import { Select } from 'antd';

describe('test useManagerPermission', () => {
let listOpPermissionSpy: jest.SpyInstance;
Expand Down Expand Up @@ -58,4 +66,24 @@ describe('test useManagerPermission', () => {
await act(async () => jest.advanceTimersByTime(3000));
expect(result.current.opPermissionList).toEqual([]);
});

it('should render options when use generateOpPermissionSelectOptions', async () => {
const { result } = renderHook(() => useOpPermission());
const { baseElement: baseElementWithOptions } = render(
<Select data-testid="testId" value="test opPermission 1">
{result.current.generateOpPermissionSelectOptions()}
</Select>
);

await act(async () => jest.advanceTimersByTime(3000));
expect(baseElementWithOptions).toMatchSnapshot();

await act(() => {
fireEvent.mouseDown(screen.getByText('test opPermission 1'));
jest.runAllTimers();
});

await screen.findAllByText('test opPermission 1');
expect(baseElementWithOptions).toMatchSnapshot();
});
});
Loading

0 comments on commit cdeadb1

Please sign in to comment.