diff --git a/studio/hooks/analytics/useLogsPreview.tsx b/studio/hooks/analytics/useLogsPreview.tsx index b31575e956b..6927a579c91 100644 --- a/studio/hooks/analytics/useLogsPreview.tsx +++ b/studio/hooks/analytics/useLogsPreview.tsx @@ -175,7 +175,7 @@ function useLogsPreview( return { ...resolved, ...filterOverride } }) } else { - setFilters((prev) => ({ ...prev, ...newFilters, ...filterOverride })) + setFilters({ ...newFilters, ...filterOverride }) } } return [ diff --git a/studio/tests/pages/projects/LogsPreviewer.test.js b/studio/tests/pages/projects/LogsPreviewer.test.js index a9e5abdfe25..a380a1c65e7 100644 --- a/studio/tests/pages/projects/LogsPreviewer.test.js +++ b/studio/tests/pages/projects/LogsPreviewer.test.js @@ -350,9 +350,30 @@ test('filters alter generated query', async () => { userEvent.click(await screen.findByText(/Save/)) await waitFor(() => { - expect(get).toHaveBeenCalledWith(expect.stringContaining('select')) expect(get).toHaveBeenCalledWith(expect.stringContaining('500')) + expect(get).toHaveBeenCalledWith(expect.stringContaining('599')) expect(get).toHaveBeenCalledWith(expect.stringContaining('200')) + expect(get).toHaveBeenCalledWith(expect.stringContaining('299')) + expect(get).toHaveBeenCalledWith(expect.stringContaining('where')) + expect(get).toHaveBeenCalledWith(expect.stringContaining('and')) + }) + + // should be able to clear the filters + userEvent.click(await screen.findByRole('button', { name: 'Status' })) + userEvent.click(await screen.findByRole('button', { name: 'Clear' })) + get.mockClear() + + userEvent.click(await screen.findByRole('button', { name: 'Status' })) + userEvent.click(await screen.findByText(/400 codes/)) + userEvent.click(await screen.findByText(/Save/)) + + await waitFor(() => { + expect(get).not.toHaveBeenCalledWith(expect.stringContaining('500')) + expect(get).not.toHaveBeenCalledWith(expect.stringContaining('599')) + expect(get).not.toHaveBeenCalledWith(expect.stringContaining('200')) + expect(get).not.toHaveBeenCalledWith(expect.stringContaining('299')) + expect(get).toHaveBeenCalledWith(expect.stringContaining('400')) + expect(get).toHaveBeenCalledWith(expect.stringContaining('499')) expect(get).toHaveBeenCalledWith(expect.stringContaining('where')) expect(get).toHaveBeenCalledWith(expect.stringContaining('and')) })