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]:(Data Export) Add unit tests for common #209

Merged
merged 2 commits into from
Feb 4, 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
@@ -0,0 +1,150 @@
import { act, cleanup, fireEvent, screen } from '@testing-library/react';
import AuditResultList from '.';
import { superRender } from '../../../../testUtils/customRender';
import dataExport from '../../../../testUtils/mockApi/dataExport';
import {
BatchGetDataExportTaskResponseData,
ListDataExportTaskSQLsResponseData
} from '../../../../testUtils/mockApi/dataExport/data';
import { createSpySuccessResponse } 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';

describe('test DataExport/Common/AuditResultList', () => {
let batchGetTaskSpy: jest.SpyInstance;
let getTaskSQLsSpy: jest.SpyInstance;
const taskIDs = ['1233234654', '324234234'];
const projectID = '400300';

beforeEach(() => {
jest.useFakeTimers();
batchGetTaskSpy = dataExport.BatchGetDataExportTask();
getTaskSQLsSpy = dataExport.ListDataExportTaskSQLs();
});
afterEach(() => {
jest.useRealTimers();
jest.clearAllMocks();
jest.clearAllTimers();
});

it('should match snapshot', async () => {
const { baseElement } = superRender(
<AuditResultList taskIDs={taskIDs} projectID={projectID} />
);
expect(baseElement).toMatchSnapshot();

expect(batchGetTaskSpy).toBeCalledTimes(1);
expect(batchGetTaskSpy).toBeCalledWith({
project_uid: projectID,
data_export_task_uids: '1233234654,324234234'
});

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

expect(getTaskSQLsSpy).toBeCalledTimes(1);
expect(getTaskSQLsSpy).toBeCalledWith({
project_uid: projectID,
data_export_task_uid: BatchGetDataExportTaskResponseData[0].task_uid,
page_index: 1,
page_size: 20
});

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

fireEvent.click(getAllBySelector('.audit-result-exec-sql-column')[0]);
expect(baseElement).toMatchSnapshot();
});

it('should switch tab when click label', async () => {
batchGetTaskSpy.mockImplementation(() =>
createSpySuccessResponse({
data: [
...BatchGetDataExportTaskResponseData,
{
task_uid: '1752623436938612735',
db_info: {
uid: '1752583372904861696',
name: 'test-mysql-1',
db_type: '',
database_name: ''
},
status: GetDataExportTaskStatusEnum.init,
file_name: '',
audit_result: {
audit_level: '',
score: 100,
pass_rate: 1
},
export_type: 'SQL',
export_file_type: 'CSV'
}
]
})
);

const { container } = superRender(
<AuditResultList taskIDs={taskIDs} projectID={projectID} />
);
await act(async () => jest.advanceTimersByTime(3000));

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

fireEvent.click(screen.getByText('test-mysql-1'));
expect(getTaskSQLsSpy).toBeCalledTimes(2);
expect(getTaskSQLsSpy).toBeCalledWith({
project_uid: projectID,
data_export_task_uid: '1752623436938612735',
page_index: 1,
page_size: 20
});
await act(async () => jest.advanceTimersByTime(3000));
expect(container).toMatchSnapshot();
});

it('should execute updateExecuteSQLsTypeIsDQL', async () => {
const updateExecuteSQLsTypeIsDQLSpy = jest.fn();
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);

jest.clearAllMocks();
cleanup();

getTaskSQLsSpy.mockImplementation(() =>
createSpySuccessResponse({
data: [
...ListDataExportTaskSQLsResponseData,
{
uid: 7,
sql: 'INSERT INTO t1 values (name, "test")',
export_status: '',
export_sql_type: 'dml',
audit_level: ''
}
]
})
);
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(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import dms from '@actiontech/shared/lib/api/base/service/dms';
import { IGetDataExportTask } from '@actiontech/shared/lib/api/base/service/common';
import { ResponseCode } from '@actiontech/shared/lib/enum';
import DbServiceSegmentedLabel from '../DbServiceSegmentedLabel';
import { AuditTaskResV1AuditLevelEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum';

const AuditResultList: React.FC<AuditResultListProps> = ({
taskIDs,
Expand Down Expand Up @@ -50,7 +52,15 @@
value={currentTaskID}
onChange={(v) => handleChangeCurrentTask(v as string)}
options={tasks.map((v) => ({
label: v.db_info?.name,
label: (
<DbServiceSegmentedLabel
dbServiceName={v.db_info?.name ?? ''}

Check warning on line 57 in packages/base/src/page/DataExportManagement/Common/AuditResultList/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
auditLevel={
(v.audit_result
?.audit_level as AuditTaskResV1AuditLevelEnum) ?? ''

Check warning on line 60 in packages/base/src/page/DataExportManagement/Common/AuditResultList/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}
/>
),
value: !!v?.task_uid ? `${v.task_uid}` : '',
key: v.task_uid
}))}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test BackToWorkflowList should match snapshot 1`] = `
<div>
<a
href="/project/700300/data/export"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-default basic-button-wrapper css-geipcv"
type="button"
>
<span
class="ant-btn-icon"
>
<svg
fill="none"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M5.21863 7.33333H13.3333V8.66667H5.21863L8.79463 12.2427L7.85196 13.1853L2.66663 8L7.85196 2.81467L8.79463 3.75733L5.21863 7.33333Z"
fill="currentColor"
/>
</svg>
</span>
<span>
返回工单列表
</span>
</button>
</a>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject';
import { superRender } from '../../../../testUtils/customRender';
import BackToWorkflowList from '.';

describe('test BackToWorkflowList', () => {
it('should match snapshot', () => {
mockUseCurrentProject();

const { container } = superRender(<BackToWorkflowList />);
expect(container).toMatchSnapshot();
});
});
Loading
Loading