Skip to content

Commit

Permalink
fix: fix the failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadshaheer committed Jan 21, 2025
1 parent d4c473f commit 34b6c1a
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ jest.mock('hooks/queryBuilder/useGetExplorerQueryRange', () => ({
useGetExplorerQueryRange: jest.fn(),
}));

jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));

// Set up the specific behavior for useGetExplorerQueryRange in individual test cases
beforeEach(() => {
(useGetExplorerQueryRange as jest.Mock).mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jest.mock(
},
);

jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));

describe('Dashboard landing page actions header tests', () => {
it('unlock dashboard should be disabled for integrations created dashboards', async () => {
const mockLocation = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ jest.mock('hooks/queryBuilder/useGetCompositeQueryParam', () => ({
useGetCompositeQueryParam: (): Query => compositeQueryParam as Query,
}));

jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));

describe('Column unit selector panel unit test', () => {
it('unit selectors should be rendered for queries and formula', () => {
const mockLocation = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ jest.mock('providers/Dashboard/Dashboard', () => ({
}),
}));

jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));

describe('QueryTable -', () => {
it('should render correctly with all the data rows', () => {
const { container } = render(<QueryTable {...QueryTableProps} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { Router } from 'react-router-dom';
import ResourceProvider from '../ResourceProvider';
import useResourceAttribute from '../useResourceAttribute';

jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));

describe('useResourceAttribute component hook', () => {
it('should not change other query params except for resourceAttribute', async () => {
const history = createMemoryHistory({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jest.mock('react-router-dom', () => ({
const mockWindowOpen = jest.fn();
window.open = mockWindowOpen;

jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));

describe('dashboard list page', () => {
// should render on updatedAt and descend when the column key and order is messed up
it('should render the list even when the columnKey or the order is mismatched', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ jest.mock('d3-interpolate', () => ({
interpolate: jest.fn(),
}));

jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));

const logsQueryServerRequest = (): void =>
server.use(
rest.post(queryRangeURL, (req, res, ctx) =>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/TracesExplorer/Filter/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export function Filter(props: FilterProps): JSX.Element {
...data,
filters: {
...data.filters,
items: data.filters.items.map((item) => ({
items: data.filters?.items?.map((item) => ({
...item,
id: '',
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ jest.mock('react-redux', () => ({
}),
}));

jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));

describe('TracesExplorer - Filters', () => {
// Initial filter panel rendering
// Test the initial state like which filters section are opened, default state of duration slider, etc.
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/tests/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ jest.mock('react-router-dom', () => ({
}),
}));

jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));

jest.mock('react-router-dom-v5-compat', () => ({
...jest.requireActual('react-router-dom-v5-compat'),
useNavigationType: (): any => 'PUSH',
}));

export function getAppContextMock(
role: string,
appContextOverrides?: Partial<IAppContext>,
Expand Down

0 comments on commit 34b6c1a

Please sign in to comment.