From c1f35d047095d19e5ec3f8873040281d37f369a1 Mon Sep 17 00:00:00 2001 From: Nar Saynorath Date: Tue, 10 Dec 2024 14:52:56 -0500 Subject: [PATCH] Fix tests --- .../components/sortBySelector.spec.tsx | 4 +- .../hooks/useQueryParamState.spec.tsx | 39 +++++++++++----- .../hooks/useWidgetBuilderState.spec.tsx | 45 ++++++++++++++----- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/static/app/views/dashboards/widgetBuilder/components/sortBySelector.spec.tsx b/static/app/views/dashboards/widgetBuilder/components/sortBySelector.spec.tsx index 8971f2229d993a..31c51c0661c454 100644 --- a/static/app/views/dashboards/widgetBuilder/components/sortBySelector.spec.tsx +++ b/static/app/views/dashboards/widgetBuilder/components/sortBySelector.spec.tsx @@ -110,7 +110,7 @@ describe('WidgetBuilderSortBySelector', function () { expect(mockNavigate).toHaveBeenLastCalledWith( expect.objectContaining({ ...router.location, - query: expect.objectContaining({sort: ['-count']}), + query: expect.objectContaining({sort: ['-count()']}), }) ); @@ -119,7 +119,7 @@ describe('WidgetBuilderSortBySelector', function () { expect(mockNavigate).toHaveBeenLastCalledWith( expect.objectContaining({ ...router.location, - query: expect.objectContaining({sort: ['count']}), + query: expect.objectContaining({sort: ['count()']}), }) ); }); diff --git a/static/app/views/dashboards/widgetBuilder/hooks/useQueryParamState.spec.tsx b/static/app/views/dashboards/widgetBuilder/hooks/useQueryParamState.spec.tsx index cb196efbee4ec5..1a67cd4fec467c 100644 --- a/static/app/views/dashboards/widgetBuilder/hooks/useQueryParamState.spec.tsx +++ b/static/app/views/dashboards/widgetBuilder/hooks/useQueryParamState.spec.tsx @@ -6,6 +6,7 @@ import type {Sort} from 'sentry/utils/discover/fields'; import {decodeSorts} from 'sentry/utils/queryString'; import {useLocation} from 'sentry/utils/useLocation'; import {useNavigate} from 'sentry/utils/useNavigate'; +import {UrlParamBatchProvider} from 'sentry/views/dashboards/widgetBuilder/contexts/urlParamBatchContext'; import {useQueryParamState} from 'sentry/views/dashboards/widgetBuilder/hooks/useQueryParamState'; import {formatSort} from 'sentry/views/explore/tables/aggregatesTable'; @@ -29,7 +30,9 @@ describe('useQueryParamState', () => { LocationFixture({query: {testField: 'initial state'}}) ); - const {result} = renderHook(() => useQueryParamState({fieldName: 'testField'})); + const {result} = renderHook(() => useQueryParamState({fieldName: 'testField'}), { + wrapper: UrlParamBatchProvider, + }); expect(result.current[0]).toBe('initial state'); }); @@ -38,7 +41,9 @@ describe('useQueryParamState', () => { const mockedNavigate = jest.fn(); mockedUseNavigate.mockReturnValue(mockedNavigate); - const {result} = renderHook(() => useQueryParamState({fieldName: 'testField'})); + const {result} = renderHook(() => useQueryParamState({fieldName: 'testField'}), { + wrapper: UrlParamBatchProvider, + }); act(() => { result.current[1]('newValue'); @@ -73,8 +78,11 @@ describe('useQueryParamState', () => { const testDeserializer = (value: string) => `${value.toUpperCase()} - decoded`; - const {result} = renderHook(() => - useQueryParamState({fieldName: 'testField', deserializer: testDeserializer}) + const {result} = renderHook( + () => useQueryParamState({fieldName: 'testField', deserializer: testDeserializer}), + { + wrapper: UrlParamBatchProvider, + } ); expect(result.current[0]).toBe('INITIAL STATE - decoded'); @@ -93,8 +101,11 @@ describe('useQueryParamState', () => { const testSerializer = (value: TestType) => `${value.value} - ${value.count} - ${value.isActive}`; - const {result} = renderHook(() => - useQueryParamState({fieldName: 'testField', serializer: testSerializer}) + const {result} = renderHook( + () => useQueryParamState({fieldName: 'testField', serializer: testSerializer}), + { + wrapper: UrlParamBatchProvider, + } ); act(() => { @@ -113,12 +124,16 @@ describe('useQueryParamState', () => { const mockedNavigate = jest.fn(); mockedUseNavigate.mockReturnValue(mockedNavigate); - const {result} = renderHook(() => - useQueryParamState({ - fieldName: 'sort', - decoder: decodeSorts, - serializer: value => value.map(formatSort), - }) + const {result} = renderHook( + () => + useQueryParamState({ + fieldName: 'sort', + decoder: decodeSorts, + serializer: value => value.map(formatSort), + }), + { + wrapper: UrlParamBatchProvider, + } ); expect(result.current[0]).toEqual([{field: 'testField', kind: 'desc'}]); diff --git a/static/app/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState.spec.tsx b/static/app/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState.spec.tsx index 20ef2fe084e354..cbc5f6babc085f 100644 --- a/static/app/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState.spec.tsx +++ b/static/app/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState.spec.tsx @@ -5,6 +5,7 @@ import {act, renderHook} from 'sentry-test/reactTestingLibrary'; import {useLocation} from 'sentry/utils/useLocation'; import {useNavigate} from 'sentry/utils/useNavigate'; import {DisplayType, WidgetType} from 'sentry/views/dashboards/types'; +import {WidgetBuilderProvider} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext'; import useWidgetBuilderState, { BuilderStateAction, } from 'sentry/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState'; @@ -35,7 +36,9 @@ describe('useWidgetBuilderState', () => { }) ); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); expect(result.current.state.title).toBe('test'); expect(result.current.state.description).toBe('lalala this is a description'); @@ -45,7 +48,9 @@ describe('useWidgetBuilderState', () => { const mockNavigate = jest.fn(); mockedUseNavigate.mockReturnValue(mockNavigate); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); act(() => { result.current.dispatch({ type: BuilderStateAction.SET_TITLE, @@ -80,7 +85,9 @@ describe('useWidgetBuilderState', () => { }) ); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); expect(result.current.state.displayType).toBe(DisplayType.AREA); }); @@ -92,7 +99,9 @@ describe('useWidgetBuilderState', () => { }) ); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); expect(result.current.state.displayType).toBe(DisplayType.TABLE); }); @@ -101,7 +110,9 @@ describe('useWidgetBuilderState', () => { const mockNavigate = jest.fn(); mockedUseNavigate.mockReturnValue(mockNavigate); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); act(() => { result.current.dispatch({ @@ -126,7 +137,9 @@ describe('useWidgetBuilderState', () => { LocationFixture({query: {dataset: WidgetType.ISSUE}}) ); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); expect(result.current.state.dataset).toBe(WidgetType.ISSUE); }); @@ -135,7 +148,9 @@ describe('useWidgetBuilderState', () => { const mockNavigate = jest.fn(); mockedUseNavigate.mockReturnValue(mockNavigate); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); act(() => { result.current.dispatch({ @@ -156,7 +171,9 @@ describe('useWidgetBuilderState', () => { it('returns errors as the default dataset', () => { mockedUsedLocation.mockReturnValue(LocationFixture({query: {dataset: 'invalid'}})); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); expect(result.current.state.dataset).toBe(WidgetType.ERRORS); }); @@ -168,7 +185,9 @@ describe('useWidgetBuilderState', () => { LocationFixture({query: {field: ['event.type', 'potato', 'count()']}}) ); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); expect(result.current.state.fields).toEqual([ {field: 'event.type', alias: undefined, kind: 'field'}, @@ -193,7 +212,9 @@ describe('useWidgetBuilderState', () => { }) ); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); expect(result.current.state.fields).toEqual([ {field: 'event.type', alias: undefined, kind: 'field'}, @@ -229,7 +250,9 @@ describe('useWidgetBuilderState', () => { }) ); - const {result} = renderHook(() => useWidgetBuilderState()); + const {result} = renderHook(() => useWidgetBuilderState(), { + wrapper: WidgetBuilderProvider, + }); expect(result.current.state.sort).toEqual([{field: 'testField', kind: 'desc'}]);