|
| 1 | +import { |
| 2 | + renderWithReduxAndTheme, |
| 3 | + renderHooksWithTheme |
| 4 | +} from '@actiontech/shared/lib/testUtil/customRender'; |
| 5 | +import { Form } from 'antd'; |
| 6 | +import SqlManagementExceptionForm from '../index'; |
| 7 | +import { SqlManagementExceptionFormFieldType } from '../../../index.type'; |
| 8 | +import instance from '../../../../../testUtils/mockApi/instance'; |
| 9 | +import { mockUseDbServiceDriver } from '@actiontech/shared/lib/testUtil/mockHook/mockUseDbServiceDriver'; |
| 10 | +import { cleanup, act, screen, fireEvent } from '@testing-library/react'; |
| 11 | +import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; |
| 12 | + |
| 13 | +describe('sqle/SqlManagementException/SqlManagementExceptionForm', () => { |
| 14 | + let getInstanceTipListSpy: jest.SpyInstance; |
| 15 | + beforeEach(() => { |
| 16 | + jest.useFakeTimers(); |
| 17 | + mockUseDbServiceDriver(); |
| 18 | + getInstanceTipListSpy = instance.getInstanceTipList(); |
| 19 | + }); |
| 20 | + |
| 21 | + afterEach(() => { |
| 22 | + jest.useRealTimers(); |
| 23 | + cleanup(); |
| 24 | + }); |
| 25 | + |
| 26 | + const customRender = () => { |
| 27 | + const { result } = renderHooksWithTheme(() => |
| 28 | + Form.useForm<SqlManagementExceptionFormFieldType>() |
| 29 | + ); |
| 30 | + return renderWithReduxAndTheme( |
| 31 | + <SqlManagementExceptionForm form={result.current[0]} /> |
| 32 | + ); |
| 33 | + }; |
| 34 | + |
| 35 | + it('should match snapshot', () => { |
| 36 | + const { baseElement } = customRender(); |
| 37 | + expect(baseElement).toMatchSnapshot(); |
| 38 | + expect(getInstanceTipListSpy).toHaveBeenCalledTimes(1); |
| 39 | + expect(screen.getByLabelText('字符串')).toBeChecked(); |
| 40 | + expect(screen.getByLabelText('SQL语句')).toBeInTheDocument(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('render switch match type ', async () => { |
| 44 | + const { baseElement } = customRender(); |
| 45 | + await act(async () => jest.advanceTimersByTime(3000)); |
| 46 | + |
| 47 | + expect(screen.getByLabelText('字符串')).toBeChecked(); |
| 48 | + expect(screen.getByLabelText('SQL语句')).toBeInTheDocument(); |
| 49 | + |
| 50 | + fireEvent.click(screen.getByText('SQL指纹')); |
| 51 | + await act(async () => jest.advanceTimersByTime(0)); |
| 52 | + expect(screen.getByLabelText('SQL指纹')).toBeChecked(); |
| 53 | + expect(screen.getByLabelText('SQL语句')).toBeInTheDocument(); |
| 54 | + expect(baseElement).toMatchSnapshot(); |
| 55 | + |
| 56 | + fireEvent.click(screen.getByText('IP')); |
| 57 | + await act(async () => jest.advanceTimersByTime(0)); |
| 58 | + expect(getBySelector('#ip')).toBeInTheDocument(); |
| 59 | + expect(baseElement).toMatchSnapshot(); |
| 60 | + |
| 61 | + fireEvent.click(screen.getByText('网段')); |
| 62 | + await act(async () => jest.advanceTimersByTime(0)); |
| 63 | + expect(getBySelector('#cidr')).toBeInTheDocument(); |
| 64 | + expect(baseElement).toMatchSnapshot(); |
| 65 | + |
| 66 | + fireEvent.click(screen.getByText('主机名')); |
| 67 | + await act(async () => jest.advanceTimersByTime(0)); |
| 68 | + expect(getBySelector('#host')).toBeInTheDocument(); |
| 69 | + expect(baseElement).toMatchSnapshot(); |
| 70 | + |
| 71 | + fireEvent.click(screen.getByText('数据源')); |
| 72 | + await act(async () => jest.advanceTimersByTime(0)); |
| 73 | + expect(getBySelector('#instance')).toBeInTheDocument(); |
| 74 | + expect(baseElement).toMatchSnapshot(); |
| 75 | + }); |
| 76 | +}); |
0 commit comments