Skip to content

Commit

Permalink
refactor: remove unnecessary act call
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam committed Aug 2, 2023
1 parent 5ffe695 commit 06becc2
Showing 1 changed file with 13 additions and 32 deletions.
45 changes: 13 additions & 32 deletions public/components/monitoring/tests/use_monitoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ describe('useMonitoring', () => {

await waitFor(() => result.current.pageStatus === 'normal');

act(() => {
result.current.searchByNameOrId('foo');
});
result.current.searchByNameOrId('foo');
await waitFor(() =>
expect(Model.prototype.search).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -56,9 +54,7 @@ describe('useMonitoring', () => {
)
);

act(() => {
result.current.searchByStatus(['responding']);
});
result.current.searchByStatus(['responding']);
await waitFor(() =>
expect(Model.prototype.search).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -68,13 +64,10 @@ describe('useMonitoring', () => {
)
);

act(() => {
result.current.resetSearch();
});
result.current.resetSearch();
await waitFor(() => result.current.pageStatus === 'normal');
act(() => {
result.current.searchByStatus(['partial-responding']);
});

result.current.searchByStatus(['partial-responding']);
await waitFor(() =>
expect(Model.prototype.search).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -97,11 +90,9 @@ describe('useMonitoring', () => {
)
);

act(() => {
result.current.handleTableChange({
sort: { field: 'name', direction: 'desc' },
pagination: { currentPage: 2, pageSize: 10 },
});
result.current.handleTableChange({
sort: { field: 'name', direction: 'desc' },
pagination: { currentPage: 2, pageSize: 10 },
});
await waitFor(() =>
expect(Model.prototype.search).toHaveBeenCalledWith(
Expand All @@ -119,9 +110,7 @@ describe('useMonitoring', () => {

await waitFor(() => expect(Model.prototype.search).toHaveBeenCalledTimes(1));

act(() => {
result.current.reload();
});
result.current.reload();
await waitFor(() => expect(Model.prototype.search).toHaveBeenCalledTimes(2));
});

Expand Down Expand Up @@ -187,9 +176,7 @@ describe('useMonitoring', () => {
expect(result.current.pagination?.currentPage).toBe(2);
});

act(() => {
result.current.searchByNameOrId('foo');
});
result.current.searchByNameOrId('foo');

await waitFor(() => {
expect(Model.prototype.search).toHaveBeenCalledTimes(3);
Expand All @@ -215,9 +202,7 @@ describe('useMonitoring', () => {
expect(result.current.pagination?.currentPage).toBe(2);
});

act(() => {
result.current.searchByStatus(['responding']);
});
result.current.searchByStatus(['responding']);

await waitFor(() => {
expect(Model.prototype.search).toHaveBeenCalledTimes(3);
Expand Down Expand Up @@ -273,9 +258,7 @@ describe('useMonitoring.pageStatus', () => {

// Mock search function to return empty result
mockEmptyRecords();
act(() => {
result.current.searchByNameOrId('foo');
});
result.current.searchByNameOrId('foo');
await waitFor(() => expect(result.current.pageStatus).toBe('reset-filter'));
});

Expand All @@ -287,9 +270,7 @@ describe('useMonitoring.pageStatus', () => {

// assume result is empty
mockEmptyRecords();
act(() => {
result.current.searchByStatus(['responding']);
});
result.current.searchByStatus(['responding']);
await waitFor(() => expect(result.current.pageStatus).toBe('reset-filter'));
});

Expand Down

0 comments on commit 06becc2

Please sign in to comment.