Skip to content

Commit

Permalink
[test]: Update unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zzyangh committed Sep 11, 2024
1 parent 7c18064 commit 4430366
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
36 changes: 23 additions & 13 deletions packages/sqle/src/page/SqlAudit/List/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,29 @@ describe('sqle/SqlAudit/List', () => {
});

it('render polling request when sql audit status is auditing', async () => {
sqlAuditRecordsSpy.mockImplementation(() =>
createSpySuccessResponse({
data: [
{
...sqlAuditRecordMockData[0],
sql_audit_status: 'auditing'
}
],
total_nums: 2
})
);
sqlAuditRecordsSpy
.mockImplementationOnce(() =>
createSpySuccessResponse({
data: [
{
...sqlAuditRecordMockData[0],
sql_audit_status: 'auditing'
}
],
total_nums: 2
})
)
.mockImplementationOnce(() =>
createSpySuccessResponse({
data: [
{
...sqlAuditRecordMockData[0],
sql_audit_status: 'successfully'
}
],
total_nums: 2
})
);
renderWithReduxAndTheme(customRender());
await act(async () => jest.advanceTimersByTime(3000));
expect(sqlAuditRecordsSpy).toHaveBeenCalledTimes(1);
Expand All @@ -233,7 +245,5 @@ describe('sqle/SqlAudit/List', () => {
renderWithReduxAndTheme(customRender());
await act(async () => jest.advanceTimersByTime(3000));
expect(sqlAuditRecordsSpy).toHaveBeenCalledTimes(1);
await act(async () => jest.advanceTimersByTime(3000));
expect(sqlAuditRecordsSpy).not.toHaveBeenCalledTimes(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,21 @@ describe('page/SqlManagement/SQLEEIndex', () => {

it('render polling request when sql audit status is auditing', async () => {
const request = sqlManage.getSqlManageList();
request.mockImplementation(() =>
createSpySuccessResponse({
data: [
{
...sqlManageListData.data[sqlManageListData.data.length - 1]
}
]
})
);
request
.mockImplementationOnce(() =>
createSpySuccessResponse({
data: [
{
...sqlManageListData.data[sqlManageListData.data.length - 1]
}
]
})
)
.mockImplementationOnce(() =>
createSpySuccessResponse({
data: [sqlManageListData.data[0]]
})
);
superRender(<SQLEEIndex />);
await act(async () => jest.advanceTimersByTime(3000));
expect(request).toHaveBeenCalledTimes(1);
Expand All @@ -622,7 +628,5 @@ describe('page/SqlManagement/SQLEEIndex', () => {
superRender(<SQLEEIndex />);
await act(async () => jest.advanceTimersByTime(3000));
expect(request).toHaveBeenCalledTimes(1);
await act(async () => jest.advanceTimersByTime(3000));
expect(request).not.toHaveBeenCalledTimes(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,31 @@ describe('test ScanTypeSqlCollection', () => {
});

it('should polling request when sql audit status is being_audited', async () => {
getInstanceAuditPlanSQLDataSpy.mockImplementation(() => {
return createSpySuccessResponse({
data: {
rows: [
{
...mockAuditPlanSQLData?.rows?.[0],
audit_results: 'being_audited'
}
]
}
getInstanceAuditPlanSQLDataSpy
.mockImplementationOnce(() => {
return createSpySuccessResponse({
data: {
rows: [
{
...mockAuditPlanSQLData?.rows?.[0],
audit_results: 'being_audited'
}
]
}
});
})
.mockImplementationOnce(() => {
return createSpySuccessResponse({
data: {
rows: [
{
...mockAuditPlanSQLData?.rows?.[0],
audit_results: ''
}
]
}
});
});
});

customRender();
await act(async () => jest.advanceTimersByTime(3000));
Expand All @@ -171,7 +184,5 @@ describe('test ScanTypeSqlCollection', () => {
customRender();
await act(async () => jest.advanceTimersByTime(3000));
expect(getInstanceAuditPlanSQLDataSpy).toHaveBeenCalledTimes(1);
await act(async () => jest.advanceTimersByTime(3000));
expect(getInstanceAuditPlanSQLDataSpy).not.toHaveBeenCalledTimes(2);
});
});

0 comments on commit 4430366

Please sign in to comment.