Skip to content

Commit

Permalink
[test]: Add test case about stop polling request
Browse files Browse the repository at this point in the history
  • Loading branch information
zzyangh committed Sep 10, 2024
1 parent ada74b7 commit 7c18064
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/sqle/src/page/SqlAudit/List/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,23 @@ describe('sqle/SqlAudit/List', () => {
await act(async () => jest.advanceTimersByTime(3000));
expect(sqlAuditRecordsSpy).toHaveBeenCalledTimes(2);
});

it('render stop polling request when sql audit status is not auditing', async () => {
sqlAuditRecordsSpy.mockImplementation(() =>
createSpySuccessResponse({
data: [
{
...sqlAuditRecordMockData[0],
sql_audit_status: 'successfully'
}
],
total_nums: 2
})
);
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 @@ -611,4 +611,18 @@ describe('page/SqlManagement/SQLEEIndex', () => {
await act(async () => jest.advanceTimersByTime(3000));
expect(request).toHaveBeenCalledTimes(2);
});

it('render stop polling request when sql audit status is auditing', async () => {
const request = sqlManage.getSqlManageList();
request.mockImplementation(() =>
createSpySuccessResponse({
data: [sqlManageListData.data[0]]
})
);
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 @@ -153,4 +153,25 @@ describe('test ScanTypeSqlCollection', () => {
await act(async () => jest.advanceTimersByTime(3000));
expect(getInstanceAuditPlanSQLDataSpy).toHaveBeenCalledTimes(2);
});

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

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 7c18064

Please sign in to comment.