Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test]:Supplementary testing coverage #216

Merged
merged 6 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import {
BatchGetDataExportTaskResponseData,
ListDataExportTaskSQLsResponseData
} from '../../../../testUtils/mockApi/dataExport/data';
import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil/mockApi';
import {
createSpySuccessResponse,
createSpyFailResponse
} from '@actiontech/shared/lib/testUtil/mockApi';
import { GetDataExportTaskStatusEnum } from '@actiontech/shared/lib/api/base/service/common.enum';
import { getAllBySelector } from '@actiontech/shared/lib/testUtil/customQuery';
import {
getAllBySelector,
getBySelector
} from '@actiontech/shared/lib/testUtil/customQuery';

describe('test DataExport/Common/AuditResultList', () => {
let batchGetTaskSpy: jest.SpyInstance;
Expand Down Expand Up @@ -53,8 +59,79 @@ describe('test DataExport/Common/AuditResultList', () => {
await act(async () => jest.advanceTimersByTime(3000));
expect(baseElement).toMatchSnapshot();

fireEvent.click(getAllBySelector('.audit-result-exec-sql-column')[0]);
fireEvent.click(
getAllBySelector(
'.audit-result-exec-sql-column .ant-typography-ellipsis'
)[0]
);
expect(baseElement).toMatchSnapshot();
expect(getBySelector('.ant-drawer-content-wrapper')).not.toHaveClass(
'ant-drawer-content-wrapper-hidden'
);
await act(async () => jest.advanceTimersByTime(300));
fireEvent.click(getBySelector('.closed-icon-custom'));
await act(async () => jest.advanceTimersByTime(300));
expect(getBySelector('.ant-drawer-content-wrapper')).toHaveClass(
'ant-drawer-content-wrapper-hidden'
);
fireEvent.click(getAllBySelector('.audit-result-column')[1].children[0]);
await act(async () => jest.advanceTimersByTime(300));
expect(getBySelector('.ant-drawer-content-wrapper')).not.toHaveClass(
'ant-drawer-content-wrapper-hidden'
);
});

it('should match snapshot when data is null', async () => {
getTaskSQLsSpy.mockClear();
getTaskSQLsSpy.mockImplementation(() =>
createSpySuccessResponse({
data: [
{
uid: 1,
sql: null,
export_status: '',
export_sql_type: '',
audit_level: '',
audit_sql_result: [
{
level: 'error',
message: '除了自增列及大字段列之外,每个列都必须添加默认值',
rule_name: 'ddl_check_column_without_default',
db_type: ''
}
]
},
{
uid: 2,
sql: 'SELECT 1;',
export_status: '',
export_sql_type: 'dql',
audit_level: '',
audit_sql_result: [
{
level: 'error',
message: '除了自增列及大字段列之外,每个列都必须添加默认值',
rule_name: 'ddl_check_column_without_default',
db_type: ''
},
{
level: null,
message: '主键建议使用 BIGINT 无符号类型,即 BIGINT UNSIGNED',
rule_name: 'ddl_check_pk_without_bigint_unsigned',
db_type: ''
}
]
}
]
})
);
const { container } = superRender(
<AuditResultList taskIDs={taskIDs} projectID={projectID} />
);
await act(async () => jest.advanceTimersByTime(3000));
await act(async () => jest.advanceTimersByTime(3000));
expect(getTaskSQLsSpy).toBeCalledTimes(1);
expect(container).toMatchSnapshot();
});

it('should switch tab when click label', async () => {
Expand Down Expand Up @@ -146,5 +223,21 @@ describe('test DataExport/Common/AuditResultList', () => {
await act(async () => jest.advanceTimersByTime(3000));
expect(updateExecuteSQLsTypeIsDQLSpy).toBeCalledTimes(1);
expect(updateExecuteSQLsTypeIsDQLSpy).toBeCalledWith(false);

jest.clearAllMocks();
cleanup();

getTaskSQLsSpy.mockImplementation(() => createSpyFailResponse({}));
superRender(
<AuditResultList
taskIDs={taskIDs}
projectID={projectID}
updateExecuteSQLsTypeIsDQL={updateExecuteSQLsTypeIsDQLSpy}
/>
);
await act(async () => jest.advanceTimersByTime(3000));
await act(async () => jest.advanceTimersByTime(3000));
expect(updateExecuteSQLsTypeIsDQLSpy).toBeCalledTimes(1);
expect(updateExecuteSQLsTypeIsDQLSpy).toBeCalledWith(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test base/DataSource should match snapshot 1`] = `
<div>
<article
class="data-source-page-project"
/>
</div>
`;
Loading
Loading