-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from actiontech/tes/DMS-833
[test]:(Data Export) Add unit tests for common
- Loading branch information
Showing
22 changed files
with
4,805 additions
and
127 deletions.
There are no files selected for viewing
2,973 changes: 2,973 additions & 0 deletions
2,973
...se/src/page/DataExportManagement/Common/AuditResultList/__snapshots__/index.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
150 changes: 150 additions & 0 deletions
150
packages/base/src/page/DataExportManagement/Common/AuditResultList/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...src/page/DataExportManagement/Common/BackToWorkflowList/__snapshots__/index.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; |
12 changes: 12 additions & 0 deletions
12
packages/base/src/page/DataExportManagement/Common/BackToWorkflowList/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
Oops, something went wrong.