From bf09d72a8b24b4fee87b92db5184423a22d5da9c Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Mon, 22 Jan 2024 15:46:26 +0800 Subject: [PATCH 01/27] upgrade system title --- .../src/page/System/GlobalSetting/index.tsx | 152 +++++++++--------- .../base/src/page/System/License/index.tsx | 58 ++++--- .../src/page/System/LoginConnection/index.tsx | 14 +- .../page/System/PersonalizeSetting/index.tsx | 8 +- .../page/System/ProcessConnection/index.tsx | 14 +- .../page/System/PushNotification/index.tsx | 19 ++- .../System/components/BasicTitle/index.tsx | 38 +++++ packages/base/src/page/System/index.tsx | 4 +- 8 files changed, 171 insertions(+), 136 deletions(-) create mode 100644 packages/base/src/page/System/components/BasicTitle/index.tsx diff --git a/packages/base/src/page/System/GlobalSetting/index.tsx b/packages/base/src/page/System/GlobalSetting/index.tsx index 19c182a8a..5066f5a68 100644 --- a/packages/base/src/page/System/GlobalSetting/index.tsx +++ b/packages/base/src/page/System/GlobalSetting/index.tsx @@ -14,6 +14,7 @@ import { IUpdateSystemVariablesReqV1 } from '@actiontech/shared/lib/api/sqle/ser import { integerValidate } from '@actiontech/shared/lib/utils/Common'; import useHideConfigInputNode from '../../../../../shared/lib/components/ConfigItem/hooks/useHideConfigInputNode'; import { ConfigFieldMapMeta } from '@actiontech/shared/lib/components/ConfigItem/index.type'; +import SystemBasicTitle from '../components/BasicTitle'; const GlobalSetting = () => { const { t } = useTranslation(); @@ -121,80 +122,83 @@ const GlobalSetting = () => { }; return ( -
-
- {t('dmsSystem.tabPaneTitle.globalConfiguration')} -
- - {messageContextHolder} - {`${t('dmsSystem.global.orderExpiredHours')}(${t( - 'common.time.hour' - )})`} - } - descNode={String(globalConfig?.workflow_expired_hours ?? '-')} - fieldVisible={orderExpiredHoursFieldVisible} - showField={showOrderExpiredHoursField} - hideField={hideOrderExpiredHoursField} - inputNode={ - integerValidator(String(value))} - hideField={hideOrderExpiredHoursField} - onSubmit={(value: number) => { - submitGlobalConfig(value, 'workflow_expired_hours'); - }} - /> - } - /> - {`${t( - 'dmsSystem.global.operationRecordExpiredHours' - )}(${t('common.time.hour')})`} - } - descNode={String(globalConfig?.operation_record_expired_hours ?? '-')} - fieldVisible={operationRecordExpiredHoursField} - showField={showOperationRecordExpiredHoursField} - hideField={hideOperationRecordExpiredHoursField} - inputNode={ - integerValidator(String(value))} - hideField={hideOperationRecordExpiredHoursField} - onSubmit={(value: number) => { - submitGlobalConfig(value, 'operation_record_expired_hours'); - }} - /> - } - /> - - {t('dmsSystem.global.urlAddressPrefix')} - - } - descNode={!!globalConfig?.url ? globalConfig.url : '-'} - fieldVisible={urlFieldVisible} - showField={showUrlField} - hideField={hideUrlField} - inputNode={ - { - submitGlobalConfig(value, 'url'); - }} - /> - } - /> - -
+ + <> + + {messageContextHolder} + {`${t('dmsSystem.global.orderExpiredHours')}(${t( + 'common.time.hour' + )})`} + } + descNode={String(globalConfig?.workflow_expired_hours ?? '-')} + fieldVisible={orderExpiredHoursFieldVisible} + showField={showOrderExpiredHoursField} + hideField={hideOrderExpiredHoursField} + inputNode={ + integerValidator(String(value))} + hideField={hideOrderExpiredHoursField} + onSubmit={(value: number) => { + submitGlobalConfig(value, 'workflow_expired_hours'); + }} + /> + } + /> + {`${t( + 'dmsSystem.global.operationRecordExpiredHours' + )}(${t('common.time.hour')})`} + } + descNode={String( + globalConfig?.operation_record_expired_hours ?? '-' + )} + fieldVisible={operationRecordExpiredHoursField} + showField={showOperationRecordExpiredHoursField} + hideField={hideOperationRecordExpiredHoursField} + inputNode={ + integerValidator(String(value))} + hideField={hideOperationRecordExpiredHoursField} + onSubmit={(value: number) => { + submitGlobalConfig(value, 'operation_record_expired_hours'); + }} + /> + } + /> + + {t('dmsSystem.global.urlAddressPrefix')} + + } + descNode={!!globalConfig?.url ? globalConfig.url : '-'} + fieldVisible={urlFieldVisible} + showField={showUrlField} + hideField={hideUrlField} + inputNode={ + { + submitGlobalConfig(value, 'url'); + }} + /> + } + /> + + + ); }; diff --git a/packages/base/src/page/System/License/index.tsx b/packages/base/src/page/System/License/index.tsx index 0fc3450ac..da5515a01 100644 --- a/packages/base/src/page/System/License/index.tsx +++ b/packages/base/src/page/System/License/index.tsx @@ -1,19 +1,20 @@ import { useBoolean, useRequest } from 'ahooks'; -import { Space } from 'antd'; import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useDispatch } from 'react-redux'; -import EmitterKey from '../../../data/EmitterKey'; + import { updateSystemModalStatus } from '../../../store/system'; +import dms from '@actiontech/shared/lib/api/base/service/dms'; import EventEmitter from '../../../utils/EventEmitter'; -import { Row } from 'antd'; -import { BasicButton, BasicToolTips } from '@actiontech/shared'; -import { LicenseColumn } from './index.data'; -import { IconTipGray } from '@actiontech/shared/lib/Icon'; -import { ActiontechTable } from '@actiontech/shared/lib/components/ActiontechTable'; +import EmitterKey from '../../../data/EmitterKey'; + +import { Space } from 'antd'; +import { BasicButton } from '@actiontech/shared'; import { ModalName } from '../../../data/ModalName'; +import SystemBasicTitle from '../components/BasicTitle'; import ImportLicense from './Modal/ImportLicense'; -import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { LicenseColumn } from './index.data'; +import { ActiontechTable } from '@actiontech/shared/lib/components/ActiontechTable'; const License = () => { const { t } = useTranslation(); @@ -54,19 +55,11 @@ const License = () => { }, [refreshLicenseList]); return ( -
- - - {t('dmsSystem.tabPaneTitle.license')} - {/* todo: 此处提示语待产品给出后调整 */} - - - - + { {t('dmsSystem.license.import')} - - - -
+ } + > + <> + + + + ); }; diff --git a/packages/base/src/page/System/LoginConnection/index.tsx b/packages/base/src/page/System/LoginConnection/index.tsx index 249c252bc..c3ac94b2d 100644 --- a/packages/base/src/page/System/LoginConnection/index.tsx +++ b/packages/base/src/page/System/LoginConnection/index.tsx @@ -1,18 +1,18 @@ import { useTranslation } from 'react-i18next'; import LDAPSetting from './LDAPSetting'; import Oauth from './Oauth'; +import SystemBasicTitle from '../components/BasicTitle'; const LoginConnection = () => { const { t } = useTranslation(); return ( -
-
- {t('dmsSystem.tabPaneTitle.loginConnection')} -
- - -
+ + <> + + + + ); }; diff --git a/packages/base/src/page/System/PersonalizeSetting/index.tsx b/packages/base/src/page/System/PersonalizeSetting/index.tsx index cc6fd8379..0e23c6197 100644 --- a/packages/base/src/page/System/PersonalizeSetting/index.tsx +++ b/packages/base/src/page/System/PersonalizeSetting/index.tsx @@ -18,6 +18,7 @@ import { useMemo } from 'react'; import { ConfigFieldMapMeta } from '@actiontech/shared/lib/components/ConfigItem/index.type'; import useHideConfigInputNode from '@actiontech/shared/lib/components/ConfigItem/hooks/useHideConfigInputNode'; import useSystemConfig from '../../../hooks/useSystemConfig'; +import SystemBasicTitle from '../components/BasicTitle'; const PersonalizeSetting: React.FC = () => { const { t } = useTranslation(); @@ -87,10 +88,7 @@ const PersonalizeSetting: React.FC = () => { }; return ( -
-
- {t('dmsSystem.tabPaneTitle.personalize')} -
+ { } /> -
+ ); }; diff --git a/packages/base/src/page/System/ProcessConnection/index.tsx b/packages/base/src/page/System/ProcessConnection/index.tsx index e9880e612..2b3522ab2 100644 --- a/packages/base/src/page/System/ProcessConnection/index.tsx +++ b/packages/base/src/page/System/ProcessConnection/index.tsx @@ -1,18 +1,18 @@ import { useTranslation } from 'react-i18next'; import DingTalkSetting from './DingTalkSetting'; import LarkAuditSetting from './LarkAuditSetting'; +import SystemBasicTitle from '../components/BasicTitle'; const ProcessConnection = () => { const { t } = useTranslation(); return ( -
-
- {t('dmsSystem.tabPaneTitle.processConnection')} -
- - -
+ + <> + + + + ); }; diff --git a/packages/base/src/page/System/PushNotification/index.tsx b/packages/base/src/page/System/PushNotification/index.tsx index 487b5cf5d..4858aaeb2 100644 --- a/packages/base/src/page/System/PushNotification/index.tsx +++ b/packages/base/src/page/System/PushNotification/index.tsx @@ -3,21 +3,20 @@ import SMTPSetting from './SMTPSetting'; import Wechat from './Wechat'; import LarkSetting from './LarkSetting'; import WebHook from './WebhookSetting'; +import SystemBasicTitle from '../components/BasicTitle'; const PushNotification = () => { const { t } = useTranslation(); return ( -
-
- {t('dmsSystem.tabPaneTitle.pushNotification')} -
- - - - - -
+ + <> + + + + + + ); }; diff --git a/packages/base/src/page/System/components/BasicTitle/index.tsx b/packages/base/src/page/System/components/BasicTitle/index.tsx new file mode 100644 index 000000000..73ae01a90 --- /dev/null +++ b/packages/base/src/page/System/components/BasicTitle/index.tsx @@ -0,0 +1,38 @@ +import { ReactNode } from 'react'; +import { Space, Row } from 'antd'; +import { BasicToolTips } from '@actiontech/shared'; +import { IconTipGray } from '@actiontech/shared/lib/Icon'; + +export type SystemBasicTitleProps = { + title: ReactNode | string; + titleTip?: ReactNode | string; + titleExtra?: ReactNode | string; + children: ReactNode | string; +}; + +const SystemBasicTitle = (props: SystemBasicTitleProps) => { + const { title, children, titleTip, titleExtra } = props; + + return ( +
+ + + {title} + {titleTip && ( + + + + )} + + {titleExtra} + + {children} +
+ ); +}; + +export default SystemBasicTitle; diff --git a/packages/base/src/page/System/index.tsx b/packages/base/src/page/System/index.tsx index e54790fad..911ecd88c 100644 --- a/packages/base/src/page/System/index.tsx +++ b/packages/base/src/page/System/index.tsx @@ -4,8 +4,8 @@ import { useTranslation } from 'react-i18next'; import { Row } from 'antd'; import { BasicSegmented, PageHeader } from '@actiontech/shared'; import { ModalName } from '../../data/ModalName'; -import { initSystemModalStatus } from '../../store/system'; import { SystemStyleWrapper } from './style'; +import { initSystemModalStatus } from '../../store/system'; // #if [sqle] import PushNotification from './PushNotification'; @@ -86,7 +86,7 @@ const System = () => { return options.find((item) => item.value === activeTabKey)?.components; }, [activeTabKey, options]); - // #if [sqle] + // #if [ee] useEffect(() => { dispatch( initSystemModalStatus({ From 34ed5f6b0a80c510680d58887ee8165b8d72a064 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Mon, 22 Jan 2024 18:25:16 +0800 Subject: [PATCH 02/27] upgrade tab pushNotification --- .../conponents/ConfigExtraButtons.tsx | 197 +++++++++ .../LarkSetting/conponents/ConfigField.tsx | 39 ++ .../LarkSetting/index copy.tsx | 395 +++++++++++++++++ .../PushNotification/LarkSetting/index.tsx | 255 +---------- .../components/ConfigExtraButtons.tsx | 134 ++++++ .../SMTPSetting/components/ConfigField.tsx | 109 +++++ .../PushNotification/SMTPSetting/index.tsx | 400 +++++------------- .../components/ConfigExtraButtons.tsx | 86 ++++ .../WebhookSetting/components/ConfigField.tsx | 55 +++ .../PushNotification/WebhookSetting/index.tsx | 157 ++----- .../Wechat/components/ConfigExtraButtons.tsx | 126 ++++++ .../Wechat/components/ConfigField.tsx | 64 +++ .../System/PushNotification/Wechat/index.tsx | 218 ++-------- .../page/System/PushNotification/index.tsx | 3 +- .../components/ConfigModifyBtn/index.tsx | 3 +- .../ConfigSubmitButtonField/index.tsx | 38 ++ .../System/components/ConfigTestBtn/index.tsx | 2 +- .../src/page/System/hooks/useConfigRender.tsx | 1 + packages/base/src/page/System/index.tsx | 3 +- 19 files changed, 1426 insertions(+), 859 deletions(-) create mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.tsx create mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.tsx create mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/index copy.tsx create mode 100644 packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx create mode 100644 packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.tsx create mode 100644 packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.tsx create mode 100644 packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.tsx create mode 100644 packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.tsx create mode 100644 packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.tsx create mode 100644 packages/base/src/page/System/components/ConfigSubmitButtonField/index.tsx diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.tsx new file mode 100644 index 000000000..9da13b4e2 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.tsx @@ -0,0 +1,197 @@ +import { useTranslation } from 'react-i18next'; + +import { useRef, useState } from 'react'; +import { Form, message, Radio, RadioGroupProps, Space } from 'antd'; +import { useForm } from 'antd/es/form/Form'; +import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; +import { + FormItemLabel, + FormItemNoLabel +} from '@actiontech/shared/lib/components/FormCom'; +import { BasicInput, EmptyBox } from '@actiontech/shared'; +import { phoneRule } from '@actiontech/shared/lib/utils/FormRule'; + +import ConfigTestBtn from '../../../components/ConfigTestBtn'; +import ConfigTestPopoverForm from '../../../components/ConfigTestPopoverForm'; +import ConfigModifyBtn from '../../../components/ConfigModifyBtn'; + +import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; +import { TestFormFields } from '../index.type'; +import { TestFeishuConfigurationAccountTypeEnum } from '@actiontech/shared/lib/api/base/service/common.enum'; + +interface ConfigExtraButtonsProps { + enabled: string | boolean; + isConfigClosed: boolean; + extraButtonsVisible: boolean; + handleClickModify: () => void; +} + +const ConfigExtraButtons = ({ + enabled, + isConfigClosed, + extraButtonsVisible, + handleClickModify +}: ConfigExtraButtonsProps) => { + const { t } = useTranslation(); + const [messageApi, messageContextHolder] = message.useMessage(); + + const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); + const [testForm] = useForm(); + const [receiveType, setReceiveType] = + useState( + TestFeishuConfigurationAccountTypeEnum.email + ); + + const testing = useRef(false); + const testLarkConfiguration = async () => { + if (testing.current) { + return; + } + const values = await testForm.validateFields(); + testing.current = true; + toggleTestPopoverVisible(false); + const hide = messageApi.loading(t('dmsSystem.lark.testing'), 0); + dms + .TestFeishuConfiguration({ + test_feishu_configuration: { + account: + receiveType === TestFeishuConfigurationAccountTypeEnum.email + ? values.receiveEmail + : values.receivePhone, + account_type: values.receiveType + } + }) + .then((res) => { + if (res.data.code === ResponseCode.SUCCESS) { + const resData = res.data?.data; + if (resData?.is_message_sent_normally) { + messageApi.success(t('dmsSystem.lark.testSuccess')); + } else { + messageApi.error( + resData?.error_message ?? t('common.unknownError') + ); + } + } + }) + .finally(() => { + hide(); + testing.current = false; + testForm.resetFields(); + setReceiveType(TestFeishuConfigurationAccountTypeEnum.email); + }); + }; + + const onTestPopoverOpen = (open: boolean) => { + if (!enabled) { + return; + } + if (!open) { + testForm.resetFields(); + setReceiveType(TestFeishuConfigurationAccountTypeEnum.email); + } + toggleTestPopoverVisible(open); + }; + + const handleChangeReceiveType: RadioGroupProps['onChange'] = (e) => { + const receiveType = e.target.value; + setReceiveType(receiveType); + + if (receiveType === TestFeishuConfigurationAccountTypeEnum.email) { + testForm.resetFields(['receivePhone']); + } else { + testForm.resetFields(['receiveEmail']); + } + }; + return ( + <> + {messageContextHolder} + + + ); +}; + +export default ConfigExtraButtons; diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.tsx new file mode 100644 index 000000000..ae03716e5 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.tsx @@ -0,0 +1,39 @@ +import { useTranslation } from 'react-i18next'; + +import { FormItemLabel } from '@actiontech/shared/lib/components/FormCom'; +import { BasicInput } from '@actiontech/shared'; + +const ConfigField = () => { + const { t } = useTranslation(); + + return ( + <> + + + + + + + + ); +}; + +export default ConfigField; diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/index copy.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/index copy.tsx new file mode 100644 index 000000000..b6d714d35 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/LarkSetting/index copy.tsx @@ -0,0 +1,395 @@ +import { useBoolean, useRequest } from 'ahooks'; +import { + Form, + message, + Radio, + RadioGroupProps, + Space, + Spin, + Typography +} from 'antd'; +import { useForm } from 'antd/es/form/Form'; +import { useCallback, useMemo, useRef, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { FormFields, TestFormFields } from './index.type'; +import { BasicButton, BasicInput, EmptyBox } from '@actiontech/shared'; +import { phoneRule } from '@actiontech/shared/lib/utils/FormRule'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; +import { TestFeishuConfigurationAccountTypeEnum } from '@actiontech/shared/lib/api/base/service/common.enum'; +import useConfigSwitch from '../../hooks/useConfigSwitch'; +import useConfigRender, { + ReadOnlyConfigColumnsType +} from '../../hooks/useConfigRender'; +import ConfigTestBtn from '../../components/ConfigTestBtn'; +import ConfigTestPopoverForm from '../../components/ConfigTestPopoverForm'; +import ConfigModifyBtn from '../../components/ConfigModifyBtn'; +import ConfigSwitch from '../../components/ConfigSwitch'; +import { + FormItemLabel, + FormItemNoLabel +} from '@actiontech/shared/lib/components/FormCom'; +import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; +import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { IFeishuConfigurationResData } from '@actiontech/shared/lib/api/base/service/common'; +import { switchFieldName } from './index.data'; + +const LarkSetting: React.FC = () => { + const { t } = useTranslation(); + const [messageApi, messageContextHolder] = message.useMessage(); + + const { + form, + renderConfigForm, + startModify, + modifyFinish, + modifyFlag, + extraButtonsVisible, + enabled + } = useConfigRender({ + switchFieldName, + switchFieldLabel: t('dmsSystem.lark.enable') + }); + + const [submitLoading, { setTrue: startSubmit, setFalse: submitFinish }] = + useBoolean(); + + const { + data: larkInfo, + loading, + refresh: refreshLarkInfo + } = useRequest( + () => dms.GetFeishuConfiguration().then((res) => res.data?.data ?? {}), + { + onSuccess(res) { + if (res) { + form.setFieldsValue({ + enabled: !!res.is_feishu_notification_enabled + }); + } + } + } + ); + const isConfigClosed = useMemo(() => { + return !larkInfo?.is_feishu_notification_enabled; + }, [larkInfo]); + + const setFormDefaultValue = useCallback(() => { + form.setFieldsValue({ + appKey: larkInfo?.app_id, + appSecret: undefined + }); + }, [form, larkInfo]); + + const handleClickModify = () => { + setFormDefaultValue(); + startModify(); + }; + const handleClickCancel = () => { + if (isConfigClosed) form.setFieldsValue({ [switchFieldName]: false }); + setFormDefaultValue(); + modifyFinish(); + }; + const handleToggleSwitch = (open: boolean) => { + form.setFieldValue(switchFieldName, open); + }; + + const submitLarkConfig = (values: FormFields) => { + startSubmit(); + dms + .UpdateFeishuConfiguration({ + update_feishu_configuration: { + is_feishu_notification_enabled: values.enabled, + app_id: values.appKey, + app_secret: values.appSecret + } + }) + .then((res) => { + if (res.data.code === ResponseCode.SUCCESS) { + modifyFinish(); + refreshLarkInfo(); + form.resetFields(); + } + }) + .finally(() => { + submitFinish(); + }); + }; + + const switchOpen = Form.useWatch(switchFieldName, form); + + const { + configSwitchPopoverVisible, + onConfigSwitchPopoverOpen, + onConfigSwitchPopoverConfirm, + onConfigSwitchChange + } = useConfigSwitch({ + isConfigClosed, + switchOpen, + modifyFlag, + startSubmit, + submitFinish, + handleClickModify, + handleUpdateConfig: () => + dms.UpdateFeishuConfiguration({ + update_feishu_configuration: { + ...larkInfo, + is_feishu_notification_enabled: false + } + }), + handleClickCancel, + refreshConfig: refreshLarkInfo, + handleToggleSwitch + }); + + const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); + const [testForm] = useForm(); + const [receiveType, setReceiveType] = + useState( + TestFeishuConfigurationAccountTypeEnum.email + ); + const testing = useRef(false); + const testLarkConfiguration = async () => { + if (testing.current) { + return; + } + const values = await testForm.validateFields(); + testing.current = true; + toggleTestPopoverVisible(false); + const hide = messageApi.loading(t('dmsSystem.lark.testing'), 0); + dms + .TestFeishuConfiguration({ + test_feishu_configuration: { + account: + receiveType === TestFeishuConfigurationAccountTypeEnum.email + ? values.receiveEmail + : values.receivePhone, + account_type: values.receiveType + } + }) + .then((res) => { + if (res.data.code === ResponseCode.SUCCESS) { + const resData = res.data?.data; + if (resData?.is_message_sent_normally) { + messageApi.success(t('dmsSystem.lark.testSuccess')); + } else { + messageApi.error( + resData?.error_message ?? t('common.unknownError') + ); + } + } + }) + .finally(() => { + hide(); + testing.current = false; + testForm.resetFields(); + setReceiveType(TestFeishuConfigurationAccountTypeEnum.email); + }); + }; + const onTestPopoverOpen = (open: boolean) => { + if (!enabled) { + return; + } + if (!open) { + testForm.resetFields(); + setReceiveType(TestFeishuConfigurationAccountTypeEnum.email); + } + toggleTestPopoverVisible(open); + }; + + const handleChangeReceiveType: RadioGroupProps['onChange'] = (e) => { + const receiveType = e.target.value; + setReceiveType(receiveType); + + if (receiveType === TestFeishuConfigurationAccountTypeEnum.email) { + testForm.resetFields(['receivePhone']); + } else { + testForm.resetFields(['receiveEmail']); + } + }; + + const readonlyColumnsConfig: ReadOnlyConfigColumnsType = + useMemo(() => { + return [ + { + label: 'App ID', + span: 3, + dataIndex: 'app_id', + hidden: !larkInfo?.is_feishu_notification_enabled, + render: (val) => ( + {val || '--'} + ) + } + ]; + }, [larkInfo]); + + return ( +
+ + {messageContextHolder} + + {renderConfigForm({ + data: larkInfo ?? {}, + columns: readonlyColumnsConfig, + configExtraButtons: ( + + ), + configSwitchNode: ( + + ), + configField: ( + <> + + + + + + + + ), + submitButtonField: ( + + + + {t('common.cancel')} + + + {t('common.submit')} + + + + ), + submit: submitLarkConfig + })} + +
+ ); +}; + +export default LarkSetting; diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/index.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/index.tsx index b6d714d35..84be73399 100644 --- a/packages/base/src/page/System/PushNotification/LarkSetting/index.tsx +++ b/packages/base/src/page/System/PushNotification/LarkSetting/index.tsx @@ -1,41 +1,26 @@ -import { useBoolean, useRequest } from 'ahooks'; -import { - Form, - message, - Radio, - RadioGroupProps, - Space, - Spin, - Typography -} from 'antd'; -import { useForm } from 'antd/es/form/Form'; -import { useCallback, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { FormFields, TestFormFields } from './index.type'; -import { BasicButton, BasicInput, EmptyBox } from '@actiontech/shared'; -import { phoneRule } from '@actiontech/shared/lib/utils/FormRule'; -import { ResponseCode } from '@actiontech/shared/lib/enum'; -import { TestFeishuConfigurationAccountTypeEnum } from '@actiontech/shared/lib/api/base/service/common.enum'; +import { useBoolean, useRequest } from 'ahooks'; +import { useCallback, useMemo } from 'react'; +import { Form, Spin, Typography } from 'antd'; +import { FormFields } from './index.type'; + import useConfigSwitch from '../../hooks/useConfigSwitch'; import useConfigRender, { ReadOnlyConfigColumnsType } from '../../hooks/useConfigRender'; -import ConfigTestBtn from '../../components/ConfigTestBtn'; -import ConfigTestPopoverForm from '../../components/ConfigTestPopoverForm'; -import ConfigModifyBtn from '../../components/ConfigModifyBtn'; import ConfigSwitch from '../../components/ConfigSwitch'; -import { - FormItemLabel, - FormItemNoLabel -} from '@actiontech/shared/lib/components/FormCom'; -import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; + +import ConfigSubmitButtonField from '../../components/ConfigSubmitButtonField'; +import ConfigExtraButtons from './conponents/ConfigExtraButtons'; +import ConfigField from './conponents/ConfigField'; + import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; import { IFeishuConfigurationResData } from '@actiontech/shared/lib/api/base/service/common'; import { switchFieldName } from './index.data'; const LarkSetting: React.FC = () => { const { t } = useTranslation(); - const [messageApi, messageContextHolder] = message.useMessage(); const { form, @@ -141,72 +126,6 @@ const LarkSetting: React.FC = () => { handleToggleSwitch }); - const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); - const [testForm] = useForm(); - const [receiveType, setReceiveType] = - useState( - TestFeishuConfigurationAccountTypeEnum.email - ); - const testing = useRef(false); - const testLarkConfiguration = async () => { - if (testing.current) { - return; - } - const values = await testForm.validateFields(); - testing.current = true; - toggleTestPopoverVisible(false); - const hide = messageApi.loading(t('dmsSystem.lark.testing'), 0); - dms - .TestFeishuConfiguration({ - test_feishu_configuration: { - account: - receiveType === TestFeishuConfigurationAccountTypeEnum.email - ? values.receiveEmail - : values.receivePhone, - account_type: values.receiveType - } - }) - .then((res) => { - if (res.data.code === ResponseCode.SUCCESS) { - const resData = res.data?.data; - if (resData?.is_message_sent_normally) { - messageApi.success(t('dmsSystem.lark.testSuccess')); - } else { - messageApi.error( - resData?.error_message ?? t('common.unknownError') - ); - } - } - }) - .finally(() => { - hide(); - testing.current = false; - testForm.resetFields(); - setReceiveType(TestFeishuConfigurationAccountTypeEnum.email); - }); - }; - const onTestPopoverOpen = (open: boolean) => { - if (!enabled) { - return; - } - if (!open) { - testForm.resetFields(); - setReceiveType(TestFeishuConfigurationAccountTypeEnum.email); - } - toggleTestPopoverVisible(open); - }; - - const handleChangeReceiveType: RadioGroupProps['onChange'] = (e) => { - const receiveType = e.target.value; - setReceiveType(receiveType); - - if (receiveType === TestFeishuConfigurationAccountTypeEnum.email) { - testForm.resetFields(['receivePhone']); - } else { - testForm.resetFields(['receiveEmail']); - } - }; - const readonlyColumnsConfig: ReadOnlyConfigColumnsType = useMemo(() => { return [ @@ -225,106 +144,16 @@ const LarkSetting: React.FC = () => { return (
- {messageContextHolder} - {renderConfigForm({ data: larkInfo ?? {}, columns: readonlyColumnsConfig, configExtraButtons: ( - + ), configSwitchNode: ( { onSwitchPopoverOpen={onConfigSwitchPopoverOpen} /> ), - configField: ( - <> - - - - - - - - ), + configField: , submitButtonField: ( - - - - {t('common.cancel')} - - - {t('common.submit')} - - - + ), submit: submitLarkConfig })} diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx new file mode 100644 index 000000000..57651a481 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx @@ -0,0 +1,134 @@ +import { Form, message, Space } from 'antd'; +import { useTranslation } from 'react-i18next'; +import { useMemo, useRef, useState } from 'react'; + +import { useForm } from 'antd/es/form/Form'; +import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; +import { FormItemLabel } from '@actiontech/shared/lib/components/FormCom'; +import { BasicInput } from '@actiontech/shared'; +import ConfigTestBtn from '../../../components/ConfigTestBtn'; +import ConfigTestPopoverForm from '../../../components/ConfigTestPopoverForm'; +import ConfigModifyBtn from '../../../components/ConfigModifyBtn'; + +import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; +import { ISMTPConfigurationResData } from '@actiontech/shared/lib/api/base/service/common'; + +type typeConfigExtraButtons = { + smtpInfo: ISMTPConfigurationResData | undefined; + enabled: string | number | boolean; + extraButtonsVisible: boolean; + handleClickModify: () => void; +}; + +const ConfigExtraButtons = ({ + smtpInfo, + enabled, + extraButtonsVisible, + handleClickModify +}: typeConfigExtraButtons) => { + const { t } = useTranslation(); + + const [messageApi, messageContextHolder] = message.useMessage(); + const [testForm] = useForm<{ receiveEmail?: string }>(); + + const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); + + const isConfigClosed = useMemo(() => { + return !smtpInfo?.enable_smtp_notify; + }, [smtpInfo]); + + const testTing = useRef(false); + + const onTestPopoverOpen = (open: boolean) => { + if (!enabled) { + return; + } + if (!open) { + testForm.resetFields(); + } + toggleTestPopoverVisible(open); + }; + + const test = async () => { + if (testTing.current) { + return; + } + const values = await testForm.validateFields(); + testTing.current = true; + toggleTestPopoverVisible(false); + const hide = messageApi.loading( + t('dmsSystem.smtp.testing', { + email: values.receiveEmail + }), + 0 + ); + dms + .TestSMTPConfiguration({ + test_smtp_configuration: { + recipient_addr: values.receiveEmail + } + }) + .then((res) => { + if (res.data.code === ResponseCode.SUCCESS) { + const resData = res.data?.data; + if (resData?.is_smtp_send_normal) { + messageApi.success( + t('dmsSystem.smtp.testSuccess', { email: values.receiveEmail }) + ); + testForm.resetFields(); + } else { + messageApi.error( + resData?.send_error_message ?? t('common.unknownError') + ); + } + } + }) + .finally(() => { + hide(); + testTing.current = false; + testForm.resetFields(); + }); + }; + + return ( + <> + {messageContextHolder} + + + ); +}; + +export default ConfigExtraButtons; diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.tsx new file mode 100644 index 000000000..6004d9a51 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.tsx @@ -0,0 +1,109 @@ +import { useTranslation } from 'react-i18next'; +import { BasicInput, BasicSwitch } from '@actiontech/shared'; +import { + CustomLabelContent, + FormItemLabel +} from '@actiontech/shared/lib/components/FormCom'; +import { validatorPort } from '@actiontech/shared/lib/utils/FormRule'; + +const ConfigField = () => { + const { t } = useTranslation(); + + return ( + <> + + } + name="isSkipVerify" + valuePropName="checked" + > + + + + + + + + + + + + + + + + ({ + validator(_, value) { + if (!value || getFieldValue('password') === value) { + return Promise.resolve(); + } + return Promise.reject( + new Error(t('common.form.rule.passwordNotMatch')) + ); + } + }) + ]} + > + + + + ); +}; + +export default ConfigField; diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/index.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/index.tsx index 1e835e8af..c10cc957d 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/index.tsx +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/index.tsx @@ -1,39 +1,30 @@ -import { useCallback, useMemo, useRef, useState } from 'react'; -import { useBoolean, useRequest } from 'ahooks'; -import { Form, message, Space, Spin } from 'antd'; -import { useForm } from 'antd/es/form/Form'; import { useTranslation } from 'react-i18next'; -import { ResponseCode } from '@actiontech/shared/lib/enum'; -import { SMTPSettingFormFields } from './index.type'; -import { - BasicButton, - BasicInput, - BasicSwitch, - BasicToolTips -} from '@actiontech/shared'; -import { IconTipGray } from '@actiontech/shared/lib/Icon'; -import { validatorPort } from '@actiontech/shared/lib/utils/FormRule'; -import { - CustomLabelContent, - FormItemLabel, - FormItemNoLabel -} from '@actiontech/shared/lib/components/FormCom'; -import { ISMTPConfigurationResData } from '@actiontech/shared/lib/api/base/service/common'; -import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { useCallback, useMemo } from 'react'; +import { useBoolean, useRequest } from 'ahooks'; +import { Form, Spin } from 'antd'; + import useConfigRender, { ReadOnlyConfigColumnsType } from '../../hooks/useConfigRender'; +import { SMTPSettingFormFields } from './index.type'; import { switchFieldName } from './index.data'; -import ConfigModifyBtn from '../../components/ConfigModifyBtn'; -import ConfigTestBtn from '../../components/ConfigTestBtn'; -import ConfigSwitch from '../../components/ConfigSwitch'; + +import { ISMTPConfigurationResData } from '@actiontech/shared/lib/api/base/service/common'; +import { BasicToolTips } from '@actiontech/shared'; +import { IconTipGray } from '@actiontech/shared/lib/Icon'; + import useConfigSwitch from '../../hooks/useConfigSwitch'; -import ConfigTestPopoverForm from '../../components/ConfigTestPopoverForm'; -import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; +import ConfigSwitch from '../../components/ConfigSwitch'; + +import ConfigField from './components/ConfigField'; +import ConfigExtraButtons from './components/ConfigExtraButtons'; + +import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; +import ConfigSubmitButtonField from '../../components/ConfigSubmitButtonField'; const SMTPSetting = () => { const { t } = useTranslation(); - const [messageApi, messageContextHolder] = message.useMessage(); const { form, @@ -65,6 +56,74 @@ const SMTPSetting = () => { } ); + const switchOpen = Form.useWatch(switchFieldName, form); + + const readonlyColumnsConfig: ReadOnlyConfigColumnsType = + useMemo(() => { + return [ + { + label: t('dmsSystem.smtp.host'), + span: 3, + dataIndex: 'smtp_host', + hidden: !smtpInfo?.enable_smtp_notify + }, + { + label: t('dmsSystem.smtp.port'), + span: 3, + dataIndex: 'smtp_port', + hidden: !smtpInfo?.enable_smtp_notify + }, + { + label: t('dmsSystem.smtp.username'), + span: 3, + dataIndex: 'smtp_username', + hidden: !smtpInfo?.enable_smtp_notify + }, + { + label: ( + } + > + {t('dmsSystem.smtp.isSkipVerify')} + + ), + span: 3, + dataIndex: 'is_skip_verify', + hidden: !smtpInfo?.enable_smtp_notify, + render: (val) => <>{!!val ? t('common.true') : t('common.false')} + } + ]; + }, [t, smtpInfo]); + + const [submitLoading, { setTrue: startSubmit, setFalse: submitFinish }] = + useBoolean(); + + const submit = (values: SMTPSettingFormFields) => { + startSubmit(); + dms + .UpdateSMTPConfiguration({ + smtp_configuration: { + enable_smtp_notify: values.enable, + is_skip_verify: values.isSkipVerify, + smtp_host: values.host, + smtp_password: values.password, + smtp_port: `${values.port}`, + smtp_username: values.username + } + }) + .then((res) => { + if (res.data.code === ResponseCode.SUCCESS) { + modifyFinish(); + refreshSMTPInfo(); + form.resetFields(); + } + }) + .finally(() => { + submitFinish(); + }); + }; + const isConfigClosed = useMemo(() => { return !smtpInfo?.enable_smtp_notify; }, [smtpInfo]); @@ -86,6 +145,7 @@ const SMTPSetting = () => { setFormDefaultValue(); startModify(); }, [startModify, setFormDefaultValue]); + const handleClickCancel = () => { if (isConfigClosed) form.setFieldValue(switchFieldName, false); setFormDefaultValue(); @@ -96,35 +156,6 @@ const SMTPSetting = () => { form.setFieldValue(switchFieldName, open); }; - const [submitLoading, { setTrue: startSubmit, setFalse: submitFinish }] = - useBoolean(); - const submit = (values: SMTPSettingFormFields) => { - startSubmit(); - dms - .UpdateSMTPConfiguration({ - smtp_configuration: { - enable_smtp_notify: values.enable, - is_skip_verify: values.isSkipVerify, - smtp_host: values.host, - smtp_password: values.password, - smtp_port: `${values.port}`, - smtp_username: values.username - } - }) - .then((res) => { - if (res.data.code === ResponseCode.SUCCESS) { - modifyFinish(); - refreshSMTPInfo(); - form.resetFields(); - } - }) - .finally(() => { - submitFinish(); - }); - }; - - const switchOpen = Form.useWatch(switchFieldName, form); - const { configSwitchPopoverVisible, onConfigSwitchPopoverOpen, @@ -149,143 +180,19 @@ const SMTPSetting = () => { handleToggleSwitch }); - const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); - const [testForm] = useForm<{ receiveEmail?: string }>(); - const testTing = useRef(false); - const test = async () => { - if (testTing.current) { - return; - } - const values = await testForm.validateFields(); - testTing.current = true; - toggleTestPopoverVisible(false); - const hide = messageApi.loading( - t('dmsSystem.smtp.testing', { - email: values.receiveEmail - }), - 0 - ); - dms - .TestSMTPConfiguration({ - test_smtp_configuration: { - recipient_addr: values.receiveEmail - } - }) - .then((res) => { - if (res.data.code === ResponseCode.SUCCESS) { - const resData = res.data?.data; - if (resData?.is_smtp_send_normal) { - messageApi.success( - t('dmsSystem.smtp.testSuccess', { email: values.receiveEmail }) - ); - testForm.resetFields(); - } else { - messageApi.error( - resData?.send_error_message ?? t('common.unknownError') - ); - } - } - }) - .finally(() => { - hide(); - testTing.current = false; - testForm.resetFields(); - }); - }; - const onTestPopoverOpen = (open: boolean) => { - if (!enabled) { - return; - } - if (!open) { - testForm.resetFields(); - } - toggleTestPopoverVisible(open); - }; - - const readonlyColumnsConfig: ReadOnlyConfigColumnsType = - useMemo(() => { - return [ - { - label: t('dmsSystem.smtp.host'), - span: 3, - dataIndex: 'smtp_host', - hidden: !smtpInfo?.enable_smtp_notify - }, - { - label: t('dmsSystem.smtp.port'), - span: 3, - dataIndex: 'smtp_port', - hidden: !smtpInfo?.enable_smtp_notify - }, - { - label: t('dmsSystem.smtp.username'), - span: 3, - dataIndex: 'smtp_username', - hidden: !smtpInfo?.enable_smtp_notify - }, - { - label: ( - } - > - {t('dmsSystem.smtp.isSkipVerify')} - - ), - span: 3, - dataIndex: 'is_skip_verify', - hidden: !smtpInfo?.enable_smtp_notify, - render: (val) => <>{!!val ? t('common.true') : t('common.false')} - } - ]; - }, [t, smtpInfo]); - return (
- {messageContextHolder} - {renderConfigForm({ data: smtpInfo ?? {}, columns: readonlyColumnsConfig, configExtraButtons: ( - + ), configSwitchNode: ( { onSwitchPopoverOpen={onConfigSwitchPopoverOpen} /> ), - configField: ( - <> - - } - name="isSkipVerify" - valuePropName="checked" - > - - - - - - - - - - - - - - - - ({ - validator(_, value) { - if (!value || getFieldValue('password') === value) { - return Promise.resolve(); - } - return Promise.reject( - new Error(t('common.form.rule.passwordNotMatch')) - ); - } - }) - ]} - > - - - - ), + configField: , submitButtonField: ( - - - - {t('common.cancel')} - - - {t('common.submit')} - - - + ), submit })} diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.tsx new file mode 100644 index 000000000..63d9c6c9b --- /dev/null +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.tsx @@ -0,0 +1,86 @@ +import { useTranslation } from 'react-i18next'; +import { useRef } from 'react'; +import { message, Space } from 'antd'; + +import ConfigModifyBtn from '../../../components/ConfigModifyBtn'; +import { BasicButton, BasicToolTips } from '@actiontech/shared'; +import { IconTest } from '../../../../../icon/system'; + +import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; + +interface ConfigExtraButtonsProps { + enabled: string | number | boolean; + isConfigClosed: boolean; + extraButtonsVisible: boolean; + handleClickModify: () => void; + msgUrl: string; +} + +const ConfigExtraButtons = ({ + enabled, + isConfigClosed, + extraButtonsVisible, + handleClickModify, + msgUrl +}: ConfigExtraButtonsProps) => { + const { t } = useTranslation(); + const [messageApi, messageContextHolder] = message.useMessage(); + + const testTing = useRef(false); + const test = () => { + if (testTing.current) { + return; + } + + testTing.current = true; + const hide = messageApi.loading( + t('dmsSystem.webhook.testing', { url: msgUrl }), + 0 + ); + dms + .TestWebHookConfiguration() + .then((res) => { + if (res.data.code === ResponseCode.SUCCESS) { + const resData = res.data?.data; + + if (resData?.is_message_sent_normally) { + messageApi.success(t('dmsSystem.webhook.testSuccess')); + } else { + messageApi.error( + resData?.send_error_message ?? t('common.unknownError') + ); + } + } + }) + .finally(() => { + hide(); + testTing.current = false; + }); + }; + + return ( + <> + {messageContextHolder} + + + ); +}; + +export default ConfigExtraButtons; diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.tsx new file mode 100644 index 000000000..1b835d447 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.tsx @@ -0,0 +1,55 @@ +import { useTranslation } from 'react-i18next'; + +import { BasicInput, BasicInputNumber } from '@actiontech/shared'; +import { FormItemLabel } from '@actiontech/shared/lib/components/FormCom'; + +const ConfigField = () => { + const { t } = useTranslation(); + + return ( + <> + + + + + + + + + + + + + + ); +}; + +export default ConfigField; diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/index.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/index.tsx index cdabea43d..769028ffa 100644 --- a/packages/base/src/page/System/PushNotification/WebhookSetting/index.tsx +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/index.tsx @@ -1,34 +1,27 @@ -import { useBoolean, useRequest } from 'ahooks'; -import { Form, message, Space, Spin } from 'antd'; -import { useCallback, useMemo, useRef } from 'react'; import { useTranslation } from 'react-i18next'; +import { useBoolean, useRequest } from 'ahooks'; +import { useCallback, useMemo } from 'react'; +import { Form, Spin } from 'antd'; import { Link } from 'react-router-dom'; -import { ResponseCode } from '@actiontech/shared/lib/enum'; -import { WebhookFormFields } from './index.type'; -import dms from '@actiontech/shared/lib/api/base/service/dms'; -import { IWebHookConfigurationData } from '@actiontech/shared/lib/api/base/service/common'; + import { DEFAULT_CONSTANT, switchFieldName } from './index.data'; import useConfigRender, { ReadOnlyConfigColumnsType } from '../../hooks/useConfigRender'; import useConfigSwitch from '../../hooks/useConfigSwitch'; + import ConfigSwitch from '../../components/ConfigSwitch'; -import ConfigModifyBtn from '../../components/ConfigModifyBtn'; -import { - BasicButton, - BasicInput, - BasicInputNumber, - BasicToolTips -} from '@actiontech/shared'; -import { IconTest } from '../../../../icon/system'; -import { - FormItemLabel, - FormItemNoLabel -} from '@actiontech/shared/lib/components/FormCom'; +import ConfigExtraButtons from './components/ConfigExtraButtons'; +import ConfigField from './components/ConfigField'; +import ConfigSubmitButtonField from '../../components/ConfigSubmitButtonField'; + +import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { IWebHookConfigurationData } from '@actiontech/shared/lib/api/base/service/common'; +import { WebhookFormFields } from './index.type'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; const WebHook: React.FC = () => { const { t } = useTranslation(); - const [messageApi, messageContextHolder] = message.useMessage(); const { form, @@ -157,38 +150,6 @@ const WebHook: React.FC = () => { handleToggleSwitch }); - const testTing = useRef(false); - const test = () => { - if (testTing.current) { - return; - } - - testTing.current = true; - const hide = messageApi.loading( - t('dmsSystem.webhook.testing', { url: webhookConfig?.url ?? '' }), - 0 - ); - dms - .TestWebHookConfiguration() - .then((res) => { - if (res.data.code === ResponseCode.SUCCESS) { - const resData = res.data?.data; - - if (resData?.is_message_sent_normally) { - messageApi.success(t('dmsSystem.webhook.testSuccess')); - } else { - messageApi.error( - resData?.send_error_message ?? t('common.unknownError') - ); - } - } - }) - .finally(() => { - hide(); - testTing.current = false; - }); - }; - const readonlyColumnsConfig: ReadOnlyConfigColumnsType = useMemo(() => { return [ @@ -204,29 +165,17 @@ const WebHook: React.FC = () => { return (
- {messageContextHolder} - {renderConfigForm({ data: webhookConfig ?? {}, columns: readonlyColumnsConfig, configExtraButtons: ( - + ), configSwitchNode: ( { onSwitchPopoverOpen={onConfigSwitchPopoverOpen} /> ), - configField: ( - <> - - - - - - - - - - - - - - ), + configField: , submitButtonField: ( - - - - {t('common.cancel')} - - - {t('common.submit')} - - - + ), submit })} diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.tsx new file mode 100644 index 000000000..825e405ad --- /dev/null +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.tsx @@ -0,0 +1,126 @@ +import { useTranslation } from 'react-i18next'; +import { useRef, useState } from 'react'; + +import { Form, message, Space } from 'antd'; +import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; +import { + CustomLabelContent, + FormItemLabel +} from '@actiontech/shared/lib/components/FormCom'; +import ConfigModifyBtn from '../../../components/ConfigModifyBtn'; +import ConfigTestBtn from '../../../components/ConfigTestBtn'; +import ConfigTestPopoverForm from '../../../components/ConfigTestPopoverForm'; +import { BasicInput } from '@actiontech/shared'; + +import dms from '@actiontech/shared/lib/api/base/service/dms'; + +type typeConfigExtraButtons = { + extraButtonsVisible: boolean; + isConfigClosed: boolean; + enabled: string | boolean | undefined; + handleClickModify: () => void; +}; + +const ConfigExtraButtons = ({ + extraButtonsVisible, + isConfigClosed, + enabled, + handleClickModify +}: typeConfigExtraButtons) => { + const { t } = useTranslation(); + const [messageApi, messageContextHolder] = message.useMessage(); + const [testForm] = Form.useForm<{ receiveId?: string }>(); + + const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); + const testTing = useRef(false); + const test = async () => { + if (testTing.current) { + return; + } + const values = await testForm.validateFields(); + + testTing.current = true; + toggleTestPopoverVisible(false); + const hide = messageApi.loading( + t('dmsSystem.wechat.testing', { id: values.receiveId }), + 0 + ); + dms + .TestWeChatConfiguration({ + test_wechat_configuration: { + recipient_id: values.receiveId + } + }) + .then((res) => { + const resData = res.data?.data; + if (resData?.is_wechat_send_normal) { + messageApi.success(t('dmsSystem.wechat.testSuccess')); + } else { + messageApi.error( + resData?.send_error_message ?? t('common.unknownError') + ); + } + }) + .finally(() => { + hide(); + testTing.current = false; + testForm.resetFields(); + }); + }; + + const onTestPopoverOpen = (open: boolean) => { + if (!enabled) { + return; + } + if (!open) { + testForm.resetFields(); + } + toggleTestPopoverVisible(open); + }; + + return ( + <> + {messageContextHolder} + + + ); +}; + +export default ConfigExtraButtons; diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.tsx new file mode 100644 index 000000000..feed8607e --- /dev/null +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.tsx @@ -0,0 +1,64 @@ +import { useTranslation } from 'react-i18next'; + +import { BasicInput, BasicSwitch } from '@actiontech/shared'; +import { FormItemLabel } from '@actiontech/shared/lib/components/FormCom'; + +const ConfigField = () => { + const { t } = useTranslation(); + + return ( + <> + + + + + + + + + + + + + + + + + ); +}; + +export default ConfigField; diff --git a/packages/base/src/page/System/PushNotification/Wechat/index.tsx b/packages/base/src/page/System/PushNotification/Wechat/index.tsx index 6bbc27e9b..0ccb7297a 100644 --- a/packages/base/src/page/System/PushNotification/Wechat/index.tsx +++ b/packages/base/src/page/System/PushNotification/Wechat/index.tsx @@ -1,32 +1,27 @@ -import { useCallback, useMemo, useRef, useState } from 'react'; -import { useBoolean, useRequest } from 'ahooks'; -import { Form, message, Space, Spin } from 'antd'; import { useTranslation } from 'react-i18next'; -import { ResponseCode } from '@actiontech/shared/lib/enum'; -import { WechatFormFields } from './index.type'; +import { useCallback, useMemo } from 'react'; + +import { useBoolean, useRequest } from 'ahooks'; + +import { switchFieldName } from './index.data'; +import { Form, Spin } from 'antd'; +import ConfigSwitch from '../../components/ConfigSwitch'; +import useConfigSwitch from '../../hooks/useConfigSwitch'; import useConfigRender, { ReadOnlyConfigColumnsType } from '../../hooks/useConfigRender'; + +import ConfigExtraButtons from './components/ConfigExtraButtons'; +import ConfigField from './components/ConfigField'; +import ConfigSubmitButtonField from '../../components/ConfigSubmitButtonField'; + import dms from '@actiontech/shared/lib/api/base/service/dms'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; +import { WechatFormFields } from './index.type'; import { IWeChatConfigurationResData } from '@actiontech/shared/lib/api/base/service/common'; -import { BasicButton, BasicInput, BasicSwitch } from '@actiontech/shared'; -import { switchFieldName } from './index.data'; -import { - CustomLabelContent, - FormItemLabel, - FormItemNoLabel -} from '@actiontech/shared/lib/components/FormCom'; -import ConfigSwitch from '../../components/ConfigSwitch'; -import ConfigModifyBtn from '../../components/ConfigModifyBtn'; -import ConfigTestBtn from '../../components/ConfigTestBtn'; -import useConfigSwitch from '../../hooks/useConfigSwitch'; -import ConfigTestPopoverForm from '../../components/ConfigTestPopoverForm'; -import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; const Wechat = () => { const { t } = useTranslation(); - const [testForm] = Form.useForm<{ receiveId?: string }>(); - const [messageApi, messageContextHolder] = message.useMessage(); const { data: wechatConfig, @@ -58,10 +53,6 @@ const Wechat = () => { switchFieldLabel: t('dmsSystem.wechat.enable_wechat_notify') }); - const isConfigClosed = useMemo(() => { - return !wechatConfig?.enable_wechat_notify; - }, [wechatConfig]); - const [submitLoading, { setTrue: startSubmit, setFalse: submitFinish }] = useBoolean(); const submit = (values: WechatFormFields) => { @@ -105,6 +96,10 @@ const Wechat = () => { setFormDefaultValue(); startModify(); }; + const isConfigClosed = useMemo(() => { + return !wechatConfig?.enable_wechat_notify; + }, [wechatConfig]); + const handleClickCancel = () => { if (isConfigClosed) form.setFieldsValue({ [switchFieldName]: false }); setFormDefaultValue(); @@ -141,53 +136,6 @@ const Wechat = () => { handleToggleSwitch }); - const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); - const testTing = useRef(false); - const test = async () => { - if (testTing.current) { - return; - } - const values = await testForm.validateFields(); - - testTing.current = true; - toggleTestPopoverVisible(false); - const hide = messageApi.loading( - t('dmsSystem.wechat.testing', { id: values.receiveId }), - 0 - ); - dms - .TestWeChatConfiguration({ - test_wechat_configuration: { - recipient_id: values.receiveId - } - }) - .then((res) => { - const resData = res.data?.data; - if (resData?.is_wechat_send_normal) { - messageApi.success(t('dmsSystem.wechat.testSuccess')); - } else { - messageApi.error( - resData?.send_error_message ?? t('common.unknownError') - ); - } - }) - .finally(() => { - hide(); - testTing.current = false; - testForm.resetFields(); - }); - }; - - const onTestPopoverOpen = (open: boolean) => { - if (!enabled) { - return; - } - if (!open) { - testForm.resetFields(); - } - toggleTestPopoverVisible(open); - }; - const readonlyColumnsConfig: ReadOnlyConfigColumnsType = useMemo(() => { return [ @@ -222,53 +170,16 @@ const Wechat = () => { return (
- {messageContextHolder} {renderConfigForm({ data: wechatConfig ?? {}, columns: readonlyColumnsConfig, configExtraButtons: ( - + ), configSwitchNode: ( { onSwitchPopoverOpen={onConfigSwitchPopoverOpen} /> ), - configField: ( - <> - - - - - - - - - - - - - - - - - ), + configField: , submitButtonField: ( - - - - {t('common.cancel')} - - - {t('common.submit')} - - - + ), submit })} diff --git a/packages/base/src/page/System/PushNotification/index.tsx b/packages/base/src/page/System/PushNotification/index.tsx index 4858aaeb2..7104b943e 100644 --- a/packages/base/src/page/System/PushNotification/index.tsx +++ b/packages/base/src/page/System/PushNotification/index.tsx @@ -1,9 +1,10 @@ import { useTranslation } from 'react-i18next'; + +import SystemBasicTitle from '../components/BasicTitle'; import SMTPSetting from './SMTPSetting'; import Wechat from './Wechat'; import LarkSetting from './LarkSetting'; import WebHook from './WebhookSetting'; -import SystemBasicTitle from '../components/BasicTitle'; const PushNotification = () => { const { t } = useTranslation(); diff --git a/packages/base/src/page/System/components/ConfigModifyBtn/index.tsx b/packages/base/src/page/System/components/ConfigModifyBtn/index.tsx index dcfb9d609..f8aed8f7c 100644 --- a/packages/base/src/page/System/components/ConfigModifyBtn/index.tsx +++ b/packages/base/src/page/System/components/ConfigModifyBtn/index.tsx @@ -1,9 +1,10 @@ +import { useTranslation } from 'react-i18next'; import { BasicButton, BasicToolTips } from '@actiontech/shared'; import { IconModify } from '../../../../icon/system'; -import { useTranslation } from 'react-i18next'; const ConfigModifyBtn: React.FC<{ onClick: () => void }> = ({ onClick }) => { const { t } = useTranslation(); + return ( void; +} + +const ConfigSubmitButtonField = ({ + submitLoading, + handleClickCancel +}: ConfigSubmitButtonFieldProps) => { + const { t } = useTranslation(); + return ( + <> + + + + {t('common.cancel')} + + + {t('common.submit')} + + + + + ); +}; + +export default ConfigSubmitButtonField; diff --git a/packages/base/src/page/System/components/ConfigTestBtn/index.tsx b/packages/base/src/page/System/components/ConfigTestBtn/index.tsx index 6adea73a6..fc6c685b8 100644 --- a/packages/base/src/page/System/components/ConfigTestBtn/index.tsx +++ b/packages/base/src/page/System/components/ConfigTestBtn/index.tsx @@ -1,6 +1,6 @@ +import { useTranslation } from 'react-i18next'; import { MutableRefObject } from 'react'; import { Popover } from 'antd'; -import { useTranslation } from 'react-i18next'; import { BasicButton, BasicToolTips } from '@actiontech/shared'; import { IconTest } from '../../../../icon/system'; diff --git a/packages/base/src/page/System/hooks/useConfigRender.tsx b/packages/base/src/page/System/hooks/useConfigRender.tsx index aa7b739b6..b9a57d1d4 100644 --- a/packages/base/src/page/System/hooks/useConfigRender.tsx +++ b/packages/base/src/page/System/hooks/useConfigRender.tsx @@ -24,6 +24,7 @@ export function renderReadOnlyModeConfig( ) { const { data = {} as T, columns, modifyFlag } = params; const hasConfig = columns.some((column) => !column.hidden); + return ( !modifyFlag && hasConfig && ( diff --git a/packages/base/src/page/System/index.tsx b/packages/base/src/page/System/index.tsx index 911ecd88c..1115f6da5 100644 --- a/packages/base/src/page/System/index.tsx +++ b/packages/base/src/page/System/index.tsx @@ -3,9 +3,9 @@ import { useDispatch } from 'react-redux'; import { useTranslation } from 'react-i18next'; import { Row } from 'antd'; import { BasicSegmented, PageHeader } from '@actiontech/shared'; -import { ModalName } from '../../data/ModalName'; import { SystemStyleWrapper } from './style'; import { initSystemModalStatus } from '../../store/system'; +import { ModalName } from '../../data/ModalName'; // #if [sqle] import PushNotification from './PushNotification'; @@ -31,6 +31,7 @@ enum SystemSegmentedKeyEnum { const System = () => { const { t } = useTranslation(); + const dispatch = useDispatch(); const options = useMemo( From 1e79e90ecf2102c59af4f3cd5c9d1cf67866b179 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 13:53:32 +0800 Subject: [PATCH 03/27] upgrade processConnection --- .../components/ConfigExtraButtons.tsx | 71 +++++ .../components/ConfigField.tsx | 39 +++ .../DingTalkSetting/index.tsx | 120 ++------ .../components/ConfigExtraButtons.tsx | 191 +++++++++++++ .../components/ConfigField.tsx | 37 +++ .../LarkAuditSetting/index.tsx | 262 ++---------------- 6 files changed, 386 insertions(+), 334 deletions(-) create mode 100644 packages/base/src/page/System/ProcessConnection/DingTalkSetting/components/ConfigExtraButtons.tsx create mode 100644 packages/base/src/page/System/ProcessConnection/DingTalkSetting/components/ConfigField.tsx create mode 100644 packages/base/src/page/System/ProcessConnection/LarkAuditSetting/components/ConfigExtraButtons.tsx create mode 100644 packages/base/src/page/System/ProcessConnection/LarkAuditSetting/components/ConfigField.tsx diff --git a/packages/base/src/page/System/ProcessConnection/DingTalkSetting/components/ConfigExtraButtons.tsx b/packages/base/src/page/System/ProcessConnection/DingTalkSetting/components/ConfigExtraButtons.tsx new file mode 100644 index 000000000..493e092b3 --- /dev/null +++ b/packages/base/src/page/System/ProcessConnection/DingTalkSetting/components/ConfigExtraButtons.tsx @@ -0,0 +1,71 @@ +import { useTranslation } from 'react-i18next'; +import { useRef } from 'react'; + +import { message, Space } from 'antd'; +import { BasicToolTips, BasicButton } from '@actiontech/shared'; +import ConfigModifyBtn from '../../../components/ConfigModifyBtn'; +import { IconTest } from '../../../../../icon/system'; + +import configuration from '@actiontech/shared/lib/api/sqle/service/configuration'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; + +interface ConfigExtraButtonsProps { + isConfigClosed: boolean; + extraButtonsVisible: boolean; + handleClickModify: () => void; +} + +const ConfigExtraButtons = ({ + isConfigClosed, + extraButtonsVisible, + handleClickModify +}: ConfigExtraButtonsProps) => { + const { t } = useTranslation(); + const [messageApi, messageContextHolder] = message.useMessage(); + + const testTing = useRef(false); + const testDingTalkConfiguration = () => { + if (testTing.current) { + return; + } + testTing.current = true; + configuration + .testDingTalkConfigV1() + .then((res) => { + if (res.data.code === ResponseCode.SUCCESS) { + if (res.data.data?.is_ding_talk_send_normal) { + messageApi.success(t('dmsSystem.dingTalk.testSuccess')); + } else { + messageApi.error( + res.data.data?.send_error_message ?? t('common.unknownError') + ); + } + } + }) + .finally(() => { + testTing.current = false; + }); + }; + + return ( + <> + {messageContextHolder} + + + ); +}; + +export default ConfigExtraButtons; diff --git a/packages/base/src/page/System/ProcessConnection/DingTalkSetting/components/ConfigField.tsx b/packages/base/src/page/System/ProcessConnection/DingTalkSetting/components/ConfigField.tsx new file mode 100644 index 000000000..54dab0374 --- /dev/null +++ b/packages/base/src/page/System/ProcessConnection/DingTalkSetting/components/ConfigField.tsx @@ -0,0 +1,39 @@ +import { useTranslation } from 'react-i18next'; + +import { FormItemLabel } from '@actiontech/shared/lib/components/FormCom'; +import { BasicInput } from '@actiontech/shared'; + +const ConfigField = () => { + const { t } = useTranslation(); + + return ( + <> + + + + + + + + ); +}; + +export default ConfigField; diff --git a/packages/base/src/page/System/ProcessConnection/DingTalkSetting/index.tsx b/packages/base/src/page/System/ProcessConnection/DingTalkSetting/index.tsx index 213282dfd..579399a95 100644 --- a/packages/base/src/page/System/ProcessConnection/DingTalkSetting/index.tsx +++ b/packages/base/src/page/System/ProcessConnection/DingTalkSetting/index.tsx @@ -1,29 +1,27 @@ -import { useCallback, useMemo, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { useBoolean, useRequest } from 'ahooks'; -import { Form, message, Space, Spin, Typography } from 'antd'; -import { BasicToolTips, BasicButton, BasicInput } from '@actiontech/shared'; +import { useCallback, useMemo } from 'react'; + +import { Form, Spin, Typography } from 'antd'; +import { CustomLabelContent } from '@actiontech/shared/lib/components/FormCom'; +import ConfigSwitch from '../../components/ConfigSwitch'; +import ConfigExtraButtons from './components/ConfigExtraButtons'; +import ConfigField from './components/ConfigField'; + import useConfigRender, { ReadOnlyConfigColumnsType } from '../../hooks/useConfigRender'; +import useConfigSwitch from '../../hooks/useConfigSwitch'; + import configuration from '@actiontech/shared/lib/api/sqle/service/configuration'; import { IDingTalkConfigurationV1 } from '@actiontech/shared/lib/api/sqle/service/common'; import { ResponseCode } from '@actiontech/shared/lib/enum'; import { FormFields } from './index.type'; import { defaultFormData, switchFieldName } from './index.data'; -import useConfigSwitch from '../../hooks/useConfigSwitch'; -import { - CustomLabelContent, - FormItemLabel, - FormItemNoLabel -} from '@actiontech/shared/lib/components/FormCom'; -import ConfigModifyBtn from '../../components/ConfigModifyBtn'; -import { IconTest } from '../../../../icon/system'; -import ConfigSwitch from '../../components/ConfigSwitch'; +import ConfigSubmitButtonField from '../../components/ConfigSubmitButtonField'; const DingTalkSetting: React.FC = () => { const { t } = useTranslation(); - const [messageApi, messageContextHolder] = message.useMessage(); const { form, renderConfigForm, @@ -132,30 +130,6 @@ const DingTalkSetting: React.FC = () => { handleToggleSwitch }); - const testTing = useRef(false); - const testDingTalkConfiguration = () => { - if (testTing.current) { - return; - } - testTing.current = true; - configuration - .testDingTalkConfigV1() - .then((res) => { - if (res.data.code === ResponseCode.SUCCESS) { - if (res.data.data?.is_ding_talk_send_normal) { - messageApi.success(t('dmsSystem.dingTalk.testSuccess')); - } else { - messageApi.error( - res.data.data?.send_error_message ?? t('common.unknownError') - ); - } - } - }) - .finally(() => { - testTing.current = false; - }); - }; - const readonlyColumnsConfig: ReadOnlyConfigColumnsType = useMemo(() => { return [ @@ -174,26 +148,15 @@ const DingTalkSetting: React.FC = () => { return (
- {messageContextHolder} - {renderConfigForm({ data: dingTalkInfo ?? {}, columns: readonlyColumnsConfig, configExtraButtons: ( - + ), configSwitchNode: ( { onSwitchPopoverOpen={onConfigSwitchPopoverOpen} /> ), - configField: ( - <> - - - - - - - - ), + configField: , submitButtonField: ( - - - - {t('common.cancel')} - - - {t('common.submit')} - - - + ), submit: submitDingTalkConfig })} diff --git a/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/components/ConfigExtraButtons.tsx b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/components/ConfigExtraButtons.tsx new file mode 100644 index 000000000..2e5b9cabb --- /dev/null +++ b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/components/ConfigExtraButtons.tsx @@ -0,0 +1,191 @@ +import { useTranslation } from 'react-i18next'; +import { useRef, useState } from 'react'; + +import { + Form, + Radio, + RadioGroupProps, + Space, + message as messageApi +} from 'antd'; +import { BasicInput, EmptyBox } from '@actiontech/shared'; +import { + FormItemLabel, + FormItemNoLabel +} from '@actiontech/shared/lib/components/FormCom'; +import ConfigTestBtn from '../../../components/ConfigTestBtn'; +import ConfigTestPopoverForm from '../../../components/ConfigTestPopoverForm'; +import ConfigModifyBtn from '../../../components/ConfigModifyBtn'; +import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; + +import configuration from '@actiontech/shared/lib/api/sqle/service/configuration'; +import { TestFeishuConfigurationReqV1AccountTypeEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum'; +import { phoneRule } from '@actiontech/shared/lib/utils/FormRule'; +import { TestFormFields } from '../index.type'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; + +interface ConfigExtraButtonsProps { + isConfigClosed: boolean; + extraButtonsVisible: boolean; + enabled: string | boolean; + handleClickModify: () => void; +} + +const ConfigExtraButtons = ({ + isConfigClosed, + extraButtonsVisible, + enabled, + handleClickModify +}: ConfigExtraButtonsProps) => { + const { t } = useTranslation(); + const [message, messageContextHolder] = messageApi.useMessage(); + + const [testForm] = Form.useForm(); + const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); + const [receiveType, setReceiveType] = + useState( + TestFeishuConfigurationReqV1AccountTypeEnum.email + ); + const testing = useRef(false); + + const testLarkAuditConfiguration = async () => { + if (testing.current) { + return; + } + testing.current = true; + toggleTestPopoverVisible(false); + const hide = message.loading(t('dmsSystem.larkAudit.testing'), 0); + const values = await testForm.validateFields(); + + configuration + .testFeishuAuditConfigV1({ + account: + receiveType === TestFeishuConfigurationReqV1AccountTypeEnum.email + ? values.receiveEmail + : values.receivePhone, + account_type: values.receiveType + }) + .then((res) => { + if (res.data.code === ResponseCode.SUCCESS) { + const resData = res.data?.data; + + if (resData?.is_message_sent_normally) { + message.success(t('dmsSystem.larkAudit.testSuccess')); + } else { + message.error(resData?.error_message ?? t('common.unknownError')); + } + } + }) + .finally(() => { + hide(); + testing.current = false; + testForm.resetFields(); + setReceiveType(TestFeishuConfigurationReqV1AccountTypeEnum.email); + }); + }; + + const handleChangeReceiveType: RadioGroupProps['onChange'] = (e) => { + const receiveType = e.target.value; + setReceiveType(receiveType); + + if (receiveType === TestFeishuConfigurationReqV1AccountTypeEnum.email) { + testForm.resetFields(['receivePhone']); + } else { + testForm.resetFields(['receiveEmail']); + } + }; + + const onTestPopoverOpen = (open: boolean) => { + if (!enabled) { + return; + } + if (!open) { + testForm.resetFields(); + setReceiveType(TestFeishuConfigurationReqV1AccountTypeEnum.email); + } + toggleTestPopoverVisible(open); + }; + + return ( + <> + {messageContextHolder} + + + ); +}; + +export default ConfigExtraButtons; diff --git a/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/components/ConfigField.tsx b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/components/ConfigField.tsx new file mode 100644 index 000000000..9f847f0af --- /dev/null +++ b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/components/ConfigField.tsx @@ -0,0 +1,37 @@ +import { useTranslation } from 'react-i18next'; +import { FormItemLabel } from '@actiontech/shared/lib/components/FormCom'; +import { BasicInput } from '@actiontech/shared'; + +const ConfigField = () => { + const { t } = useTranslation(); + return ( + <> + + + + + + + + ); +}; + +export default ConfigField; diff --git a/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx index 6b701746b..f51328e0c 100644 --- a/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx +++ b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx @@ -1,46 +1,29 @@ -import { useCallback, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { - Form, - Radio, - RadioGroupProps, - Space, - Spin, - Typography, - message as messageApi -} from 'antd'; import { useBoolean, useRequest } from 'ahooks'; -import { - BasicButton, - BasicInput, - EmptyBox, - EnterpriseFeatureDisplay -} from '@actiontech/shared'; -import { - CustomLabelContent, - FormItemLabel, - FormItemNoLabel -} from '@actiontech/shared/lib/components/FormCom'; +import { useCallback, useMemo } from 'react'; + +import { Form, Spin, Typography, message as messageApi } from 'antd'; +import { EnterpriseFeatureDisplay } from '@actiontech/shared'; +import ConfigSwitch from '../../components/ConfigSwitch'; +import { CustomLabelContent } from '@actiontech/shared/lib/components/FormCom'; +import ConfigField from './components/ConfigField'; +import ConfigSubmitButtonField from '../../components/ConfigSubmitButtonField'; +import ConfigExtraButtons from './components/ConfigExtraButtons'; + +import useConfigSwitch from '../../hooks/useConfigSwitch'; import useConfigRender, { ReadOnlyConfigColumnsType } from '../../hooks/useConfigRender'; -import useConfigSwitch from '../../hooks/useConfigSwitch'; -import ConfigTestBtn from '../../components/ConfigTestBtn'; -import ConfigTestPopoverForm from '../../components/ConfigTestPopoverForm'; -import ConfigModifyBtn from '../../components/ConfigModifyBtn'; -import ConfigSwitch from '../../components/ConfigSwitch'; -import { ResponseCode } from '@actiontech/shared/lib/enum'; -import { FormFields, TestFormFields } from './index.type'; -import { TestFeishuConfigurationReqV1AccountTypeEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum'; -import { defaultFormData, switchFieldName } from './index.data'; + import configuration from '@actiontech/shared/lib/api/sqle/service/configuration'; +import { FormFields } from './index.type'; +import { defaultFormData, switchFieldName } from './index.data'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; import { IFeishuConfigurationV1 } from '@actiontech/shared/lib/api/sqle/service/common'; -import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; -import { phoneRule } from '@actiontech/shared/lib/utils/FormRule'; const LarkAuditSetting: React.FC = () => { const { t } = useTranslation(); - const [message, messageContextHolder] = messageApi.useMessage(); + const { form, renderConfigForm, @@ -151,72 +134,6 @@ const LarkAuditSetting: React.FC = () => { handleToggleSwitch }); - const [testForm] = Form.useForm(); - const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); - const [receiveType, setReceiveType] = - useState( - TestFeishuConfigurationReqV1AccountTypeEnum.email - ); - const testing = useRef(false); - - const testLarkAuditConfiguration = async () => { - if (testing.current) { - return; - } - testing.current = true; - toggleTestPopoverVisible(false); - const hide = message.loading(t('dmsSystem.larkAudit.testing'), 0); - const values = await testForm.validateFields(); - - configuration - .testFeishuAuditConfigV1({ - account: - receiveType === TestFeishuConfigurationReqV1AccountTypeEnum.email - ? values.receiveEmail - : values.receivePhone, - account_type: values.receiveType - }) - .then((res) => { - if (res.data.code === ResponseCode.SUCCESS) { - const resData = res.data?.data; - - if (resData?.is_message_sent_normally) { - message.success(t('dmsSystem.larkAudit.testSuccess')); - } else { - message.error(resData?.error_message ?? t('common.unknownError')); - } - } - }) - .finally(() => { - hide(); - testing.current = false; - testForm.resetFields(); - setReceiveType(TestFeishuConfigurationReqV1AccountTypeEnum.email); - }); - }; - - const handleChangeReceiveType: RadioGroupProps['onChange'] = (e) => { - const receiveType = e.target.value; - setReceiveType(receiveType); - - if (receiveType === TestFeishuConfigurationReqV1AccountTypeEnum.email) { - testForm.resetFields(['receivePhone']); - } else { - testForm.resetFields(['receiveEmail']); - } - }; - - const onTestPopoverOpen = (open: boolean) => { - if (!enabled) { - return; - } - if (!open) { - testForm.resetFields(); - setReceiveType(TestFeishuConfigurationReqV1AccountTypeEnum.email); - } - toggleTestPopoverVisible(open); - }; - const readonlyColumnsConfig: ReadOnlyConfigColumnsType = useMemo(() => { return [ @@ -235,8 +152,6 @@ const LarkAuditSetting: React.FC = () => { return (
- {messageContextHolder} - { data: larkAuditInfo ?? {}, columns: readonlyColumnsConfig, configExtraButtons: ( - + ), configSwitchNode: ( { onSwitchPopoverOpen={onConfigSwitchPopoverOpen} /> ), - configField: ( - <> - - - - - - - - ), + configField: , submitButtonField: ( - - - - {t('common.cancel')} - - - {t('common.submit')} - - - + ), submit: submitLarkAuditConfig })} From d54c4aadd89395af59a6ee0db683e5c79a0827a5 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 14:13:49 +0800 Subject: [PATCH 04/27] case BasicTitle --- .../__snapshots__/index.test.tsx.snap | 81 +++++++++++++++++++ .../components/BasicTitle/index.test.tsx | 27 +++++++ 2 files changed, 108 insertions(+) create mode 100644 packages/base/src/page/System/components/BasicTitle/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/components/BasicTitle/index.test.tsx diff --git a/packages/base/src/page/System/components/BasicTitle/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/components/BasicTitle/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..5268fe619 --- /dev/null +++ b/packages/base/src/page/System/components/BasicTitle/__snapshots__/index.test.tsx.snap @@ -0,0 +1,81 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/components/BasicTitle render title 1`] = ` + +
+
+
+
+
+ title cont +
+
+
+ + child node + +
+
+ +`; + +exports[`base/System/components/BasicTitle render title when title other params 1`] = ` + +
+
+
+
+
+ title cont +
+
+
+
+ + + +
+
+
+
+ + titleExtra + +
+ children string +
+
+ +`; diff --git a/packages/base/src/page/System/components/BasicTitle/index.test.tsx b/packages/base/src/page/System/components/BasicTitle/index.test.tsx new file mode 100644 index 000000000..603a248aa --- /dev/null +++ b/packages/base/src/page/System/components/BasicTitle/index.test.tsx @@ -0,0 +1,27 @@ +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import SystemBasicTitle, { SystemBasicTitleProps } from '.'; + + +describe('base/System/components/BasicTitle', () => { + const customRender = (params: SystemBasicTitleProps) => { + return renderWithTheme(); + }; + + it('render title', () => { + const { baseElement } = customRender({ + title: 'title cont', + children: child node + }); + expect(baseElement).toMatchSnapshot(); + }); + + it('render title when title other params', () => { + const { baseElement } = customRender({ + title: 'title cont', + children: 'children string', + titleTip: 'this is title tip', + titleExtra: titleExtra + }); + expect(baseElement).toMatchSnapshot(); + }); +}); From e2f6c0fed1808111589c1f7715dc6422e60cc1d1 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 14:19:21 +0800 Subject: [PATCH 05/27] case ConfigModifyBtn --- .../__snapshots__/index.test.tsx.snap | 106 ++++++++++++++++++ .../components/ConfigModifyBtn/index.test.tsx | 31 +++++ 2 files changed, 137 insertions(+) create mode 100644 packages/base/src/page/System/components/ConfigModifyBtn/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/components/ConfigModifyBtn/index.test.tsx diff --git a/packages/base/src/page/System/components/ConfigModifyBtn/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/components/ConfigModifyBtn/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..a12e0b749 --- /dev/null +++ b/packages/base/src/page/System/components/ConfigModifyBtn/__snapshots__/index.test.tsx.snap @@ -0,0 +1,106 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/components/ConfigModifyBtn render snap 1`] = ` + +
+
+
+ +
+
+
+ +`; + +exports[`base/System/components/ConfigModifyBtn render snap 2`] = ` + +
+
+
+ +
+
+
+
+
+
+ +
+
+
+ +`; diff --git a/packages/base/src/page/System/components/ConfigModifyBtn/index.test.tsx b/packages/base/src/page/System/components/ConfigModifyBtn/index.test.tsx new file mode 100644 index 000000000..106941113 --- /dev/null +++ b/packages/base/src/page/System/components/ConfigModifyBtn/index.test.tsx @@ -0,0 +1,31 @@ +import { cleanup, fireEvent, act } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +import ConfigModifyBtn from '.'; + +describe('base/System/components/ConfigModifyBtn', () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + cleanup(); + }); + + it('render snap', async () => { + const onClickFn = jest.fn(); + const { baseElement } = renderWithTheme(); + expect(baseElement).toMatchSnapshot(); + + const btnEle = getBySelector('.ant-btn', baseElement); + + fireEvent.mouseOver(btnEle); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + fireEvent.click(btnEle); + expect(onClickFn).toBeCalled(); + }) +}); From cbb48fe8764681c7607dd80fa3764a1047d0977e Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 14:27:07 +0800 Subject: [PATCH 06/27] case ConfigSubmitButtonField --- .../__snapshots__/index.test.tsx.snap | 158 ++++++++++++++++++ .../ConfigSubmitButtonField/index.test.tsx | 39 +++++ 2 files changed, 197 insertions(+) create mode 100644 packages/base/src/page/System/components/ConfigSubmitButtonField/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/components/ConfigSubmitButtonField/index.test.tsx diff --git a/packages/base/src/page/System/components/ConfigSubmitButtonField/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/components/ConfigSubmitButtonField/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..2b8acb8f3 --- /dev/null +++ b/packages/base/src/page/System/components/ConfigSubmitButtonField/__snapshots__/index.test.tsx.snap @@ -0,0 +1,158 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/components/ConfigSubmitButtonField render snap when submit is false 1`] = ` + +
+
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+ +`; + +exports[`base/System/components/ConfigSubmitButtonField render snap when submit is true 1`] = ` + +
+
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+ +`; diff --git a/packages/base/src/page/System/components/ConfigSubmitButtonField/index.test.tsx b/packages/base/src/page/System/components/ConfigSubmitButtonField/index.test.tsx new file mode 100644 index 000000000..b535844da --- /dev/null +++ b/packages/base/src/page/System/components/ConfigSubmitButtonField/index.test.tsx @@ -0,0 +1,39 @@ +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; + +import ConfigSubmitButtonField from '.'; + +describe('base/System/components/ConfigSubmitButtonField', () => { + const handleClickCancelFn = jest.fn(); + const customRender = (submitLoading: boolean) => { + return renderWithTheme(); + } + + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + cleanup(); + }); + + it('render snap when submit is true', () => { + const { baseElement } = customRender(true); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when submit is false', () => { + const { baseElement } = customRender(false); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when click cancel', async () => { + customRender(false); + + expect(screen.getByText('取 消')).toBeInTheDocument(); + fireEvent.click(screen.getByText('取 消')); + await act(async () => jest.advanceTimersByTime(500)); + expect(handleClickCancelFn).toBeCalled(); + }) +}); From 7c8ba26839ecfb2b34a47bcb899f66e11da4551b Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 14:42:40 +0800 Subject: [PATCH 07/27] case ConfigSwitch --- .../__snapshots__/index.test.tsx.snap | 275 ++++++++++++++++++ .../components/ConfigSwitch/index.test.tsx | 86 ++++++ .../System/components/ConfigSwitch/index.tsx | 2 +- 3 files changed, 362 insertions(+), 1 deletion(-) create mode 100644 packages/base/src/page/System/components/ConfigSwitch/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/components/ConfigSwitch/index.test.tsx diff --git a/packages/base/src/page/System/components/ConfigSwitch/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/components/ConfigSwitch/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..735cfe111 --- /dev/null +++ b/packages/base/src/page/System/components/ConfigSwitch/__snapshots__/index.test.tsx.snap @@ -0,0 +1,275 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/components/ConfigSwitch render snap when modifyFlag is false 1`] = ` + +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/components/ConfigSwitch render snap when switch disabled 1`] = ` + +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; diff --git a/packages/base/src/page/System/components/ConfigSwitch/index.test.tsx b/packages/base/src/page/System/components/ConfigSwitch/index.test.tsx new file mode 100644 index 000000000..778a40c28 --- /dev/null +++ b/packages/base/src/page/System/components/ConfigSwitch/index.test.tsx @@ -0,0 +1,86 @@ +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import ConfigSwitch, { ConfigSwitchParams } from '.'; +import Form from 'antd/es/form/Form'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +describe('base/System/components/ConfigSwitch', () => { + const onConfirmFn = jest.fn(); + const onSwitchChangeFn = jest.fn(); + const onSwitchPopoverOpenFn = jest.fn(); + const customRender = ( + params: Omit< + ConfigSwitchParams, + 'switchFieldName' | 'onConfirm' | 'onSwitchChange' | 'onSwitchPopoverOpen' + > + ) => { + return renderWithTheme( +
+ + + ); + }; + + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + cleanup(); + }); + + it('render snap when switch disabled', () => { + const { baseElement } = customRender({ + switchOpen: false, + modifyFlag: true, + submitLoading: true, + popoverVisible: true + }); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when modifyFlag is false', () => { + const { baseElement } = customRender({ + switchOpen: false, + modifyFlag: false, + submitLoading: true, + popoverVisible: true + }); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when confirm popover', async () => { + customRender({ + switchOpen: false, + modifyFlag: false, + submitLoading: false, + popoverVisible: true + }); + expect(screen.getByText('是否确认关闭当前配置?')).toBeInTheDocument(); + expect(screen.getByText('OK')).toBeInTheDocument(); + fireEvent.click(screen.getByText('OK')); + await act(async () => jest.advanceTimersByTime(500)); + expect(onConfirmFn).toBeCalled(); + }); + + it('render snap when click switch', async () => { + const { baseElement } = customRender({ + switchOpen: false, + modifyFlag: false, + submitLoading: false, + popoverVisible: false + }); + + const switchHandle = getBySelector('.ant-switch-handle', baseElement); + fireEvent.click(switchHandle); + await act(async () => jest.advanceTimersByTime(500)); + expect(onSwitchChangeFn).toBeCalled(); + }) +}); diff --git a/packages/base/src/page/System/components/ConfigSwitch/index.tsx b/packages/base/src/page/System/components/ConfigSwitch/index.tsx index 0d212f188..c7d94954d 100644 --- a/packages/base/src/page/System/components/ConfigSwitch/index.tsx +++ b/packages/base/src/page/System/components/ConfigSwitch/index.tsx @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'; import { FormItemLabel } from '@actiontech/shared/lib/components/FormCom'; import { BasicSwitch } from '@actiontech/shared'; -interface ConfigSwitchParams { +export interface ConfigSwitchParams { switchFieldName: string; switchOpen?: boolean; modifyFlag: boolean; From ecb7c7004deac866ac73447fab30e599ded82870 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 15:19:16 +0800 Subject: [PATCH 08/27] case ConfigTestBtn --- .../__snapshots__/index.test.tsx.snap | 218 ++++++++++++++++++ .../components/ConfigTestBtn/index.test.tsx | 55 +++++ 2 files changed, 273 insertions(+) create mode 100644 packages/base/src/page/System/components/ConfigTestBtn/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/components/ConfigTestBtn/index.test.tsx diff --git a/packages/base/src/page/System/components/ConfigTestBtn/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/components/ConfigTestBtn/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..2c0f6aa2c --- /dev/null +++ b/packages/base/src/page/System/components/ConfigTestBtn/__snapshots__/index.test.tsx.snap @@ -0,0 +1,218 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/components/ConfigTestBtn render snap when Popover cont show 1`] = ` + +
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/components/ConfigTestBtn render snap when btn hover 1`] = ` + +
+
+
+ +
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/components/ConfigTestBtn render snap when btn is default 1`] = ` + +
+
+
+ +
+
+
+ +`; + +exports[`base/System/components/ConfigTestBtn render snap when btn is loading 1`] = ` + +
+
+
+ +
+
+
+ +`; diff --git a/packages/base/src/page/System/components/ConfigTestBtn/index.test.tsx b/packages/base/src/page/System/components/ConfigTestBtn/index.test.tsx new file mode 100644 index 000000000..5ffc41f8f --- /dev/null +++ b/packages/base/src/page/System/components/ConfigTestBtn/index.test.tsx @@ -0,0 +1,55 @@ +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import ConfigTestBtn from '.'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +describe('base/System/components/ConfigTestBtn', () => { + const onPopoverOpenChangeFn = jest.fn(); + const testingRef = jest.fn(); + + const customRender = (popoverOpen = false) => { + return renderWithTheme( + popoverForm} + testingRef={testingRef()} + /> + ); + }; + + beforeEach(() => { + jest.useFakeTimers(); + testingRef.mockImplementation(() => ({ current: false })); + }); + + afterEach(() => { + jest.useRealTimers(); + cleanup(); + }); + + it('render snap when btn is default', () => { + const { baseElement } = customRender(false); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when btn is loading', () => { + testingRef.mockImplementation(() => ({ current: true })); + const { baseElement } = customRender(false); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when btn hover', async () => { + const { baseElement } = customRender(false); + + const btnEle = getBySelector('.ant-btn[type="submit"]'); + fireEvent.mouseOver(btnEle); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when Popover cont show', async () => { + const { baseElement } = customRender(true); + expect(baseElement).toMatchSnapshot(); + }); +}); From d9b159ce32453953c9aac0dc5713e356770a8060 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 15:25:18 +0800 Subject: [PATCH 09/27] case ConfigTestPopoverForm --- .../__snapshots__/index.test.tsx.snap | 62 +++++++++++++++++++ .../ConfigTestPopoverForm/index.test.tsx | 48 ++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 packages/base/src/page/System/components/ConfigTestPopoverForm/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/components/ConfigTestPopoverForm/index.test.tsx diff --git a/packages/base/src/page/System/components/ConfigTestPopoverForm/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/components/ConfigTestPopoverForm/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..362fa005f --- /dev/null +++ b/packages/base/src/page/System/components/ConfigTestPopoverForm/__snapshots__/index.test.tsx.snap @@ -0,0 +1,62 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/components/ConfigTestPopoverForm render snap 1`] = ` + +
+
+
+
+ this is a children node +
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+ +`; diff --git a/packages/base/src/page/System/components/ConfigTestPopoverForm/index.test.tsx b/packages/base/src/page/System/components/ConfigTestPopoverForm/index.test.tsx new file mode 100644 index 000000000..1999ec230 --- /dev/null +++ b/packages/base/src/page/System/components/ConfigTestPopoverForm/index.test.tsx @@ -0,0 +1,48 @@ +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; + +import ConfigTestPopoverForm from '.'; + +describe('base/System/components/ConfigTestPopoverForm', () => { + const handleTestFn = jest.fn(); + const handleCancelFn = jest.fn(); + const customRender = () => { + return renderWithTheme( + this is a children node
} + /> + ); + }; + + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + cleanup(); + }); + + it('render snap', () => { + const { baseElement } = customRender(); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when click cancel btn', async () => { + customRender(); + + expect(screen.getByText('取 消')).toBeInTheDocument(); + fireEvent.click(screen.getByText('取 消')); + expect(handleCancelFn).toBeCalled(); + }); + + it('render snap when click submit btn', async () => { + customRender(); + + expect(screen.getByText('确 认')).toBeInTheDocument(); + fireEvent.click(screen.getByText('确 认')); + expect(handleTestFn).toBeCalled(); + }); +}); From edbcff836bb68881d37c13a78737748c90ad37f8 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 15:26:24 +0800 Subject: [PATCH 10/27] delete no used code --- .../LarkSetting/index copy.tsx | 395 ------------------ 1 file changed, 395 deletions(-) delete mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/index copy.tsx diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/index copy.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/index copy.tsx deleted file mode 100644 index b6d714d35..000000000 --- a/packages/base/src/page/System/PushNotification/LarkSetting/index copy.tsx +++ /dev/null @@ -1,395 +0,0 @@ -import { useBoolean, useRequest } from 'ahooks'; -import { - Form, - message, - Radio, - RadioGroupProps, - Space, - Spin, - Typography -} from 'antd'; -import { useForm } from 'antd/es/form/Form'; -import { useCallback, useMemo, useRef, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { FormFields, TestFormFields } from './index.type'; -import { BasicButton, BasicInput, EmptyBox } from '@actiontech/shared'; -import { phoneRule } from '@actiontech/shared/lib/utils/FormRule'; -import { ResponseCode } from '@actiontech/shared/lib/enum'; -import { TestFeishuConfigurationAccountTypeEnum } from '@actiontech/shared/lib/api/base/service/common.enum'; -import useConfigSwitch from '../../hooks/useConfigSwitch'; -import useConfigRender, { - ReadOnlyConfigColumnsType -} from '../../hooks/useConfigRender'; -import ConfigTestBtn from '../../components/ConfigTestBtn'; -import ConfigTestPopoverForm from '../../components/ConfigTestPopoverForm'; -import ConfigModifyBtn from '../../components/ConfigModifyBtn'; -import ConfigSwitch from '../../components/ConfigSwitch'; -import { - FormItemLabel, - FormItemNoLabel -} from '@actiontech/shared/lib/components/FormCom'; -import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; -import dms from '@actiontech/shared/lib/api/base/service/dms'; -import { IFeishuConfigurationResData } from '@actiontech/shared/lib/api/base/service/common'; -import { switchFieldName } from './index.data'; - -const LarkSetting: React.FC = () => { - const { t } = useTranslation(); - const [messageApi, messageContextHolder] = message.useMessage(); - - const { - form, - renderConfigForm, - startModify, - modifyFinish, - modifyFlag, - extraButtonsVisible, - enabled - } = useConfigRender({ - switchFieldName, - switchFieldLabel: t('dmsSystem.lark.enable') - }); - - const [submitLoading, { setTrue: startSubmit, setFalse: submitFinish }] = - useBoolean(); - - const { - data: larkInfo, - loading, - refresh: refreshLarkInfo - } = useRequest( - () => dms.GetFeishuConfiguration().then((res) => res.data?.data ?? {}), - { - onSuccess(res) { - if (res) { - form.setFieldsValue({ - enabled: !!res.is_feishu_notification_enabled - }); - } - } - } - ); - const isConfigClosed = useMemo(() => { - return !larkInfo?.is_feishu_notification_enabled; - }, [larkInfo]); - - const setFormDefaultValue = useCallback(() => { - form.setFieldsValue({ - appKey: larkInfo?.app_id, - appSecret: undefined - }); - }, [form, larkInfo]); - - const handleClickModify = () => { - setFormDefaultValue(); - startModify(); - }; - const handleClickCancel = () => { - if (isConfigClosed) form.setFieldsValue({ [switchFieldName]: false }); - setFormDefaultValue(); - modifyFinish(); - }; - const handleToggleSwitch = (open: boolean) => { - form.setFieldValue(switchFieldName, open); - }; - - const submitLarkConfig = (values: FormFields) => { - startSubmit(); - dms - .UpdateFeishuConfiguration({ - update_feishu_configuration: { - is_feishu_notification_enabled: values.enabled, - app_id: values.appKey, - app_secret: values.appSecret - } - }) - .then((res) => { - if (res.data.code === ResponseCode.SUCCESS) { - modifyFinish(); - refreshLarkInfo(); - form.resetFields(); - } - }) - .finally(() => { - submitFinish(); - }); - }; - - const switchOpen = Form.useWatch(switchFieldName, form); - - const { - configSwitchPopoverVisible, - onConfigSwitchPopoverOpen, - onConfigSwitchPopoverConfirm, - onConfigSwitchChange - } = useConfigSwitch({ - isConfigClosed, - switchOpen, - modifyFlag, - startSubmit, - submitFinish, - handleClickModify, - handleUpdateConfig: () => - dms.UpdateFeishuConfiguration({ - update_feishu_configuration: { - ...larkInfo, - is_feishu_notification_enabled: false - } - }), - handleClickCancel, - refreshConfig: refreshLarkInfo, - handleToggleSwitch - }); - - const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); - const [testForm] = useForm(); - const [receiveType, setReceiveType] = - useState( - TestFeishuConfigurationAccountTypeEnum.email - ); - const testing = useRef(false); - const testLarkConfiguration = async () => { - if (testing.current) { - return; - } - const values = await testForm.validateFields(); - testing.current = true; - toggleTestPopoverVisible(false); - const hide = messageApi.loading(t('dmsSystem.lark.testing'), 0); - dms - .TestFeishuConfiguration({ - test_feishu_configuration: { - account: - receiveType === TestFeishuConfigurationAccountTypeEnum.email - ? values.receiveEmail - : values.receivePhone, - account_type: values.receiveType - } - }) - .then((res) => { - if (res.data.code === ResponseCode.SUCCESS) { - const resData = res.data?.data; - if (resData?.is_message_sent_normally) { - messageApi.success(t('dmsSystem.lark.testSuccess')); - } else { - messageApi.error( - resData?.error_message ?? t('common.unknownError') - ); - } - } - }) - .finally(() => { - hide(); - testing.current = false; - testForm.resetFields(); - setReceiveType(TestFeishuConfigurationAccountTypeEnum.email); - }); - }; - const onTestPopoverOpen = (open: boolean) => { - if (!enabled) { - return; - } - if (!open) { - testForm.resetFields(); - setReceiveType(TestFeishuConfigurationAccountTypeEnum.email); - } - toggleTestPopoverVisible(open); - }; - - const handleChangeReceiveType: RadioGroupProps['onChange'] = (e) => { - const receiveType = e.target.value; - setReceiveType(receiveType); - - if (receiveType === TestFeishuConfigurationAccountTypeEnum.email) { - testForm.resetFields(['receivePhone']); - } else { - testForm.resetFields(['receiveEmail']); - } - }; - - const readonlyColumnsConfig: ReadOnlyConfigColumnsType = - useMemo(() => { - return [ - { - label: 'App ID', - span: 3, - dataIndex: 'app_id', - hidden: !larkInfo?.is_feishu_notification_enabled, - render: (val) => ( - {val || '--'} - ) - } - ]; - }, [larkInfo]); - - return ( -
- - {messageContextHolder} - - {renderConfigForm({ - data: larkInfo ?? {}, - columns: readonlyColumnsConfig, - configExtraButtons: ( - - ), - configSwitchNode: ( - - ), - configField: ( - <> - - - - - - - - ), - submitButtonField: ( - - - - {t('common.cancel')} - - - {t('common.submit')} - - - - ), - submit: submitLarkConfig - })} - -
- ); -}; - -export default LarkSetting; From 7cf4f33271c0fb51876fe34e4433114e32ec61cc Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 16:34:38 +0800 Subject: [PATCH 11/27] case LarkSetting components --- .../conponents/ConfigExtraButtons.test.tsx | 155 ++++ .../conponents/ConfigExtraButtons.tsx | 2 +- .../conponents/ConfigField.test.tsx | 13 + .../ConfigExtraButtons.test.tsx.snap | 741 ++++++++++++++++++ .../ConfigTestPopoverForm/index.test.tsx | 2 +- 5 files changed, 911 insertions(+), 2 deletions(-) create mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.test.tsx create mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.test.tsx create mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/conponents/__snapshots__/ConfigExtraButtons.test.tsx.snap diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.test.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.test.tsx new file mode 100644 index 000000000..f33d65d25 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.test.tsx @@ -0,0 +1,155 @@ +import ConfigExtraButtons, { + ConfigExtraButtonsProps +} from './ConfigExtraButtons'; + +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +import system from '../../../../../testUtils/mockApi/system'; +import { TestFeishuConfigurationAccountTypeEnum } from '@actiontech/shared/lib/api/base/service/common.enum'; +import { createSpyErrorResponse } from '@actiontech/shared/lib/testUtil/mockApi'; + +describe('base/System/PushNotification/LarkSetting/ConfigExtraButtons', () => { + let requestTestFeishuConfiguration: jest.SpyInstance; + const handleClickModifyFn = jest.fn(); + const customRender = ( + params: Omit + ) => { + return renderWithTheme( + + ); + }; + + beforeEach(() => { + jest.useFakeTimers(); + requestTestFeishuConfiguration = system.testLarkConfig(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + describe('render snap when hidden val is true', () => { + it('render isConfigClosed is true', () => { + const { baseElement } = customRender({ + isConfigClosed: true, + extraButtonsVisible: true, + enabled: false + }); + expect(baseElement).toMatchSnapshot(); + }); + it('render extraButtonsVisible is false', () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: false, + enabled: false + }); + expect(baseElement).toMatchSnapshot(); + }); + }); + + describe('render snap form', () => { + it('render popover cancel btn', async () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true + }); + + const btnPopoverOpen = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.click(btnPopoverOpen); + await act(async () => jest.advanceTimersByTime(500)); + expect(screen.getByText('取 消')).toBeInTheDocument(); + await act(async () => jest.advanceTimersByTime(300)); + expect(baseElement).toMatchSnapshot(); + }); + + it('render form validate', async () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true + }); + + const btnPopoverOpen = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.click(btnPopoverOpen); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + expect( + getBySelector('input[ placeholder="请输入邮箱"]', baseElement) + ).toBeInTheDocument(); + expect(screen.getByText('手机号')).toBeInTheDocument(); + fireEvent.click(screen.getByText('手机号')); + await act(async () => jest.advanceTimersByTime(500)); + expect( + getBySelector('input[ placeholder="请输入手机号"]', baseElement) + ).toBeInTheDocument(); + + fireEvent.change(getBySelector('#receivePhone', baseElement), { + target: { + value: '15115215134' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + + expect(screen.getByText('确 认')).toBeInTheDocument(); + fireEvent.click(screen.getByText('确 认')); + await act(async () => jest.advanceTimersByTime(300)); + expect(screen.getByText('正在向飞书推送消息...')).toBeInTheDocument(); + await act(async () => jest.advanceTimersByTime(3000)); + expect(requestTestFeishuConfiguration).toBeCalled(); + expect(requestTestFeishuConfiguration).toBeCalledWith({ + test_feishu_configuration: { + account: '15115215134', + account_type: TestFeishuConfigurationAccountTypeEnum.phone + } + }); + expect(screen.getByText('已成功将消息推送至指定账号')).toBeInTheDocument(); + }); + + it('render form when api error', async () => { + requestTestFeishuConfiguration.mockImplementation(() => + createSpyErrorResponse({ error_message: 'error info' }) + ); + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true + }); + + const btnPopoverOpen = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.click(btnPopoverOpen); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.change(getBySelector('#receiveEmail', baseElement), { + target: { + value: '1@q.com' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(screen.getByText('确 认')); + await act(async () => jest.advanceTimersByTime(3300)); + expect(requestTestFeishuConfiguration).toBeCalled(); + expect(requestTestFeishuConfiguration).toBeCalledWith({ + test_feishu_configuration: { + account: '1@q.com', + account_type: TestFeishuConfigurationAccountTypeEnum.email + } + }); + }); + }) +}); diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.tsx index 9da13b4e2..6fd0e5c04 100644 --- a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.tsx +++ b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.tsx @@ -20,7 +20,7 @@ import { ResponseCode } from '@actiontech/shared/lib/enum'; import { TestFormFields } from '../index.type'; import { TestFeishuConfigurationAccountTypeEnum } from '@actiontech/shared/lib/api/base/service/common.enum'; -interface ConfigExtraButtonsProps { +export interface ConfigExtraButtonsProps { enabled: string | boolean; isConfigClosed: boolean; extraButtonsVisible: boolean; diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.test.tsx new file mode 100644 index 000000000..f672930a4 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.test.tsx @@ -0,0 +1,13 @@ +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; + +import { Form } from 'antd'; +import ConfigField from './ConfigField'; + +describe('base/System/PushNotification/LarkSetting/ConfigField', () => { + it('render snap', () => { + const { baseElement } = renderWithTheme(
+ + ); + expect(baseElement).toMatchSnapshot(); + }); +}); diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/__snapshots__/ConfigExtraButtons.test.tsx.snap b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/__snapshots__/ConfigExtraButtons.test.tsx.snap new file mode 100644 index 000000000..02b57800c --- /dev/null +++ b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/__snapshots__/ConfigExtraButtons.test.tsx.snap @@ -0,0 +1,741 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/LarkSetting/ConfigExtraButtons render snap form render form validate 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/LarkSetting/ConfigExtraButtons render snap form render popover cancel btn 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/LarkSetting/ConfigExtraButtons render snap when hidden val is true render extraButtonsVisible is false 1`] = ` + +
+ +
+ +`; + +exports[`base/System/PushNotification/LarkSetting/ConfigExtraButtons render snap when hidden val is true render isConfigClosed is true 1`] = ` + +
+ +
+ +`; diff --git a/packages/base/src/page/System/components/ConfigTestPopoverForm/index.test.tsx b/packages/base/src/page/System/components/ConfigTestPopoverForm/index.test.tsx index 1999ec230..abdaf2764 100644 --- a/packages/base/src/page/System/components/ConfigTestPopoverForm/index.test.tsx +++ b/packages/base/src/page/System/components/ConfigTestPopoverForm/index.test.tsx @@ -1,4 +1,4 @@ -import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { cleanup, fireEvent, screen } from '@testing-library/react'; import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; import ConfigTestPopoverForm from '.'; From f8a4454754547bf84cc7f6a36878dd129e810747 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 17:05:20 +0800 Subject: [PATCH 12/27] init case LarkSetting --- .../LarkAuditSetting/index.tsx | 2 +- .../__snapshots__/index.test.tsx.snap | 2317 +++++++++++++++++ .../__snapshots__/ConfigField.test.tsx.snap | 121 + .../LarkSetting/index.test.tsx | 93 + 4 files changed, 2532 insertions(+), 1 deletion(-) create mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/conponents/__snapshots__/ConfigField.test.tsx.snap create mode 100644 packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx diff --git a/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx index f51328e0c..9d85f3846 100644 --- a/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx +++ b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx @@ -2,7 +2,7 @@ import { useTranslation } from 'react-i18next'; import { useBoolean, useRequest } from 'ahooks'; import { useCallback, useMemo } from 'react'; -import { Form, Spin, Typography, message as messageApi } from 'antd'; +import { Form, Spin, Typography } from 'antd'; import { EnterpriseFeatureDisplay } from '@actiontech/shared'; import ConfigSwitch from '../../components/ConfigSwitch'; import { CustomLabelContent } from '@actiontech/shared/lib/components/FormCom'; diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/PushNotification/LarkSetting/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..a9ae5bf8f --- /dev/null +++ b/packages/base/src/page/System/PushNotification/LarkSetting/__snapshots__/index.test.tsx.snap @@ -0,0 +1,2317 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/LarkSetting render snap 1`] = ` + +
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/LarkSetting render snap 2`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + +
+
+ + App ID + + +
+ app_id +
+
+
+
+
+
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/LarkSetting render switch cancel btn render snap when click cont cancel btn 1`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + +
+
+ + App ID + + +
+ app_id +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/LarkSetting render switch cancel btn render snap when click cont cancel btn 2`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + +
+
+ + App ID + + +
+ app_id +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/LarkSetting render switch cancel btn render snap when click switch change 1`] = ` + +
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + +
+
+ + App ID + + +
+ app_id +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/__snapshots__/ConfigField.test.tsx.snap b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/__snapshots__/ConfigField.test.tsx.snap new file mode 100644 index 000000000..94e68b284 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/__snapshots__/ConfigField.test.tsx.snap @@ -0,0 +1,121 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/LarkSetting/ConfigField render snap 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+ +`; diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx new file mode 100644 index 000000000..9851dfd41 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx @@ -0,0 +1,93 @@ +import LarkSetting from '.'; + +import system from '../../../../testUtils/mockApi/system'; + +import { cleanup, fireEvent, act, screen, getAllByText } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +describe('base/System/PushNotification/LarkSetting', () => { + let requestGetFeishuConfiguration: jest.SpyInstance; + let requestUpdateFeishuConfiguration: jest.SpyInstance; + const customRender = () => { + return renderWithTheme(); + }; + + beforeEach(() => { + jest.useFakeTimers(); + requestGetFeishuConfiguration = system.getLarkConfig(); + requestUpdateFeishuConfiguration = system.updateLarkConfig(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + it('render snap', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + await act(async () => jest.advanceTimersByTime(2600)); + expect(requestGetFeishuConfiguration).toBeCalled(); + expect(baseElement).toMatchSnapshot(); + }); + + describe('render switch cancel btn', () => { + it('render snap when click cont cancel btn', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + expect(screen.getByText('是否启用飞书推送')).toBeInTheDocument(); + + const switchEle = getBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + expect(screen.getByText('取 消')).toBeInTheDocument(); + fireEvent.click(screen.getByText('取 消')); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when click switch change', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + + const switchEle = getBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + expect(screen.getByText('是否确认关闭当前配置?')).toBeInTheDocument(); + expect(screen.getByText('Cancel')).toBeInTheDocument(); + expect(screen.getByText('OK')).toBeInTheDocument(); + + fireEvent.click(screen.getByText('Cancel')); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + fireEvent.click(screen.getByText('OK')); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); + }); + + describe('render submit lark setting', () => { + it('render submit success', async () => { + + }) + }) +}); From 68b254e5bc56fd024af02677141920f9aaa5bf19 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 17:20:52 +0800 Subject: [PATCH 13/27] formatter code --- .../conponents/ConfigExtraButtons.test.tsx | 6 ++++-- .../LarkSetting/conponents/ConfigField.test.tsx | 8 +++++--- .../PushNotification/LarkSetting/index.test.tsx | 14 +++++++++----- .../System/components/BasicTitle/index.test.tsx | 1 - .../components/ConfigModifyBtn/index.test.tsx | 6 ++++-- .../ConfigSubmitButtonField/index.test.tsx | 11 ++++++++--- .../components/ConfigSwitch/index.test.tsx | 16 ++++++++-------- 7 files changed, 38 insertions(+), 24 deletions(-) diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.test.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.test.tsx index f33d65d25..cf3c1c71f 100644 --- a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.test.tsx +++ b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigExtraButtons.test.tsx @@ -114,7 +114,9 @@ describe('base/System/PushNotification/LarkSetting/ConfigExtraButtons', () => { account_type: TestFeishuConfigurationAccountTypeEnum.phone } }); - expect(screen.getByText('已成功将消息推送至指定账号')).toBeInTheDocument(); + expect( + screen.getByText('已成功将消息推送至指定账号') + ).toBeInTheDocument(); }); it('render form when api error', async () => { @@ -151,5 +153,5 @@ describe('base/System/PushNotification/LarkSetting/ConfigExtraButtons', () => { } }); }); - }) + }); }); diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.test.tsx index f672930a4..6c92d2658 100644 --- a/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.test.tsx +++ b/packages/base/src/page/System/PushNotification/LarkSetting/conponents/ConfigField.test.tsx @@ -5,9 +5,11 @@ import ConfigField from './ConfigField'; describe('base/System/PushNotification/LarkSetting/ConfigField', () => { it('render snap', () => { - const { baseElement } = renderWithTheme(
- - ); + const { baseElement } = renderWithTheme( +
+ + + ); expect(baseElement).toMatchSnapshot(); }); }); diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx index 9851dfd41..87d6ce6c1 100644 --- a/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx +++ b/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx @@ -2,7 +2,13 @@ import LarkSetting from '.'; import system from '../../../../testUtils/mockApi/system'; -import { cleanup, fireEvent, act, screen, getAllByText } from '@testing-library/react'; +import { + cleanup, + fireEvent, + act, + screen, + getAllByText +} from '@testing-library/react'; import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; @@ -86,8 +92,6 @@ describe('base/System/PushNotification/LarkSetting', () => { }); describe('render submit lark setting', () => { - it('render submit success', async () => { - - }) - }) + it('render submit success', async () => {}); + }); }); diff --git a/packages/base/src/page/System/components/BasicTitle/index.test.tsx b/packages/base/src/page/System/components/BasicTitle/index.test.tsx index 603a248aa..35e9f1256 100644 --- a/packages/base/src/page/System/components/BasicTitle/index.test.tsx +++ b/packages/base/src/page/System/components/BasicTitle/index.test.tsx @@ -1,7 +1,6 @@ import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; import SystemBasicTitle, { SystemBasicTitleProps } from '.'; - describe('base/System/components/BasicTitle', () => { const customRender = (params: SystemBasicTitleProps) => { return renderWithTheme(); diff --git a/packages/base/src/page/System/components/ConfigModifyBtn/index.test.tsx b/packages/base/src/page/System/components/ConfigModifyBtn/index.test.tsx index 106941113..2536527d0 100644 --- a/packages/base/src/page/System/components/ConfigModifyBtn/index.test.tsx +++ b/packages/base/src/page/System/components/ConfigModifyBtn/index.test.tsx @@ -16,7 +16,9 @@ describe('base/System/components/ConfigModifyBtn', () => { it('render snap', async () => { const onClickFn = jest.fn(); - const { baseElement } = renderWithTheme(); + const { baseElement } = renderWithTheme( + + ); expect(baseElement).toMatchSnapshot(); const btnEle = getBySelector('.ant-btn', baseElement); @@ -27,5 +29,5 @@ describe('base/System/components/ConfigModifyBtn', () => { fireEvent.click(btnEle); expect(onClickFn).toBeCalled(); - }) + }); }); diff --git a/packages/base/src/page/System/components/ConfigSubmitButtonField/index.test.tsx b/packages/base/src/page/System/components/ConfigSubmitButtonField/index.test.tsx index b535844da..9399d52ac 100644 --- a/packages/base/src/page/System/components/ConfigSubmitButtonField/index.test.tsx +++ b/packages/base/src/page/System/components/ConfigSubmitButtonField/index.test.tsx @@ -6,8 +6,13 @@ import ConfigSubmitButtonField from '.'; describe('base/System/components/ConfigSubmitButtonField', () => { const handleClickCancelFn = jest.fn(); const customRender = (submitLoading: boolean) => { - return renderWithTheme(); - } + return renderWithTheme( + + ); + }; beforeEach(() => { jest.useFakeTimers(); @@ -35,5 +40,5 @@ describe('base/System/components/ConfigSubmitButtonField', () => { fireEvent.click(screen.getByText('取 消')); await act(async () => jest.advanceTimersByTime(500)); expect(handleClickCancelFn).toBeCalled(); - }) + }); }); diff --git a/packages/base/src/page/System/components/ConfigSwitch/index.test.tsx b/packages/base/src/page/System/components/ConfigSwitch/index.test.tsx index 778a40c28..65596a496 100644 --- a/packages/base/src/page/System/components/ConfigSwitch/index.test.tsx +++ b/packages/base/src/page/System/components/ConfigSwitch/index.test.tsx @@ -27,14 +27,14 @@ describe('base/System/components/ConfigSwitch', () => { ); }; - beforeEach(() => { - jest.useFakeTimers(); - }); + beforeEach(() => { + jest.useFakeTimers(); + }); - afterEach(() => { - jest.useRealTimers(); - cleanup(); - }); + afterEach(() => { + jest.useRealTimers(); + cleanup(); + }); it('render snap when switch disabled', () => { const { baseElement } = customRender({ @@ -82,5 +82,5 @@ describe('base/System/components/ConfigSwitch', () => { fireEvent.click(switchHandle); await act(async () => jest.advanceTimersByTime(500)); expect(onSwitchChangeFn).toBeCalled(); - }) + }); }); From aea7be7fd4b5995fa0d32f5ecdf4d26b0a991bb8 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 19:20:30 +0800 Subject: [PATCH 14/27] case LarkSetting --- .../LarkAuditSetting/index.ee.tsx | 188 +++++++ .../LarkAuditSetting/index.tsx | 203 +------ .../__snapshots__/index.test.tsx.snap | 517 ++++++++++++++++++ .../LarkSetting/index.test.tsx | 49 +- 4 files changed, 759 insertions(+), 198 deletions(-) create mode 100644 packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx diff --git a/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx new file mode 100644 index 000000000..2b8ebf627 --- /dev/null +++ b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx @@ -0,0 +1,188 @@ +import { useTranslation } from 'react-i18next'; +import { useBoolean, useRequest } from 'ahooks'; +import { useCallback, useMemo } from 'react'; + +import { Form, Spin, Typography } from 'antd'; +import ConfigSwitch from '../../components/ConfigSwitch'; +import { CustomLabelContent } from '@actiontech/shared/lib/components/FormCom'; +import ConfigField from './components/ConfigField'; +import ConfigSubmitButtonField from '../../components/ConfigSubmitButtonField'; +import ConfigExtraButtons from './components/ConfigExtraButtons'; + +import useConfigSwitch from '../../hooks/useConfigSwitch'; +import useConfigRender, { + ReadOnlyConfigColumnsType +} from '../../hooks/useConfigRender'; + +import configuration from '@actiontech/shared/lib/api/sqle/service/configuration'; +import { FormFields } from './index.type'; +import { defaultFormData, switchFieldName } from './index.data'; +import { ResponseCode } from '@actiontech/shared/lib/enum'; +import { IFeishuConfigurationV1 } from '@actiontech/shared/lib/api/sqle/service/common'; + +const LarkAuditSettingEEIndex = () => { + const { t } = useTranslation(); + + const { + form, + renderConfigForm, + startModify, + modifyFinish, + modifyFlag, + extraButtonsVisible, + enabled + } = useConfigRender({ + switchFieldName, + switchFieldLabel: ( + + ) + }); + + const [submitLoading, { setTrue: startSubmit, setFalse: submitFinish }] = + useBoolean(); + + const { + data: larkAuditInfo, + loading: getLarkAuditInfoLoading, + refresh: refreshLarkAuditInfo + } = useRequest( + () => + configuration + .getFeishuAuditConfigurationV1() + .then((res) => res.data.data ?? {}), + { + onSuccess(res) { + if (res) { + form.setFieldsValue({ + enabled: !!res.is_feishu_notification_enabled + }); + } + } + } + ); + + const isConfigClosed = useMemo(() => { + return !larkAuditInfo?.is_feishu_notification_enabled; + }, [larkAuditInfo]); + + const setFormDefaultValue = useCallback(() => { + form.setFieldsValue({ + appKey: larkAuditInfo?.app_id, + appSecret: undefined + }); + }, [form, larkAuditInfo]); + + const handleClickModify = () => { + setFormDefaultValue(); + startModify(); + }; + + const handleClickCancel = () => { + if (isConfigClosed) form.setFieldValue(switchFieldName, false); + setFormDefaultValue(); + modifyFinish(); + }; + + const handleToggleSwitch = (open: boolean) => { + form.setFieldValue(switchFieldName, open); + }; + + const submitLarkAuditConfig = (values: FormFields) => { + startSubmit(); + configuration + .updateFeishuAuditConfigurationV1({ + is_feishu_notification_enabled: values.enabled, + app_id: values.appKey, + app_secret: values.appSecret + }) + .then((res) => { + if (res.data.code === ResponseCode.SUCCESS) { + handleClickCancel(); + refreshLarkAuditInfo(); + } + }) + .finally(() => { + submitFinish(); + }); + }; + + const switchOpen = Form.useWatch(switchFieldName, form); + + const { + configSwitchPopoverVisible, + onConfigSwitchPopoverOpen, + onConfigSwitchPopoverConfirm, + onConfigSwitchChange + } = useConfigSwitch({ + isConfigClosed, + switchOpen, + modifyFlag, + startSubmit, + submitFinish, + handleClickModify, + handleUpdateConfig: () => + configuration.updateFeishuAuditConfigurationV1({ + ...defaultFormData, + is_feishu_notification_enabled: false + }), + handleClickCancel, + refreshConfig: refreshLarkAuditInfo, + handleToggleSwitch + }); + + const readonlyColumnsConfig: ReadOnlyConfigColumnsType = + useMemo(() => { + return [ + { + label: 'App ID', + span: 3, + dataIndex: 'app_id', + hidden: !larkAuditInfo?.is_feishu_notification_enabled, + render: (val) => ( + {val || '--'} + ) + } + ]; + }, [larkAuditInfo]); + return ( + + {renderConfigForm({ + data: larkAuditInfo ?? {}, + columns: readonlyColumnsConfig, + configExtraButtons: ( + + ), + configSwitchNode: ( + + ), + configField: , + submitButtonField: ( + + ), + submit: submitLarkAuditConfig + })} + + ); +}; + +export default LarkAuditSettingEEIndex; diff --git a/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx index 9d85f3846..4b7364c9e 100644 --- a/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx +++ b/packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.tsx @@ -1,202 +1,25 @@ import { useTranslation } from 'react-i18next'; -import { useBoolean, useRequest } from 'ahooks'; -import { useCallback, useMemo } from 'react'; -import { Form, Spin, Typography } from 'antd'; +import { Typography } from 'antd'; import { EnterpriseFeatureDisplay } from '@actiontech/shared'; -import ConfigSwitch from '../../components/ConfigSwitch'; -import { CustomLabelContent } from '@actiontech/shared/lib/components/FormCom'; -import ConfigField from './components/ConfigField'; -import ConfigSubmitButtonField from '../../components/ConfigSubmitButtonField'; -import ConfigExtraButtons from './components/ConfigExtraButtons'; - -import useConfigSwitch from '../../hooks/useConfigSwitch'; -import useConfigRender, { - ReadOnlyConfigColumnsType -} from '../../hooks/useConfigRender'; - -import configuration from '@actiontech/shared/lib/api/sqle/service/configuration'; -import { FormFields } from './index.type'; -import { defaultFormData, switchFieldName } from './index.data'; -import { ResponseCode } from '@actiontech/shared/lib/enum'; -import { IFeishuConfigurationV1 } from '@actiontech/shared/lib/api/sqle/service/common'; +import LarkAuditSettingEEIndex from './index.ee'; const LarkAuditSetting: React.FC = () => { const { t } = useTranslation(); - const { - form, - renderConfigForm, - startModify, - modifyFinish, - modifyFlag, - extraButtonsVisible, - enabled - } = useConfigRender({ - switchFieldName, - switchFieldLabel: ( - - ) - }); - - const [submitLoading, { setTrue: startSubmit, setFalse: submitFinish }] = - useBoolean(); - - const { - data: larkAuditInfo, - loading: getLarkAuditInfoLoading, - refresh: refreshLarkAuditInfo - } = useRequest( - () => - configuration - .getFeishuAuditConfigurationV1() - .then((res) => res.data.data ?? {}), - { - onSuccess(res) { - if (res) { - form.setFieldsValue({ - enabled: !!res.is_feishu_notification_enabled - }); - } - } - } - ); - - const isConfigClosed = useMemo(() => { - return !larkAuditInfo?.is_feishu_notification_enabled; - }, [larkAuditInfo]); - - const setFormDefaultValue = useCallback(() => { - form.setFieldsValue({ - appKey: larkAuditInfo?.app_id, - appSecret: undefined - }); - }, [form, larkAuditInfo]); - - const handleClickModify = () => { - setFormDefaultValue(); - startModify(); - }; - - const handleClickCancel = () => { - if (isConfigClosed) form.setFieldValue(switchFieldName, false); - setFormDefaultValue(); - modifyFinish(); - }; - - const handleToggleSwitch = (open: boolean) => { - form.setFieldValue(switchFieldName, open); - }; - - const submitLarkAuditConfig = (values: FormFields) => { - startSubmit(); - configuration - .updateFeishuAuditConfigurationV1({ - is_feishu_notification_enabled: values.enabled, - app_id: values.appKey, - app_secret: values.appSecret - }) - .then((res) => { - if (res.data.code === ResponseCode.SUCCESS) { - handleClickCancel(); - refreshLarkAuditInfo(); - } - }) - .finally(() => { - submitFinish(); - }); - }; - - const switchOpen = Form.useWatch(switchFieldName, form); - - const { - configSwitchPopoverVisible, - onConfigSwitchPopoverOpen, - onConfigSwitchPopoverConfirm, - onConfigSwitchChange - } = useConfigSwitch({ - isConfigClosed, - switchOpen, - modifyFlag, - startSubmit, - submitFinish, - handleClickModify, - handleUpdateConfig: () => - configuration.updateFeishuAuditConfigurationV1({ - ...defaultFormData, - is_feishu_notification_enabled: false - }), - handleClickCancel, - refreshConfig: refreshLarkAuditInfo, - handleToggleSwitch - }); - - const readonlyColumnsConfig: ReadOnlyConfigColumnsType = - useMemo(() => { - return [ - { - label: 'App ID', - span: 3, - dataIndex: 'app_id', - hidden: !larkAuditInfo?.is_feishu_notification_enabled, - render: (val) => ( - {val || '--'} - ) - } - ]; - }, [larkAuditInfo]); - return (
- - - {t('dmsSystem.larkAudit.ceTips')} - - } - isConfigPage={true} - > - <> - {renderConfigForm({ - data: larkAuditInfo ?? {}, - columns: readonlyColumnsConfig, - configExtraButtons: ( - - ), - configSwitchNode: ( - - ), - configField: , - submitButtonField: ( - - ), - submit: submitLarkAuditConfig - })} - - - + + {t('dmsSystem.larkAudit.ceTips')} + + } + isConfigPage={true} + > + +
); }; diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/PushNotification/LarkSetting/__snapshots__/index.test.tsx.snap index a9ae5bf8f..0c008d203 100644 --- a/packages/base/src/page/System/PushNotification/LarkSetting/__snapshots__/index.test.tsx.snap +++ b/packages/base/src/page/System/PushNotification/LarkSetting/__snapshots__/index.test.tsx.snap @@ -796,6 +796,523 @@ exports[`base/System/PushNotification/LarkSetting render snap 2`] = ` `; +exports[`base/System/PushNotification/LarkSetting render submit lark setting render submit success 1`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + +
+
+ + App ID + + +
+ app_id +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + exports[`base/System/PushNotification/LarkSetting render switch cancel btn render snap when click cont cancel btn 1`] = `
diff --git a/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx b/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx index 87d6ce6c1..13a515c30 100644 --- a/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx +++ b/packages/base/src/page/System/PushNotification/LarkSetting/index.test.tsx @@ -2,13 +2,7 @@ import LarkSetting from '.'; import system from '../../../../testUtils/mockApi/system'; -import { - cleanup, - fireEvent, - act, - screen, - getAllByText -} from '@testing-library/react'; +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; @@ -92,6 +86,45 @@ describe('base/System/PushNotification/LarkSetting', () => { }); describe('render submit lark setting', () => { - it('render submit success', async () => {}); + it('render submit success', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + const switchEle = getBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.change(getBySelector('#appKey', baseElement), { + target: { + value: 'app key' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + fireEvent.change(getBySelector('#appSecret', baseElement), { + target: { + value: 'app secret' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + expect(screen.getByText('提 交')).toBeInTheDocument(); + fireEvent.click(screen.getByText('提 交')); + await act(async () => jest.advanceTimersByTime(300)); + expect(baseElement).toMatchSnapshot(); + await act(async () => jest.advanceTimersByTime(3000)); + expect(requestUpdateFeishuConfiguration).toBeCalled(); + expect(requestUpdateFeishuConfiguration).toBeCalledWith({ + update_feishu_configuration: { + app_id: 'app key', + app_secret: 'app secret', + is_feishu_notification_enabled: true + } + }); + expect(requestGetFeishuConfiguration).toBeCalled(); + }); }); }); From 5a8a26a972255ca43e2345e44b645654bafe83c0 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Tue, 23 Jan 2024 19:38:00 +0800 Subject: [PATCH 15/27] case ConfigExtraButtons --- .../components/ConfigExtraButtons.test.tsx | 140 +++ .../components/ConfigExtraButtons.tsx | 17 +- .../ConfigExtraButtons.test.tsx.snap | 842 ++++++++++++++++++ .../PushNotification/SMTPSetting/index.tsx | 2 +- 4 files changed, 991 insertions(+), 10 deletions(-) create mode 100644 packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.test.tsx create mode 100644 packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigExtraButtons.test.tsx.snap diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.test.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.test.tsx new file mode 100644 index 000000000..db950a190 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.test.tsx @@ -0,0 +1,140 @@ +import ConfigExtraButtons, { typeConfigExtraButtons } from './ConfigExtraButtons'; + +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +import system from '../../../../../testUtils/mockApi/system'; + +describe('base/System/PushNotification/SMTPSetting/ConfigExtraButtons', () => { + let requestTestSMTPConfigurationSuccess: jest.SpyInstance; + const handleClickModifyFn = jest.fn(); + const customRender = ( + params: Omit + ) => { + return renderWithTheme( + + ); + }; + + beforeEach(() => { + jest.useFakeTimers(); + requestTestSMTPConfigurationSuccess = system.testSMTPConfigSuccess(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + describe('render snap when hidden val is true', () => { + it('render isConfigClosed is true', () => { + const { baseElement } = customRender({ + isConfigClosed: true, + extraButtonsVisible: true, + enabled: false, + }); + expect(baseElement).toMatchSnapshot(); + }); + it('render extraButtonsVisible is false', () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: false, + enabled: false + }); + expect(baseElement).toMatchSnapshot(); + }); + }); + + describe('render snap form', () => { + it('render popover cancel btn', async () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true + }); + + const btnPopoverOpen = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.click(btnPopoverOpen); + await act(async () => jest.advanceTimersByTime(500)); + expect(screen.getByText('取 消')).toBeInTheDocument(); + await act(async () => jest.advanceTimersByTime(300)); + expect(baseElement).toMatchSnapshot(); + }); + + it('render form validate', async () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true + }); + + const btnPopoverOpen = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.click(btnPopoverOpen); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + expect( + getBySelector('input[ placeholder="请输入接收邮箱"]', baseElement) + ).toBeInTheDocument(); + + fireEvent.change(getBySelector('#receiveEmail', baseElement), { + target: { + value: '1@q.com' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(screen.getByText('确 认')); + await act(async () => jest.advanceTimersByTime(3300)); + expect(requestTestSMTPConfigurationSuccess).toBeCalled(); + expect(requestTestSMTPConfigurationSuccess).toBeCalledWith({ + test_smtp_configuration: { + recipient_addr: '1@q.com' + } + }); + }); + + it('render form submit error', async () => { + const requestTestSMTPConfigurationError = system.testSMTPConfigFail(); + + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true + }); + + const btnPopoverOpen = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.click(btnPopoverOpen); + await act(async () => jest.advanceTimersByTime(500)); + + expect( + getBySelector('input[ placeholder="请输入接收邮箱"]', baseElement) + ).toBeInTheDocument(); + + fireEvent.change(getBySelector('#receiveEmail', baseElement), { + target: { + value: '2@a.com' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + fireEvent.click(screen.getByText('确 认')); + await act(async () => jest.advanceTimersByTime(3300)); + expect(requestTestSMTPConfigurationError).toBeCalledWith({ + test_smtp_configuration: { + recipient_addr: '2@a.com' + } + }); + expect(baseElement).toMatchSnapshot(); + }) + }) +}); diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx index 57651a481..048fbe089 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx @@ -12,17 +12,16 @@ import ConfigModifyBtn from '../../../components/ConfigModifyBtn'; import dms from '@actiontech/shared/lib/api/base/service/dms'; import { ResponseCode } from '@actiontech/shared/lib/enum'; -import { ISMTPConfigurationResData } from '@actiontech/shared/lib/api/base/service/common'; -type typeConfigExtraButtons = { - smtpInfo: ISMTPConfigurationResData | undefined; +export type typeConfigExtraButtons = { + isConfigClosed: boolean; enabled: string | number | boolean; extraButtonsVisible: boolean; handleClickModify: () => void; }; const ConfigExtraButtons = ({ - smtpInfo, + isConfigClosed, enabled, extraButtonsVisible, handleClickModify @@ -34,10 +33,6 @@ const ConfigExtraButtons = ({ const [testPopoverVisible, toggleTestPopoverVisible] = useState(false); - const isConfigClosed = useMemo(() => { - return !smtpInfo?.enable_smtp_notify; - }, [smtpInfo]); - const testTing = useRef(false); const onTestPopoverOpen = (open: boolean) => { @@ -119,7 +114,11 @@ const ConfigExtraButtons = ({ } ]} > - + diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigExtraButtons.test.tsx.snap b/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigExtraButtons.test.tsx.snap new file mode 100644 index 000000000..dc1fa7927 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigExtraButtons.test.tsx.snap @@ -0,0 +1,842 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/SMTPSetting/ConfigExtraButtons render snap form render form submit error 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + + + + 正在向 “2@a.com” 发送测试邮件... + +
+
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigExtraButtons render snap form render form validate 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigExtraButtons render snap form render popover cancel btn 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigExtraButtons render snap when hidden val is true render extraButtonsVisible is false 1`] = ` + +
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigExtraButtons render snap when hidden val is true render isConfigClosed is true 1`] = ` + +
+ +
+ +`; diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/index.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/index.tsx index c10cc957d..af9af9c07 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/index.tsx +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/index.tsx @@ -188,7 +188,7 @@ const SMTPSetting = () => { columns: readonlyColumnsConfig, configExtraButtons: ( Date: Tue, 23 Jan 2024 19:48:07 +0800 Subject: [PATCH 16/27] case ConfigField --- .../components/ConfigField.test.tsx | 99 + .../__snapshots__/ConfigField.test.tsx.snap | 2381 +++++++++++++++++ 2 files changed, 2480 insertions(+) create mode 100644 packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx create mode 100644 packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx new file mode 100644 index 000000000..0d3b1c105 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx @@ -0,0 +1,99 @@ +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; + +import { Form } from 'antd'; +import ConfigField from './ConfigField'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +describe('base/System/PushNotification/SMTPSetting/ConfigField', () => { + const customRender = () => { + return renderWithTheme( +
+ + + ); + }; + + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + it('render snap', () => { + const { baseElement } = customRender(); + expect(baseElement).toMatchSnapshot(); + }); + + it('render validator Port', async () => { + const { baseElement } = customRender(); + + const portEle = getBySelector('#port', baseElement); + + fireEvent.change(portEle, { + target: { + value: 'a' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + fireEvent.change(portEle, { + target: { + value: '0' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + fireEvent.change(portEle, { + target: { + value: '65536' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + fireEvent.change(portEle, { + target: { + value: '8080' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); + + it('render pwd must be same', async () => { + const { baseElement } = customRender(); + + const pwdEle = getBySelector('#password', baseElement); + const pwdConfirmEle = getBySelector('#passwordConfirm', baseElement); + + fireEvent.change(pwdEle, { + target: { + value: '1' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.change(pwdConfirmEle, { + target: { + value: '12' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + fireEvent.change(pwdConfirmEle, { + target: { + value: '1' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); +}); diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap b/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap new file mode 100644 index 000000000..4ff8bbb6c --- /dev/null +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap @@ -0,0 +1,2381 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/SMTPSetting/ render pwd must be same 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ render pwd must be same 2`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ render snap 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ render validator Port 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ render validator Port 2`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ render validator Port 3`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ render validator Port 4`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+ +`; From 1c50464f319c3adf0c92a47388928b5a2b2e6fc5 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 13:43:40 +0800 Subject: [PATCH 17/27] case SMTPSetting --- .../__snapshots__/index.test.tsx.snap | 4545 +++++++++++++++++ .../components/ConfigExtraButtons.test.tsx | 10 +- .../components/ConfigExtraButtons.tsx | 2 +- .../components/ConfigField.test.tsx | 2 +- .../SMTPSetting/components/ConfigField.tsx | 30 +- .../__snapshots__/ConfigField.test.tsx.snap | 2380 +++++++++ .../SMTPSetting/index.test.tsx | 152 + 7 files changed, 7110 insertions(+), 11 deletions(-) create mode 100644 packages/base/src/page/System/PushNotification/SMTPSetting/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/PushNotification/SMTPSetting/index.test.tsx diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/PushNotification/SMTPSetting/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..8488a47d3 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/__snapshots__/index.test.tsx.snap @@ -0,0 +1,4545 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/SMTPSetting render snap 1`] = ` + +
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting render snap 2`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + +
+
+ + SMTP地址 + + + 10.10.10.1 + +
+
+
+ + SMTP端口 + + + 3300 + +
+
+
+ + SMTP用户名 + + + currentUser@gamil.com + +
+
+
+ +
+
+ 是否跳过证书认证 +
+
+ + + +
+
+
+ + 否 + +
+
+
+
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting render submit SMTP setting render submit success 1`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + +
+
+ + SMTP地址 + + + 10.10.10.1 + +
+
+
+ + SMTP端口 + + + 3300 + +
+
+
+ + SMTP用户名 + + + currentUser@gamil.com + +
+
+
+ +
+
+ 是否跳过证书认证 +
+
+ + + +
+
+
+ + 否 + +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting render switch cancel btn render snap when click cont cancel btn 1`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + +
+
+ + SMTP地址 + + + 10.10.10.1 + +
+
+
+ + SMTP端口 + + + 3300 + +
+
+
+ + SMTP用户名 + + + currentUser@gamil.com + +
+
+
+ +
+
+ 是否跳过证书认证 +
+
+ + + +
+
+
+ + 否 + +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting render switch cancel btn render snap when click cont cancel btn 2`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + +
+
+ + SMTP地址 + + + 10.10.10.1 + +
+
+
+ + SMTP端口 + + + 3300 + +
+
+
+ + SMTP用户名 + + + currentUser@gamil.com + +
+
+
+ +
+
+ 是否跳过证书认证 +
+
+ + + +
+
+
+ + 否 + +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting render switch cancel btn render snap when click switch change 1`] = ` + +
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + +
+
+ + SMTP地址 + + + 10.10.10.1 + +
+
+
+ + SMTP端口 + + + 3300 + +
+
+
+ + SMTP用户名 + + + currentUser@gamil.com + +
+
+
+ +
+
+ 是否跳过证书认证 +
+
+ + + +
+
+
+ + 否 + +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.test.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.test.tsx index db950a190..7f6bef009 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.test.tsx +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.test.tsx @@ -1,4 +1,6 @@ -import ConfigExtraButtons, { typeConfigExtraButtons } from './ConfigExtraButtons'; +import ConfigExtraButtons, { + typeConfigExtraButtons +} from './ConfigExtraButtons'; import { cleanup, fireEvent, act, screen } from '@testing-library/react'; import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; @@ -33,7 +35,7 @@ describe('base/System/PushNotification/SMTPSetting/ConfigExtraButtons', () => { const { baseElement } = customRender({ isConfigClosed: true, extraButtonsVisible: true, - enabled: false, + enabled: false }); expect(baseElement).toMatchSnapshot(); }); @@ -135,6 +137,6 @@ describe('base/System/PushNotification/SMTPSetting/ConfigExtraButtons', () => { } }); expect(baseElement).toMatchSnapshot(); - }) - }) + }); + }); }); diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx index 048fbe089..33e9bd0a1 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigExtraButtons.tsx @@ -1,6 +1,6 @@ import { Form, message, Space } from 'antd'; import { useTranslation } from 'react-i18next'; -import { useMemo, useRef, useState } from 'react'; +import { useRef, useState } from 'react'; import { useForm } from 'antd/es/form/Form'; import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style'; diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx index 0d3b1c105..3597027e5 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx @@ -1,4 +1,4 @@ -import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { cleanup, fireEvent, act } from '@testing-library/react'; import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; import { Form } from 'antd'; diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.tsx index 6004d9a51..4f9a82011 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.tsx +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.tsx @@ -34,7 +34,11 @@ const ConfigField = () => { } ]} > - + { } ]} > - + { } ]} > - + { } ]} > - + { }) ]} > - + ); diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap b/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap index 4ff8bbb6c..e1dcadc3d 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap @@ -2379,3 +2379,2383 @@ exports[`base/System/PushNotification/SMTPSetting/ render validator Port 4`] = `
`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be same 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be same 2`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigField render snap 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator Port 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator Port 2`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator Port 3`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator Port 4`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+ +`; diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/index.test.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/index.test.tsx new file mode 100644 index 000000000..bc026e109 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/index.test.tsx @@ -0,0 +1,152 @@ +import SMTPSetting from '.'; + +import system from '../../../../testUtils/mockApi/system'; + +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { getAllBySelector, getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +describe('base/System/PushNotification/SMTPSetting', () => { + let requestGetSMTPConfiguration: jest.SpyInstance; + let requestUpdateSMTPConfiguration: jest.SpyInstance; + const customRender = () => { + return renderWithTheme(); + }; + + beforeEach(() => { + jest.useFakeTimers(); + requestGetSMTPConfiguration = system.getSMTPConfig(); + requestUpdateSMTPConfiguration = system.updateSMTPConfig(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + it('render snap', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + await act(async () => jest.advanceTimersByTime(2600)); + expect(requestGetSMTPConfiguration).toBeCalled(); + expect(baseElement).toMatchSnapshot(); + }); + + describe('render switch cancel btn', () => { + it('render snap when click cont cancel btn', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + expect(screen.getByText('启用邮件推送')).toBeInTheDocument(); + + const switchEle = getAllBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + expect(switchEle.length).toBe(2); + fireEvent.click(switchEle[0]); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + expect(screen.getByText('取 消')).toBeInTheDocument(); + fireEvent.click(screen.getByText('取 消')); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when click switch change', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + const switchEle = getAllBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle[0]); + await act(async () => jest.advanceTimersByTime(500)); + expect(screen.getByText('是否确认关闭当前配置?')).toBeInTheDocument(); + expect(screen.getByText('Cancel')).toBeInTheDocument(); + expect(screen.getByText('OK')).toBeInTheDocument(); + + fireEvent.click(screen.getByText('Cancel')); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(switchEle[0]); + await act(async () => jest.advanceTimersByTime(500)); + fireEvent.click(screen.getByText('OK')); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }) + }); + + describe('render submit SMTP setting', () => { + it('render submit success', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + const switchEle = getAllBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle[0]); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.change(getBySelector('#host', baseElement), { + target: { + value: '10.10.10.1' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + fireEvent.change(getBySelector('#port', baseElement), { + target: { + value: '8080' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + fireEvent.change(getBySelector('#username', baseElement), { + target: { + value: '1@a.com' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + fireEvent.change(getBySelector('#password', baseElement), { + target: { + value: '123' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + fireEvent.change(getBySelector('#passwordConfirm', baseElement), { + target: { + value: '123' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + expect(screen.getByText('提 交')).toBeInTheDocument(); + fireEvent.click(screen.getByText('提 交')); + await act(async () => jest.advanceTimersByTime(300)); + expect(baseElement).toMatchSnapshot(); + await act(async () => jest.advanceTimersByTime(3000)); + expect(requestUpdateSMTPConfiguration).toBeCalled(); + expect(requestUpdateSMTPConfiguration).toBeCalledWith({ + smtp_configuration: { + enable_smtp_notify: true, + is_skip_verify: undefined, + smtp_host: '10.10.10.1', + smtp_password: '123', + smtp_port: '8080', + smtp_username: '1@a.com' + } + }); + await act(async () => jest.advanceTimersByTime(3000)); + expect(requestGetSMTPConfiguration).toBeCalled(); + }) + }); +}); From 4e05f2e9d1dac405e2b1035c15ceec0ab50288b2 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 13:59:45 +0800 Subject: [PATCH 18/27] case ConfigExtraButtons --- .../components/ConfigExtraButtons.test.tsx | 136 ++++ .../Wechat/components/ConfigExtraButtons.tsx | 8 +- .../ConfigExtraButtons.test.tsx.snap | 615 ++++++++++++++++++ 3 files changed, 757 insertions(+), 2 deletions(-) create mode 100644 packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.test.tsx create mode 100644 packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigExtraButtons.test.tsx.snap diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.test.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.test.tsx new file mode 100644 index 000000000..1a6ba1013 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.test.tsx @@ -0,0 +1,136 @@ +import ConfigExtraButtons, { typeConfigExtraButtons } from './ConfigExtraButtons'; + +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +import system from '../../../../../testUtils/mockApi/system'; +import { createSpyErrorResponse } from '@actiontech/shared/lib/testUtil/mockApi'; + +describe('base/System/PushNotification/Wechat/ConfigExtraButtons', () => { + let requestTestWeChatConfiguration: jest.SpyInstance; + const handleClickModifyFn = jest.fn(); + const customRender = ( + params: Omit + ) => { + return renderWithTheme( + + ); + }; + + beforeEach(() => { + jest.useFakeTimers(); + requestTestWeChatConfiguration = system.testWeChatConfig(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + describe('render snap when hidden val is true', () => { + it('render isConfigClosed is true', () => { + const { baseElement } = customRender({ + isConfigClosed: true, + extraButtonsVisible: true, + enabled: false + }); + expect(baseElement).toMatchSnapshot(); + }); + it('render extraButtonsVisible is false', () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: false, + enabled: false + }); + expect(baseElement).toMatchSnapshot(); + }); + }); + + describe('render snap form', () => { + it('render popover cancel btn', async () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true + }); + + const btnPopoverOpen = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.click(btnPopoverOpen); + await act(async () => jest.advanceTimersByTime(500)); + expect(screen.getByText('取 消')).toBeInTheDocument(); + await act(async () => jest.advanceTimersByTime(300)); + expect(baseElement).toMatchSnapshot(); + }); + + it('render form validate', async () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true + }); + const btnPopoverOpen = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.click(btnPopoverOpen); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + expect( + getBySelector('input[ placeholder="请输入接收者UserID"]', baseElement) + ).toBeInTheDocument(); + + fireEvent.change(getBySelector('#receiveId', baseElement), { + target: { + value: 'id val' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(screen.getByText('确 认')); + await act(async () => jest.advanceTimersByTime(3300)); + expect(requestTestWeChatConfiguration).toBeCalled(); + expect(requestTestWeChatConfiguration).toBeCalledWith({ + test_wechat_configuration: { + recipient_id: 'id val' + } + }); + }); + + it('render form when api error', async () => { + requestTestWeChatConfiguration.mockImplementation(() => + createSpyErrorResponse({ error_message: 'error info' }) + ); + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true + }); + + const btnPopoverOpen = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.click(btnPopoverOpen); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.change(getBySelector('#receiveId', baseElement), { + target: { + value: 'id val2' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + fireEvent.click(screen.getByText('确 认')); + await act(async () => jest.advanceTimersByTime(3300)); + expect(requestTestWeChatConfiguration).toBeCalledWith({ + test_wechat_configuration: { + recipient_id: 'id val2' + } + }); + }) + }) +}); diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.tsx index 825e405ad..672d72a34 100644 --- a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.tsx +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.tsx @@ -14,7 +14,7 @@ import { BasicInput } from '@actiontech/shared'; import dms from '@actiontech/shared/lib/api/base/service/dms'; -type typeConfigExtraButtons = { +export type typeConfigExtraButtons = { extraButtonsVisible: boolean; isConfigClosed: boolean; enabled: string | boolean | undefined; @@ -110,7 +110,11 @@ const ConfigExtraButtons = ({ } ]} > - + diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigExtraButtons.test.tsx.snap b/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigExtraButtons.test.tsx.snap new file mode 100644 index 000000000..18043b588 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigExtraButtons.test.tsx.snap @@ -0,0 +1,615 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/Wechat/ConfigExtraButtons render snap form render form validate 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/Wechat/ConfigExtraButtons render snap form render popover cancel btn 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/Wechat/ConfigExtraButtons render snap when hidden val is true render extraButtonsVisible is false 1`] = ` + +
+ +
+ +`; + +exports[`base/System/PushNotification/Wechat/ConfigExtraButtons render snap when hidden val is true render isConfigClosed is true 1`] = ` + +
+ +
+ +`; From b9c96cb8c3e420dd5e171d3608a6b8276c81d8df Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 14:03:42 +0800 Subject: [PATCH 19/27] case ConfigField --- .../Wechat/components/ConfigField.test.tsx | 15 ++ .../Wechat/components/ConfigField.tsx | 24 +- .../__snapshots__/ConfigField.test.tsx.snap | 250 ++++++++++++++++++ 3 files changed, 285 insertions(+), 4 deletions(-) create mode 100644 packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx create mode 100644 packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigField.test.tsx.snap diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx new file mode 100644 index 000000000..ff69f49e7 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx @@ -0,0 +1,15 @@ +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; + +import { Form } from 'antd'; +import ConfigField from './ConfigField'; + +describe('base/System/PushNotification/Wechat/ConfigField', () => { + it('render snap', () => { + const { baseElement } = renderWithTheme( +
+ + + ); + expect(baseElement).toMatchSnapshot(); + }); +}); diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.tsx index feed8607e..79d852fd8 100644 --- a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.tsx +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.tsx @@ -18,7 +18,11 @@ const ConfigField = () => { } ]} > - + { } ]} > - + { } ]} > - + { - + ); diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigField.test.tsx.snap b/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigField.test.tsx.snap new file mode 100644 index 000000000..3e1d7f5dc --- /dev/null +++ b/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigField.test.tsx.snap @@ -0,0 +1,250 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/Wechat/ConfigField render snap 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +`; From 1a4beab1d7d94fd6f11ff25d2b6a72f9fba1f8dc Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 14:29:43 +0800 Subject: [PATCH 20/27] case Wechat --- .../Wechat/__snapshots__/index.test.tsx.snap | 3132 +++++++++++++++++ .../Wechat/components/ConfigField.test.tsx | 42 +- .../__snapshots__/ConfigField.test.tsx.snap | 520 +++ .../PushNotification/Wechat/index.test.tsx | 147 + 4 files changed, 3838 insertions(+), 3 deletions(-) create mode 100644 packages/base/src/page/System/PushNotification/Wechat/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/PushNotification/Wechat/index.test.tsx diff --git a/packages/base/src/page/System/PushNotification/Wechat/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/PushNotification/Wechat/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..29a447a3f --- /dev/null +++ b/packages/base/src/page/System/PushNotification/Wechat/__snapshots__/index.test.tsx.snap @@ -0,0 +1,3132 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/Wechat render snap 1`] = ` + +
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/Wechat render snap 2`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/Wechat render submit wechat setting render submit success 1`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/Wechat render switch cancel btn render snap when click cont cancel btn 1`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/Wechat render switch cancel btn render snap when click cont cancel btn 2`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/Wechat render switch cancel btn render snap when click switch change 1`] = ` + +
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx index ff69f49e7..b38934669 100644 --- a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx @@ -1,15 +1,51 @@ import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; import { Form } from 'antd'; import ConfigField from './ConfigField'; describe('base/System/PushNotification/Wechat/ConfigField', () => { - it('render snap', () => { - const { baseElement } = renderWithTheme( + const customRender = () => { + return renderWithTheme(
- ); + ) + }; + + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + it('render snap', () => { + const { baseElement } = customRender(); + expect(baseElement).toMatchSnapshot(); + }); + + it('render validate agent_id item', async () => { + const { baseElement } = customRender(); + + fireEvent.change(getBySelector('#agent_id', baseElement), { + target: { + value: 'agent_id' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + fireEvent.change(getBySelector('#agent_id', baseElement), { + target: { + value: '123' + } + }); + await act(async () => jest.advanceTimersByTime(500)); expect(baseElement).toMatchSnapshot(); }); }); diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigField.test.tsx.snap b/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigField.test.tsx.snap index 3e1d7f5dc..30122d186 100644 --- a/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigField.test.tsx.snap +++ b/packages/base/src/page/System/PushNotification/Wechat/components/__snapshots__/ConfigField.test.tsx.snap @@ -248,3 +248,523 @@ exports[`base/System/PushNotification/Wechat/ConfigField render snap 1`] = `
`; + +exports[`base/System/PushNotification/Wechat/ConfigField render validate agent_id item 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/Wechat/ConfigField render validate agent_id item 2`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+ +`; diff --git a/packages/base/src/page/System/PushNotification/Wechat/index.test.tsx b/packages/base/src/page/System/PushNotification/Wechat/index.test.tsx new file mode 100644 index 000000000..26b75ecfd --- /dev/null +++ b/packages/base/src/page/System/PushNotification/Wechat/index.test.tsx @@ -0,0 +1,147 @@ +import Wechat from '.'; + +import system from '../../../../testUtils/mockApi/system'; + +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { getAllBySelector, getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +describe('base/System/PushNotification/Wechat', () => { + let requestGetWeChatConfiguration: jest.SpyInstance; + let requestUpdateWeChatConfiguration: jest.SpyInstance; + const customRender = () => { + return renderWithTheme(); + }; + + beforeEach(() => { + jest.useFakeTimers(); + requestGetWeChatConfiguration = system.getWeChatConfig(); + requestUpdateWeChatConfiguration = system.updateWeChatConfig(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + it('render snap', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + await act(async () => jest.advanceTimersByTime(2600)); + expect(requestGetWeChatConfiguration).toBeCalled(); + expect(baseElement).toMatchSnapshot(); + }); + + describe('render switch cancel btn', () => { + it('render snap when click cont cancel btn', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + expect(screen.getByText('是否启用微信通知')).toBeInTheDocument(); + + const switchEle = getAllBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + expect(switchEle.length).toBe(2); + fireEvent.click(switchEle[0]); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + expect(screen.getByText('取 消')).toBeInTheDocument(); + fireEvent.click(screen.getByText('取 消')); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when click switch change', async () => { + const { baseElement } = customRender(); + await act(async () => jest.advanceTimersByTime(3300)); + + const switchEle = getAllBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle[0]); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(switchEle[0]); + await act(async () => jest.advanceTimersByTime(500)); + expect( + screen.getByText( + '关闭配置后当前的编辑信息将不会被保留,是否确认关闭配置?' + ) + ).toBeInTheDocument(); + expect(screen.getByText('Cancel')).toBeInTheDocument(); + expect(screen.getByText('OK')).toBeInTheDocument(); + + fireEvent.click(screen.getByText('Cancel')); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(switchEle[0]); + await act(async () => jest.advanceTimersByTime(500)); + fireEvent.click(screen.getByText('OK')); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); + }) + + describe('render submit wechat setting', () => { + it('render submit success', async () => { + const { baseElement } = customRender(); + await act(async () => jest.advanceTimersByTime(3300)); + const switchEle = getAllBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle[0]); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.change(getBySelector('#corp_id', baseElement), { + target: { + value: 'corp id' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + fireEvent.change(getBySelector('#agent_id', baseElement), { + target: { + value: '1234' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + fireEvent.change(getBySelector('#corp_secret', baseElement), { + target: { + value: 'abcd' + } + }); + await act(async () => jest.advanceTimersByTime(300)); + + expect(screen.getByText('提 交')).toBeInTheDocument(); + fireEvent.click(screen.getByText('提 交')); + await act(async () => jest.advanceTimersByTime(300)); + expect(baseElement).toMatchSnapshot(); + await act(async () => jest.advanceTimersByTime(3000)); + expect(requestUpdateWeChatConfiguration).toBeCalled(); + expect(requestUpdateWeChatConfiguration).toBeCalledWith({ + update_wechat_configuration: { + enable_wechat_notify: true, + corp_id: 'corp id', + corp_secret: 'abcd', + agent_id: 1234, + safe_enabled: false, + proxy_ip: '1.1.1.1' + } + }); + + await act(async () => jest.advanceTimersByTime(3000)); + expect(requestGetWeChatConfiguration).toBeCalled(); + }); + + + }) +}); From 0bfc53776d7dd584d6fe34dbcb0cf3befe9ccd58 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 15:16:20 +0800 Subject: [PATCH 21/27] case ConfigExtraButtons --- .../components/ConfigExtraButtons.test.tsx | 98 +++ .../components/ConfigExtraButtons.tsx | 2 +- .../ConfigExtraButtons.test.tsx.snap | 567 ++++++++++++++++++ 3 files changed, 666 insertions(+), 1 deletion(-) create mode 100644 packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.test.tsx create mode 100644 packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigExtraButtons.test.tsx.snap diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.test.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.test.tsx new file mode 100644 index 000000000..299776d4d --- /dev/null +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.test.tsx @@ -0,0 +1,98 @@ +import ConfigExtraButtons, { + ConfigExtraButtonsProps +} from './ConfigExtraButtons'; + +import { cleanup, fireEvent, act } from '@testing-library/react'; +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +import system from '../../../../../testUtils/mockApi/system'; +import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil/mockApi'; + +describe('base/System/PushNotification/WebhookSetting/ConfigExtraButtons', () => { + let requestTestWebHookConfiguration: jest.SpyInstance; + const handleClickModifyFn = jest.fn(); + const customRender = ( + params: Omit + ) => { + return renderWithTheme( + + ); + }; + + beforeEach(() => { + jest.useFakeTimers(); + requestTestWebHookConfiguration = system.testWebhookConfig(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + describe('render snap when hidden val is true', () => { + it('render isConfigClosed is true', () => { + const { baseElement } = customRender({ + isConfigClosed: true, + extraButtonsVisible: true, + enabled: false, + msgUrl: '' + }); + expect(baseElement).toMatchSnapshot(); + }); + + it('render extraButtonsVisible is false', () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: false, + enabled: false, + msgUrl: 'a.com' + }); + expect(baseElement).toMatchSnapshot(); + }); + }); + + describe('render snap form', () => { + it('render submit btn event change', async () => { + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true, + msgUrl: '' + }); + + const btnSubmit = getBySelector( + '.ant-btn[type="submit"]', + baseElement + ); + fireEvent.mouseOver(btnSubmit); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + fireEvent.click(btnSubmit); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + await act(async () => jest.advanceTimersByTime(2600)); + expect(requestTestWebHookConfiguration).toBeCalled(); + }); + + it('render submit btn when api error', async () => { + requestTestWebHookConfiguration.mockImplementation(() => + createSpySuccessResponse({ send_error_message: 'error info' }) + ); + const { baseElement } = customRender({ + isConfigClosed: false, + extraButtonsVisible: true, + enabled: true, + msgUrl: '' + }); + + const btnSubmit = getBySelector('.ant-btn[type="submit"]', baseElement); + fireEvent.click(btnSubmit); + await act(async () => jest.advanceTimersByTime(3300)); + expect(requestTestWebHookConfiguration).toBeCalled(); + expect(baseElement).toMatchSnapshot(); + }) + }); +}); diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.tsx index 63d9c6c9b..048daeaa7 100644 --- a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.tsx +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.tsx @@ -9,7 +9,7 @@ import { IconTest } from '../../../../../icon/system'; import dms from '@actiontech/shared/lib/api/base/service/dms'; import { ResponseCode } from '@actiontech/shared/lib/enum'; -interface ConfigExtraButtonsProps { +export interface ConfigExtraButtonsProps { enabled: string | number | boolean; isConfigClosed: boolean; extraButtonsVisible: boolean; diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigExtraButtons.test.tsx.snap b/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigExtraButtons.test.tsx.snap new file mode 100644 index 000000000..1b8629014 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigExtraButtons.test.tsx.snap @@ -0,0 +1,567 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/WebhookSetting/ConfigExtraButtons render snap form render submit btn event change 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/WebhookSetting/ConfigExtraButtons render snap form render submit btn event change 2`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + + + + 正在向推送测试信息... + +
+
+
+
+ +`; + +exports[`base/System/PushNotification/WebhookSetting/ConfigExtraButtons render snap form render submit btn when api error 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ + + + + 未知错误... + +
+
+
+
+ +`; + +exports[`base/System/PushNotification/WebhookSetting/ConfigExtraButtons render snap when hidden val is true render extraButtonsVisible is false 1`] = ` + +
+ +
+ +`; + +exports[`base/System/PushNotification/WebhookSetting/ConfigExtraButtons render snap when hidden val is true render isConfigClosed is true 1`] = ` + +
+ +
+ +`; From 5796c3463e54c0a3e480a2129dede01733d538d8 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 15:24:24 +0800 Subject: [PATCH 22/27] case ConfigField --- .../components/ConfigField.test.tsx | 2 +- .../components/ConfigField.test.tsx | 19 ++ .../__snapshots__/ConfigField.test.tsx.snap | 305 ++++++++++++++++++ 3 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.test.tsx create mode 100644 packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigField.test.tsx.snap diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx index 3597027e5..535390796 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/ConfigField.test.tsx @@ -1,9 +1,9 @@ import { cleanup, fireEvent, act } from '@testing-library/react'; import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; import { Form } from 'antd'; import ConfigField from './ConfigField'; -import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; describe('base/System/PushNotification/SMTPSetting/ConfigField', () => { const customRender = () => { diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.test.tsx new file mode 100644 index 000000000..64dae108d --- /dev/null +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.test.tsx @@ -0,0 +1,19 @@ +import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; + +import { Form } from 'antd'; +import ConfigField from './ConfigField'; + +describe('base/System/PushNotification/WebhookSetting/ConfigField', () => { + const customRender = () => { + return renderWithTheme( +
+ + + ); + }; + + it('render snap', () => { + const { baseElement } = customRender(); + expect(baseElement).toMatchSnapshot(); + }) +}); diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigField.test.tsx.snap b/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigField.test.tsx.snap new file mode 100644 index 000000000..3e412322f --- /dev/null +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigField.test.tsx.snap @@ -0,0 +1,305 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/WebhookSetting/ConfigField render snap 1`] = ` + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +`; From 34a37a268c18e7e66a155448c9b51f55fc236d83 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 15:49:58 +0800 Subject: [PATCH 23/27] case WebhookSetting --- .../SMTPSetting/index.test.tsx | 9 +- .../__snapshots__/index.test.tsx.snap | 3635 +++++++++++++++++ .../components/ConfigExtraButtons.test.tsx | 7 +- .../components/ConfigField.test.tsx | 22 +- .../WebhookSetting/components/ConfigField.tsx | 6 +- .../__snapshots__/ConfigField.test.tsx.snap | 304 ++ .../WebhookSetting/index.test.tsx | 142 + .../components/ConfigExtraButtons.test.tsx | 8 +- .../Wechat/components/ConfigField.test.tsx | 2 +- .../PushNotification/Wechat/index.test.tsx | 11 +- 10 files changed, 4127 insertions(+), 19 deletions(-) create mode 100644 packages/base/src/page/System/PushNotification/WebhookSetting/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/PushNotification/WebhookSetting/index.test.tsx diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/index.test.tsx b/packages/base/src/page/System/PushNotification/SMTPSetting/index.test.tsx index bc026e109..447ea05a0 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/index.test.tsx +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/index.test.tsx @@ -4,7 +4,10 @@ import system from '../../../../testUtils/mockApi/system'; import { cleanup, fireEvent, act, screen } from '@testing-library/react'; import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; -import { getAllBySelector, getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; +import { + getAllBySelector, + getBySelector +} from '@actiontech/shared/lib/testUtil/customQuery'; describe('base/System/PushNotification/SMTPSetting', () => { let requestGetSMTPConfiguration: jest.SpyInstance; @@ -79,7 +82,7 @@ describe('base/System/PushNotification/SMTPSetting', () => { fireEvent.click(screen.getByText('OK')); await act(async () => jest.advanceTimersByTime(500)); expect(baseElement).toMatchSnapshot(); - }) + }); }); describe('render submit SMTP setting', () => { @@ -147,6 +150,6 @@ describe('base/System/PushNotification/SMTPSetting', () => { }); await act(async () => jest.advanceTimersByTime(3000)); expect(requestGetSMTPConfiguration).toBeCalled(); - }) + }); }); }); diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/PushNotification/WebhookSetting/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..c3b7e5315 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/__snapshots__/index.test.tsx.snap @@ -0,0 +1,3635 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/System/PushNotification/WebhookSetting render snap 1`] = ` + +
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/WebhookSetting render snap 2`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/WebhookSetting render switch cancel btn render snap when click cont cancel btn 1`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/WebhookSetting render switch cancel btn render snap when click cont cancel btn 2`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +`; + +exports[`base/System/PushNotification/WebhookSetting render switch cancel btn render snap when click switch change 1`] = ` + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+ +`; + +exports[`base/System/PushNotification/WebhookSetting render switch cancel btn render snap when click switch change 2`] = ` + +
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +`; diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.test.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.test.tsx index 299776d4d..27201ea9a 100644 --- a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.test.tsx +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigExtraButtons.test.tsx @@ -62,10 +62,7 @@ describe('base/System/PushNotification/WebhookSetting/ConfigExtraButtons', () => msgUrl: '' }); - const btnSubmit = getBySelector( - '.ant-btn[type="submit"]', - baseElement - ); + const btnSubmit = getBySelector('.ant-btn[type="submit"]', baseElement); fireEvent.mouseOver(btnSubmit); await act(async () => jest.advanceTimersByTime(500)); expect(baseElement).toMatchSnapshot(); @@ -93,6 +90,6 @@ describe('base/System/PushNotification/WebhookSetting/ConfigExtraButtons', () => await act(async () => jest.advanceTimersByTime(3300)); expect(requestTestWebHookConfiguration).toBeCalled(); expect(baseElement).toMatchSnapshot(); - }) + }); }); }); diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.test.tsx index 64dae108d..3df37ceba 100644 --- a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.test.tsx +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.test.tsx @@ -1,4 +1,6 @@ import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; +import { act, cleanup, fireEvent } from '@testing-library/react'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; import { Form } from 'antd'; import ConfigField from './ConfigField'; @@ -12,8 +14,26 @@ describe('base/System/PushNotification/WebhookSetting/ConfigField', () => { ); }; + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + it('render snap', () => { const { baseElement } = customRender(); expect(baseElement).toMatchSnapshot(); - }) + }); + + it('render validate url', async () => { + const { baseElement } = customRender(); + + fireEvent.change(getBySelector('#url', baseElement)); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); }); diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.tsx index 1b835d447..86e89f806 100644 --- a/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.tsx +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/ConfigField.tsx @@ -46,7 +46,11 @@ const ConfigField = () => { - + ); diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigField.test.tsx.snap b/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigField.test.tsx.snap index 3e412322f..363a93bbe 100644 --- a/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigField.test.tsx.snap +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/components/__snapshots__/ConfigField.test.tsx.snap @@ -290,6 +290,56 @@ exports[`base/System/PushNotification/WebhookSetting/ConfigField render snap 1`] +
+
+
+
+
+ +
+ +`; + +exports[`base/System/PushNotification/WebhookSetting/ConfigField render validate url 1`] = ` + +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/index.test.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/index.test.tsx new file mode 100644 index 000000000..a67d8a68f --- /dev/null +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/index.test.tsx @@ -0,0 +1,142 @@ +import system from '../../../../testUtils/mockApi/system'; + +import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { superRender } from '@actiontech/shared/lib/testUtil/customRender'; +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; + +import WebHook from '.'; + +describe('base/System/PushNotification/WebhookSetting', () => { + let requestGetWebHookConfiguration: jest.SpyInstance; + let requestUpdateWebHookConfiguration: jest.SpyInstance; + + const customRender = () => { + return superRender(); + }; + + beforeEach(() => { + jest.useFakeTimers(); + requestGetWebHookConfiguration = system.getWebhookConfig(); + requestUpdateWebHookConfiguration = system.updateWebhookConfig(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + it('render snap', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + await act(async () => jest.advanceTimersByTime(2600)); + expect(requestGetWebHookConfiguration).toBeCalled(); + expect(baseElement).toMatchSnapshot(); + }); + + describe('render switch cancel btn', () => { + it('render snap when click cont cancel btn', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + expect(screen.getByText('是否开启Webhook通知')).toBeInTheDocument(); + + const switchEle = getBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + + expect(screen.getByText('取 消')).toBeInTheDocument(); + fireEvent.click(screen.getByText('取 消')); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); + + it('render snap when click switch change', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + + const switchEle = getBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + expect( + screen.getByText( + '关闭配置后当前的编辑信息将不会被保留,是否确认关闭配置?' + ) + ).toBeInTheDocument(); + expect(screen.getByText('Cancel')).toBeInTheDocument(); + expect(screen.getByText('OK')).toBeInTheDocument(); + + fireEvent.click(screen.getByText('Cancel')); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + fireEvent.click(screen.getByText('OK')); + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + }); + }); + + describe('render submit lark setting', () => { + it.only('render submit success', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(3300)); + const switchEle = getBySelector( + '.basic-switch-wrapper .ant-switch-inner', + baseElement + ); + fireEvent.click(switchEle); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.change(getBySelector('#url', baseElement), { + target: { + value: 'http://a.com' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.change(getBySelector('#maxRetryTimes', baseElement), { + target: { + value: '1' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + + fireEvent.change(getBySelector('#retryIntervalSeconds', baseElement), { + target: { + value: '2' + } + }); + await act(async () => jest.advanceTimersByTime(500)); + + expect(screen.getByText('提 交')).toBeInTheDocument(); + fireEvent.click(screen.getByText('提 交')); + await act(async () => jest.advanceTimersByTime(500)); + expect(requestUpdateWebHookConfiguration).toBeCalled(); + expect(requestUpdateWebHookConfiguration).toBeCalledWith({ + webhook_config: { + enable: true, + max_retry_times: 1, + retry_interval_seconds: 2, + token: undefined, + url: 'http://a.com' + } + }); + }); + }); +}); diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.test.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.test.tsx index 1a6ba1013..a5ba45125 100644 --- a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.test.tsx +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigExtraButtons.test.tsx @@ -1,4 +1,6 @@ -import ConfigExtraButtons, { typeConfigExtraButtons } from './ConfigExtraButtons'; +import ConfigExtraButtons, { + typeConfigExtraButtons +} from './ConfigExtraButtons'; import { cleanup, fireEvent, act, screen } from '@testing-library/react'; import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; @@ -131,6 +133,6 @@ describe('base/System/PushNotification/Wechat/ConfigExtraButtons', () => { recipient_id: 'id val2' } }); - }) - }) + }); + }); }); diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx index b38934669..df8ebf19f 100644 --- a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx @@ -11,7 +11,7 @@ describe('base/System/PushNotification/Wechat/ConfigField', () => {
- ) + ); }; beforeEach(() => { diff --git a/packages/base/src/page/System/PushNotification/Wechat/index.test.tsx b/packages/base/src/page/System/PushNotification/Wechat/index.test.tsx index 26b75ecfd..c0ae72b07 100644 --- a/packages/base/src/page/System/PushNotification/Wechat/index.test.tsx +++ b/packages/base/src/page/System/PushNotification/Wechat/index.test.tsx @@ -4,7 +4,10 @@ import system from '../../../../testUtils/mockApi/system'; import { cleanup, fireEvent, act, screen } from '@testing-library/react'; import { renderWithTheme } from '@actiontech/shared/lib/testUtil/customRender'; -import { getAllBySelector, getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; +import { + getAllBySelector, + getBySelector +} from '@actiontech/shared/lib/testUtil/customQuery'; describe('base/System/PushNotification/Wechat', () => { let requestGetWeChatConfiguration: jest.SpyInstance; @@ -87,7 +90,7 @@ describe('base/System/PushNotification/Wechat', () => { await act(async () => jest.advanceTimersByTime(500)); expect(baseElement).toMatchSnapshot(); }); - }) + }); describe('render submit wechat setting', () => { it('render submit success', async () => { @@ -141,7 +144,5 @@ describe('base/System/PushNotification/Wechat', () => { await act(async () => jest.advanceTimersByTime(3000)); expect(requestGetWeChatConfiguration).toBeCalled(); }); - - - }) + }); }); From 7a8fa10c29a87210e86a03b9329c0531904c9493 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 15:59:25 +0800 Subject: [PATCH 24/27] remove test only code --- .../page/System/PushNotification/WebhookSetting/index.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/base/src/page/System/PushNotification/WebhookSetting/index.test.tsx b/packages/base/src/page/System/PushNotification/WebhookSetting/index.test.tsx index a67d8a68f..aa36a7603 100644 --- a/packages/base/src/page/System/PushNotification/WebhookSetting/index.test.tsx +++ b/packages/base/src/page/System/PushNotification/WebhookSetting/index.test.tsx @@ -92,7 +92,7 @@ describe('base/System/PushNotification/WebhookSetting', () => { }); describe('render submit lark setting', () => { - it.only('render submit success', async () => { + it('render submit success', async () => { const { baseElement } = customRender(); await act(async () => jest.advanceTimersByTime(3300)); From 91491b78f158d64ad4d100d6858a82601f092b7b Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 16:01:13 +0800 Subject: [PATCH 25/27] upgrade snap --- .../__snapshots__/ConfigField.test.tsx.snap | 2450 +---------------- .../__snapshots__/index.test.tsx.snap | 12 +- 2 files changed, 41 insertions(+), 2421 deletions(-) diff --git a/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap b/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap index e1dcadc3d..300569049 100644 --- a/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap +++ b/packages/base/src/page/System/PushNotification/SMTPSetting/components/__snapshots__/ConfigField.test.tsx.snap @@ -1,2385 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`base/System/PushNotification/SMTPSetting/ render pwd must be same 1`] = ` - -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
-
-
- -
- -`; - -exports[`base/System/PushNotification/SMTPSetting/ render pwd must be same 2`] = ` - -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
-
-
- -
- -`; - -exports[`base/System/PushNotification/SMTPSetting/ render snap 1`] = ` - -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
- -`; - -exports[`base/System/PushNotification/SMTPSetting/ render validator Port 1`] = ` - -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
- -
- -`; - -exports[`base/System/PushNotification/SMTPSetting/ render validator Port 2`] = ` - -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
- -
- -`; - -exports[`base/System/PushNotification/SMTPSetting/ render validator Port 3`] = ` - -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
- -
- -`; - -exports[`base/System/PushNotification/SMTPSetting/ render validator Port 4`] = ` - -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
-
-
-
- -
-
-
-
- - - - - - - - -
-
-
-
-
- -
- -`; - exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be same 1`] = `
@@ -2479,7 +99,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="host" - placeholder="请输入{{name}}" + placeholder="请输入SMTP地址" type="text" value="" /> @@ -2518,7 +138,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="port" - placeholder="请输入{{name}}" + placeholder="请输入SMTP端口" type="text" value="" /> @@ -2557,7 +177,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="username" - placeholder="请输入{{name}}" + placeholder="请输入SMTP用户名" type="text" value="" /> @@ -2599,7 +219,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be aria-required="true" class="ant-input css-dev-only-do-not-override-txh9fw" id="password" - placeholder="请输入{{name}}" + placeholder="请输入SMTP密码" type="password" /> @@ -2822,7 +442,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="host" - placeholder="请输入{{name}}" + placeholder="请输入SMTP地址" type="text" value="" /> @@ -2861,7 +481,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="port" - placeholder="请输入{{name}}" + placeholder="请输入SMTP端口" type="text" value="" /> @@ -2900,7 +520,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="username" - placeholder="请输入{{name}}" + placeholder="请输入SMTP用户名" type="text" value="" /> @@ -2942,7 +562,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render pwd must be aria-required="true" class="ant-input css-dev-only-do-not-override-txh9fw" id="password" - placeholder="请输入{{name}}" + placeholder="请输入SMTP密码" type="password" /> @@ -3201,7 +821,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render snap 1`] = aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="port" - placeholder="请输入{{name}}" + placeholder="请输入SMTP端口" type="text" value="" /> @@ -3240,7 +860,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render snap 1`] = aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="username" - placeholder="请输入{{name}}" + placeholder="请输入SMTP用户名" type="text" value="" /> @@ -3282,7 +902,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render snap 1`] = aria-required="true" class="ant-input css-dev-only-do-not-override-txh9fw" id="password" - placeholder="请输入{{name}}" + placeholder="请输入SMTP密码" type="password" value="" /> @@ -3352,7 +972,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render snap 1`] = aria-required="true" class="ant-input css-dev-only-do-not-override-txh9fw" id="passwordConfirm" - placeholder="请输入{{name}}" + placeholder="请输入确认SMTP密码" type="password" value="" /> @@ -3493,7 +1113,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="host" - placeholder="请输入{{name}}" + placeholder="请输入SMTP地址" type="text" value="" /> @@ -3534,7 +1154,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input ant-input-status-error css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="port" - placeholder="请输入{{name}}" + placeholder="请输入SMTP端口" type="text" value="a" /> @@ -3584,7 +1204,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="username" - placeholder="请输入{{name}}" + placeholder="请输入SMTP用户名" type="text" value="" /> @@ -3626,7 +1246,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input css-dev-only-do-not-override-txh9fw" id="password" - placeholder="请输入{{name}}" + placeholder="请输入SMTP密码" type="password" /> @@ -3876,7 +1496,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input ant-input-status-error css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="port" - placeholder="请输入{{name}}" + placeholder="请输入SMTP端口" type="text" value="0" /> @@ -3926,7 +1546,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="username" - placeholder="请输入{{name}}" + placeholder="请输入SMTP用户名" type="text" value="" /> @@ -3968,7 +1588,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input css-dev-only-do-not-override-txh9fw" id="password" - placeholder="请输入{{name}}" + placeholder="请输入SMTP密码" type="password" /> @@ -4218,7 +1838,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input ant-input-status-error css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="port" - placeholder="请输入{{name}}" + placeholder="请输入SMTP端口" type="text" value="65536" /> @@ -4268,7 +1888,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="username" - placeholder="请输入{{name}}" + placeholder="请输入SMTP用户名" type="text" value="" /> @@ -4310,7 +1930,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input css-dev-only-do-not-override-txh9fw" id="password" - placeholder="请输入{{name}}" + placeholder="请输入SMTP密码" type="password" /> @@ -4558,7 +2178,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input ant-input-status-success css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="port" - placeholder="请输入{{name}}" + placeholder="请输入SMTP端口" type="text" value="8080" /> @@ -4608,7 +2228,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input css-dev-only-do-not-override-ywkr0o basic-input-wrapper css-1pd1cd5" id="username" - placeholder="请输入{{name}}" + placeholder="请输入SMTP用户名" type="text" value="" /> @@ -4650,7 +2270,7 @@ exports[`base/System/PushNotification/SMTPSetting/ConfigField render validator P aria-required="true" class="ant-input css-dev-only-do-not-override-txh9fw" id="password" - placeholder="请输入{{name}}" + placeholder="请输入SMTP密码" type="password" /> @@ -1082,7 +1082,7 @@ exports[`base/System/PushNotification/WebhookSetting render snap 2`] = ` @@ -1651,7 +1651,7 @@ exports[`base/System/PushNotification/WebhookSetting render switch cancel btn re @@ -2223,7 +2223,7 @@ exports[`base/System/PushNotification/WebhookSetting render switch cancel btn re @@ -2792,7 +2792,7 @@ exports[`base/System/PushNotification/WebhookSetting render switch cancel btn re @@ -3472,7 +3472,7 @@ exports[`base/System/PushNotification/WebhookSetting render switch cancel btn re From c0336d157009a304fe9d4664fc6a8d46f4bcee20 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 16:08:07 +0800 Subject: [PATCH 26/27] case store/system --- packages/base/src/store/system/index.test.ts | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 packages/base/src/store/system/index.test.ts diff --git a/packages/base/src/store/system/index.test.ts b/packages/base/src/store/system/index.test.ts new file mode 100644 index 000000000..52db915a3 --- /dev/null +++ b/packages/base/src/store/system/index.test.ts @@ -0,0 +1,27 @@ +import reducers, { updateWebTitleAndLogo } from '.'; + +import { IReduxState } from '..'; +import { DMS_DEFAULT_WEB_TITLE } from '@actiontech/shared/lib/data/common'; + +describe('store system', () => { + const state: IReduxState['system'] = { + modalStatus: {}, + webTitle: DMS_DEFAULT_WEB_TITLE + }; + + it('should update web info for execute updateWebTitleAndLogo', () => { + const newState = reducers( + state, + updateWebTitleAndLogo({ + webTitle: 'this is a title', + webLogoUrl: 'this is a web logo url' + }) + ); + expect(newState).not.toBe(state); + expect(newState).toEqual({ + modalStatus: {}, + webTitle: 'this is a title', + webLogoUrl: 'this is a web logo url' + }); + }); +}); From e906a937fd2528fbac014cbf4d77f10f6ad30d61 Mon Sep 17 00:00:00 2001 From: xinbinyan <404928130@qq.com> Date: Wed, 24 Jan 2024 16:26:54 +0800 Subject: [PATCH 27/27] case pushNotification --- .../__snapshots__/index.test.tsx.snap | 4269 +++++++++++++++++ .../System/PushNotification/index.test.tsx | 32 + 2 files changed, 4301 insertions(+) create mode 100644 packages/base/src/page/System/PushNotification/__snapshots__/index.test.tsx.snap create mode 100644 packages/base/src/page/System/PushNotification/index.test.tsx diff --git a/packages/base/src/page/System/PushNotification/__snapshots__/index.test.tsx.snap b/packages/base/src/page/System/PushNotification/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000..7ff2f1260 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/__snapshots__/index.test.tsx.snap @@ -0,0 +1,4269 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`base/setting/pushNotification render snap 1`] = ` + +
+
+
+
+
+ 消息推送 +
+
+
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +`; + +exports[`base/setting/pushNotification render snap 2`] = ` + +
+
+
+
+
+ 消息推送 +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + +
+
+ + SMTP地址 + + + 10.10.10.1 + +
+
+
+ + SMTP端口 + + + 3300 + +
+
+
+ + SMTP用户名 + + + currentUser@gamil.com + +
+
+
+ +
+
+ 是否跳过证书认证 +
+
+ + + +
+
+
+ + 否 + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + +
+
+ + App ID + + +
+ app_id +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +`; diff --git a/packages/base/src/page/System/PushNotification/index.test.tsx b/packages/base/src/page/System/PushNotification/index.test.tsx new file mode 100644 index 000000000..01c372ad2 --- /dev/null +++ b/packages/base/src/page/System/PushNotification/index.test.tsx @@ -0,0 +1,32 @@ +import PushNotification from '.'; + +import { superRender } from '@actiontech/shared/lib/testUtil/customRender'; +import { cleanup, act, screen } from '@testing-library/react'; + +import system from '../../../testUtils/mockApi/system'; + +describe('base/setting/pushNotification', () => { + const customRender = () => { + return superRender(); + }; + beforeEach(() => { + jest.useFakeTimers(); + system.mockAllApi(); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + cleanup(); + }); + + it('render snap', async () => { + const { baseElement } = customRender(); + + await act(async () => jest.advanceTimersByTime(500)); + expect(baseElement).toMatchSnapshot(); + await act(async () => jest.advanceTimersByTime(2600)); + expect(baseElement).toMatchSnapshot(); + expect(screen.getByText('消息推送')).toBeInTheDocument(); + }); +});