Skip to content

Commit

Permalink
test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Jan 10, 2025
1 parent 589f7e8 commit b2c8920
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import { PlacementGroupsDetail } from './PlacementGroupsDetail';
const queryMocks = vi.hoisted(() => ({
useAllLinodesQuery: vi.fn().mockReturnValue({}),
useLocation: vi.fn().mockReturnValue({ pathname: '/placement-groups/1' }),
useParams: vi.fn().mockReturnValue({}),
useNavigate: vi.fn(),
useParams: vi.fn().mockReturnValue({ id: 1 }),
usePlacementGroupQuery: vi.fn().mockReturnValue({}),
useRegionsQuery: vi.fn().mockReturnValue({}),
useSearch: vi.fn().mockReturnValue({ query: undefined }),
}));

vi.mock('src/queries/placementGroups', async () => {
Expand All @@ -37,15 +39,9 @@ vi.mock('@tanstack/react-router', async () => {
const actual = await vi.importActual('@tanstack/react-router');
return {
...actual,
useNavigate: queryMocks.useNavigate,
useParams: queryMocks.useParams,
};
});

vi.mock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom');
return {
...actual,
useLocation: queryMocks.useLocation,
useSearch: queryMocks.useSearch,
};
});

Expand All @@ -57,13 +53,10 @@ vi.mock('src/queries/regions/regions', async () => {
};
});

describe('PlacementGroupsLanding', () => {
describe('PlacementGroupsDetail', () => {
it('renders a error page', async () => {
const { getByText } = await renderWithThemeAndRouter(
<PlacementGroupsDetail />,
{
initialRoute: '/placement-groups/1',
}
<PlacementGroupsDetail />
);

expect(getByText('Not Found')).toBeInTheDocument();
Expand All @@ -74,7 +67,6 @@ describe('PlacementGroupsLanding', () => {
data: placementGroupFactory.build({
id: 1,
}),

isLoading: true,
});
queryMocks.useAllLinodesQuery.mockReturnValue({
Expand All @@ -95,10 +87,7 @@ describe('PlacementGroupsLanding', () => {
});

const { getByRole } = await renderWithThemeAndRouter(
<PlacementGroupsDetail />,
{
initialRoute: '/placement-groups/1',
}
<PlacementGroupsDetail />
);

expect(getByRole('progressbar')).toBeInTheDocument();
Expand All @@ -113,12 +102,16 @@ describe('PlacementGroupsLanding', () => {
placement_group_type: 'anti_affinity:local',
}),
});
queryMocks.useAllLinodesQuery.mockReturnValue({
data: [],
isLoading: false,
page: 1,
pages: 1,
results: 0,
});

const { getByText } = await renderWithThemeAndRouter(
<PlacementGroupsDetail />,
{
initialRoute: '/placement-groups/1',
}
<PlacementGroupsDetail />
);

expect(getByText(/my first pg/i)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import { PlacementGroupsLinodes } from './PlacementGroupsLinodes/PlacementGroups
import { PlacementGroupsSummary } from './PlacementGroupsSummary/PlacementGroupsSummary';

export const PlacementGroupsDetail = () => {
const { id } = useParams({ from: '/placement-groups/$id' });
const placementGroupId = +id;
const { id: placementGroupId } = useParams({ from: '/placement-groups/$id' });

const {
data: placementGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,33 @@ import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';

import { PLACEMENT_GROUP_LINODES_ERROR_MESSAGE } from '../../constants';
import { PlacementGroupsLinodes } from './PlacementGroupsLinodes';
import { migrationRouteTree } from 'src/routes';

const queryMocks = vi.hoisted(() => ({
useLocation: vi.fn().mockReturnValue({ pathname: '/placement-groups/1' }),
useNavigate: vi.fn(),
useParams: vi.fn().mockReturnValue({ id: 1 }),
useSearch: vi.fn().mockReturnValue({ query: undefined }),
}));

vi.mock('@tanstack/react-router', async () => {
const actual = await vi.importActual('@tanstack/react-router');
return {
...actual,
useLocation: queryMocks.useLocation,
useNavigate: queryMocks.useNavigate,
useParams: queryMocks.useParams,
useSearch: queryMocks.useSearch,
};
});

describe('PlacementGroupsLinodes', () => {
it.only('renders an error state if placement groups are undefined', async () => {
it('renders an error state if placement groups are undefined', async () => {
const { getByText } = await renderWithThemeAndRouter(
<PlacementGroupsLinodes
isLinodeReadOnly={false}
placementGroup={undefined}
region={undefined}
/>,
{
routeTree: migrationRouteTree,
initialRoute: '/placement-groups/1'
}
/>
);

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';

import { PlacementGroupsLanding } from './PlacementGroupsLanding';
import { headers } from './PlacementGroupsLandingEmptyStateData';
import { TanstackLink } from 'src/components/TanstackLinks';

const queryMocks = vi.hoisted(() => ({
useLocation: vi.fn().mockReturnValue({ pathname: '/placement-groups' }),
Expand All @@ -21,14 +20,6 @@ vi.mock('@tanstack/react-router', async () => {
};
});

vi.mock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom');
return {
...actual,
useLocation: queryMocks.useLocation,
};
});

vi.mock('src/queries/placementGroups', async () => {
const actual = await vi.importActual('src/queries/placementGroups');
return {
Expand All @@ -37,14 +28,6 @@ vi.mock('src/queries/placementGroups', async () => {
};
});

vi.mock('src/components/Link', async () => {
const actual = await vi.importActual('src/components/Link');
return {
...actual,
Link: TanstackLink,
};
});

describe('PlacementGroupsLanding', () => {
it('renders loading state', async () => {
queryMocks.usePlacementGroupsQuery.mockReturnValue({
Expand Down
87 changes: 0 additions & 87 deletions packages/manager/src/routes/routes.test.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion packages/manager/src/utilities/testHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Provider } from 'react-redux';
import { MemoryRouter, Route } from 'react-router-dom';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { BrowserRouter } from 'react-router-dom';

import { LinodeThemeWrapper } from 'src/LinodeThemeWrapper';
import { queryClientFactory } from 'src/queries/base';
Expand Down Expand Up @@ -206,7 +207,9 @@ export const wrapWithThemeAndRouter = (
options={{ bootstrap: options.flags }}
>
<SnackbarProvider>
<RouterProvider router={router} />
<BrowserRouter>
<RouterProvider router={router} />
</BrowserRouter>
</SnackbarProvider>
</LDProvider>
</LinodeThemeWrapper>
Expand Down

0 comments on commit b2c8920

Please sign in to comment.