Skip to content

Commit

Permalink
[test](sqle/Rule): add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zzyangh committed Jan 18, 2024
1 parent 457ff03 commit 32a1792
Show file tree
Hide file tree
Showing 12 changed files with 3,242 additions and 1,167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
GetUserStatEnum
} from '../../api/base/service/common.enum';
import { OpPermissionTypeUid, SupportTheme, SystemRole } from '../../enum';
import DatabaseTypeLogo from '../../components/DatabaseTypeLogo';

export const mockCurrentUserReturn = {
isAdmin: true,
Expand Down Expand Up @@ -79,11 +80,17 @@ export const mockDBServiceDriverInfo = {
params: []
}
],
dbDriverOptions: [],
dbDriverOptions: [
{
text: 'MySQL',
value: 'MysQL',
label: <DatabaseTypeLogo dbType="MySQL" logoUrl="" />
}
],
updateDriverList: jest.fn(),
updateDriverListSync: jest.fn(),
getLogoUrlByDbType: jest.fn(),
generateDriverSelectOptions: jest.fn(),
driverInfoFetched: true,
setDriverInfoFetched: jest.fn
setDriverInfoFetched: jest.fn()
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import * as useDbServiceDriver from '../../global/useDbServiceDriver';
import { mockDBServiceDriverInfo } from './data';

export const mockUseDbServiceDriver = () => {
export const mockUseDbServiceDriver = (
mockData?: Partial<typeof mockDBServiceDriverInfo>
) => {
const spy = jest.spyOn(useDbServiceDriver, 'default');
spy.mockImplementation(() => mockDBServiceDriverInfo);
spy.mockImplementation(() => ({
...mockDBServiceDriverInfo,
...mockData
}));
return spy;
};
17 changes: 3 additions & 14 deletions packages/sqle/src/page/Rule/RuleListFilter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Form, Space, FormInstance } from 'antd';
import { Form, Space } from 'antd';
import { CustomSelect } from '@actiontech/shared/lib/components/CustomSelect';
import CustomSearchInput from '../../../components/RuleDetail/components/CustomSearchInput';
import { useTranslation } from 'react-i18next';
Expand All @@ -12,23 +12,12 @@ import { IconProjectFlag } from '@actiontech/shared/lib/Icon/common';
import useRuleTemplate from '../../../hooks/useRuleTemplate';
import useGlobalRuleTemplate from '../../../hooks/useGlobalRuleTemplate';
import { useDbServiceDriver } from '@actiontech/shared/lib/global';
import { RuleListFilterForm } from '../index.type';
import { RuleListFilterProps } from '../index.type';
import { useLocation } from 'react-router-dom';
import { IBindProject } from '../../../../../base/src/store/user';
import CustomSelectField from './CustomSelectFiled';
import { RuleUrlParamKey } from '@actiontech/shared/lib/types/common.type';

const RuleListFilter: React.FC<{
form: FormInstance<RuleListFilterForm>;
getTemplateRules: (
projectName?: string | undefined,
ruleTemplateName?: string | undefined,
fuzzyKeyword?: string | undefined
) => void;
setShowNorRuleTemplatePage: (v: boolean) => void;
bindProjects: IBindProject[];
getAllRules: () => void;
}> = ({
const RuleListFilter: React.FC<RuleListFilterProps> = ({
setShowNorRuleTemplatePage,
form,
getTemplateRules,
Expand Down
Loading

0 comments on commit 32a1792

Please sign in to comment.