From 06becc295022b793c9df76a024ee586e9f742e20 Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Mon, 31 Jul 2023 15:37:43 +0800 Subject: [PATCH] refactor: remove unnecessary act call Signed-off-by: Lin Wang --- .../monitoring/tests/use_monitoring.test.ts | 45 ++++++------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/public/components/monitoring/tests/use_monitoring.test.ts b/public/components/monitoring/tests/use_monitoring.test.ts index c58c6a8e..8c3e1760 100644 --- a/public/components/monitoring/tests/use_monitoring.test.ts +++ b/public/components/monitoring/tests/use_monitoring.test.ts @@ -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({ @@ -56,9 +54,7 @@ describe('useMonitoring', () => { ) ); - act(() => { - result.current.searchByStatus(['responding']); - }); + result.current.searchByStatus(['responding']); await waitFor(() => expect(Model.prototype.search).toHaveBeenCalledWith( expect.objectContaining({ @@ -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({ @@ -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( @@ -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)); }); @@ -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); @@ -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); @@ -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')); }); @@ -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')); });