Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
narsaynorath committed Dec 10, 2024
1 parent abce81f commit c1f35d0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('WidgetBuilderSortBySelector', function () {
expect(mockNavigate).toHaveBeenLastCalledWith(
expect.objectContaining({
...router.location,
query: expect.objectContaining({sort: ['-count']}),
query: expect.objectContaining({sort: ['-count()']}),
})
);

Expand All @@ -119,7 +119,7 @@ describe('WidgetBuilderSortBySelector', function () {
expect(mockNavigate).toHaveBeenLastCalledWith(
expect.objectContaining({
...router.location,
query: expect.objectContaining({sort: ['count']}),
query: expect.objectContaining({sort: ['count()']}),
})
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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');
});
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand All @@ -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(() => {
Expand All @@ -113,12 +124,16 @@ describe('useQueryParamState', () => {
const mockedNavigate = jest.fn();
mockedUseNavigate.mockReturnValue(mockedNavigate);

const {result} = renderHook(() =>
useQueryParamState<Sort[]>({
fieldName: 'sort',
decoder: decodeSorts,
serializer: value => value.map(formatSort),
})
const {result} = renderHook(
() =>
useQueryParamState<Sort[]>({
fieldName: 'sort',
decoder: decodeSorts,
serializer: value => value.map(formatSort),
}),
{
wrapper: UrlParamBatchProvider,
}
);

expect(result.current[0]).toEqual([{field: 'testField', kind: 'desc'}]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -80,7 +85,9 @@ describe('useWidgetBuilderState', () => {
})
);

const {result} = renderHook(() => useWidgetBuilderState());
const {result} = renderHook(() => useWidgetBuilderState(), {
wrapper: WidgetBuilderProvider,
});

expect(result.current.state.displayType).toBe(DisplayType.AREA);
});
Expand All @@ -92,7 +99,9 @@ describe('useWidgetBuilderState', () => {
})
);

const {result} = renderHook(() => useWidgetBuilderState());
const {result} = renderHook(() => useWidgetBuilderState(), {
wrapper: WidgetBuilderProvider,
});

expect(result.current.state.displayType).toBe(DisplayType.TABLE);
});
Expand All @@ -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({
Expand All @@ -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);
});
Expand All @@ -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({
Expand All @@ -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);
});
Expand All @@ -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'},
Expand All @@ -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'},
Expand Down Expand Up @@ -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'}]);

Expand Down

0 comments on commit c1f35d0

Please sign in to comment.