Skip to content

Commit

Permalink
more unit tests passing than ever before :)
Browse files Browse the repository at this point in the history
  • Loading branch information
coliu-akamai committed Jan 10, 2025
1 parent a256a13 commit 5e70be5
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 85 deletions.
6 changes: 0 additions & 6 deletions packages/manager/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ module.exports = {
'Please use routing utilities from @tanstack/react-router.',
name: 'react-router-dom',
},
{
importNames: ['renderWithTheme'],
message:
'Please use the wrapWithThemeAndRouter helper function for testing components being migrated to TanStack Router.',
name: 'src/utilities/testHelpers',
},
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('Placement Group deletion', () => {
* - Confirms that UI automatically updates to reflect deleted Placement Group.
* - Confirms that user can retry and continue with unassignment when unexpected error happens.
*/
it.only('can delete with Linodes assigned when unexpected error show up and retry', () => {
it('can delete with Linodes assigned when unexpected error show up and retry', () => {
const mockPlacementGroupRegion = chooseRegion();

// Linodes that are assigned to the Placement Group being deleted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
placementGroupFactory,
regionFactory,
} from 'src/factories';
import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsAssignLinodesDrawer } from './PlacementGroupsAssignLinodesDrawer';

Expand Down Expand Up @@ -42,12 +42,12 @@ vi.mock('src/queries/placementGroups', async () => {
});

describe('PlacementGroupsAssignLinodesDrawer', () => {
it('should render the error state', async () => {
it('should render the error state', () => {
queryMocks.useAllLinodesQuery.mockReturnValue({
error: [{ reason: 'Not found' }],
});

const { container } = await renderWithThemeAndRouter(
const { container } = renderWithTheme(
<PlacementGroupsAssignLinodesDrawer
onClose={vi.fn()}
open={true}
Expand All @@ -59,7 +59,7 @@ describe('PlacementGroupsAssignLinodesDrawer', () => {
expect(container).toBeEmptyDOMElement();
});

it('should render the drawer components', async () => {
it('should render the drawer components', () => {
queryMocks.useAllLinodesQuery.mockReturnValue({
data: [
linodeFactory.build({ id: 1, label: 'Linode-1', region: 'us-east' }),
Expand Down Expand Up @@ -117,11 +117,7 @@ describe('PlacementGroupsAssignLinodesDrawer', () => {
})
);

const {
getByPlaceholderText,
getByRole,
getByText,
} = await renderWithThemeAndRouter(
const { getByPlaceholderText, getByRole, getByText } = renderWithTheme(
<PlacementGroupsAssignLinodesDrawer
selectedPlacementGroup={placementGroupFactory.build({
label: 'PG-1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { fireEvent, waitFor } from '@testing-library/react';
import * as React from 'react';

import { placementGroupFactory } from 'src/factories';
// eslint-disable-next-line no-restricted-imports
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsCreateDrawer } from './PlacementGroupsCreateDrawer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { userEvent } from '@testing-library/user-event';
import * as React from 'react';

import { linodeFactory, placementGroupFactory } from 'src/factories';
import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsDeleteModal } from './PlacementGroupsDeleteModal';

Expand Down Expand Up @@ -45,16 +45,12 @@ const props = {
};

describe('PlacementGroupsDeleteModal', () => {
it('should render the right form elements', async () => {
it('should render the right form elements', () => {
queryMocks.usePreferences.mockReturnValue({
data: preference,
});

const {
getByRole,
getByTestId,
getByText,
} = await renderWithThemeAndRouter(
const { getByRole, getByTestId, getByText } = renderWithTheme(
<PlacementGroupsDeleteModal
{...props}
linodes={[
Expand Down Expand Up @@ -103,7 +99,7 @@ describe('PlacementGroupsDeleteModal', () => {
data: preference,
});

const { getByRole, getByTestId } = await renderWithThemeAndRouter(
const { getByRole, getByTestId } = renderWithTheme(
<PlacementGroupsDeleteModal
{...props}
linodes={[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { linodeFactory } from 'src/factories';
import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsLinodesTable } from './PlacementGroupsLinodesTable';

Expand Down Expand Up @@ -34,8 +34,8 @@ const defaultProps = {
};

describe('PlacementGroupsLinodesTable', () => {
it('renders an error state when encountering an API error', async () => {
const { getByText } = await renderWithThemeAndRouter(
it('renders an error state when encountering an API error', () => {
const { getByText } = renderWithTheme(
<PlacementGroupsLinodesTable
{...defaultProps}
error={[{ reason: 'Not found' }]}
Expand All @@ -45,24 +45,24 @@ describe('PlacementGroupsLinodesTable', () => {
expect(getByText(/not found/i)).toBeInTheDocument();
});

it('renders a loading skeleton based on the loading prop', async () => {
const { getByTestId } = await renderWithThemeAndRouter(
it('renders a loading skeleton based on the loading prop', () => {
const { getByTestId } = renderWithTheme(
<PlacementGroupsLinodesTable {...defaultProps} isFetchingLinodes />
);

expect(getByTestId('table-row-loading')).toBeInTheDocument();
});

it('should have the correct number of columns', async () => {
const { getAllByRole } = await renderWithThemeAndRouter(
it('should have the correct number of columns', () => {
const { getAllByRole } = renderWithTheme(
<PlacementGroupsLinodesTable {...defaultProps} />
);

expect(getAllByRole('columnheader')).toHaveLength(3);
});

it('should have the correct number of rows', async () => {
const { getAllByTestId } = await renderWithThemeAndRouter(
it('should have the correct number of rows', () => {
const { getAllByTestId } = renderWithTheme(
<PlacementGroupsLinodesTable {...defaultProps} />
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';

import { linodeFactory } from 'src/factories';
import { wrapWithTableBody } from 'src/utilities/testHelpers';
import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsLinodesTableRow } from './PlacementGroupsLinodesTableRow';

Expand All @@ -27,8 +27,8 @@ const defaultProps = {
};

describe('PlacementGroupsLinodesTableRow', () => {
it('should feature the right table row data', async () => {
const { getAllByRole } = await renderWithThemeAndRouter(
it('should feature the right table row data', () => {
const { getAllByRole } = renderWithTheme(
wrapWithTableBody(<PlacementGroupsLinodesTableRow {...defaultProps} />)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import * as React from 'react';

import { placementGroupFactory, regionFactory } from 'src/factories';
import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsSummary } from './PlacementGroupsSummary';

describe('PlacementGroups Summary', () => {
it('renders the placement group detail summary panel', async () => {
const { getByTestId, getByText } = await renderWithThemeAndRouter(
it('renders the placement group detail summary panel', () => {
const { getByTestId, getByText } = renderWithTheme(
<PlacementGroupsSummary
placementGroup={placementGroupFactory.build({
placement_group_type: 'affinity:local',
id: 3,
is_compliant: true,
label: 'pg-3',
Expand All @@ -36,6 +35,7 @@ describe('PlacementGroups Summary', () => {
linode_id: 10,
},
],
placement_group_type: 'affinity:local',
region: 'us-east',
})}
region={regionFactory.build({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { placementGroupFactory, regionFactory } from 'src/factories';
import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsDetailPanel } from './PlacementGroupsDetailPanel';

Expand Down Expand Up @@ -96,8 +96,8 @@ describe('PlacementGroupsDetailPanel', () => {
});
});

it('should have its select disabled and no create PG button on initial render', async () => {
const { getByRole, queryByRole } = await renderWithThemeAndRouter(
it('should have its select disabled and no create PG button on initial render', () => {
const { getByRole, queryByRole } = renderWithTheme(
<PlacementGroupsDetailPanel {...defaultProps} />
);

Expand All @@ -107,8 +107,8 @@ describe('PlacementGroupsDetailPanel', () => {
).not.toBeInTheDocument();
});

it('should have its select enabled and a create PG button when provided a region', async () => {
const { getByRole } = await renderWithThemeAndRouter(
it('should have its select enabled and a create PG button when provided a region', () => {
const { getByRole } = renderWithTheme(
<PlacementGroupsDetailPanel
{...defaultProps}
selectedRegionId="us-east"
Expand All @@ -121,12 +121,8 @@ describe('PlacementGroupsDetailPanel', () => {
).toBeEnabled();
});

it('should have its select disabled and no create PG button when provided a region without PG capability', async () => {
const {
getByRole,
getByTestId,
queryByRole,
} = await renderWithThemeAndRouter(
it('should have its select disabled and no create PG button when provided a region without PG capability', () => {
const { getByRole, getByTestId, queryByRole } = renderWithTheme(
<PlacementGroupsDetailPanel
{...defaultProps}
selectedRegionId="us-southeast"
Expand All @@ -142,8 +138,8 @@ describe('PlacementGroupsDetailPanel', () => {
).not.toBeInTheDocument();
});

it('should have its PG select enabled and Create Placement Group button disabled if the region has reached its PG capacity', async () => {
const { getByPlaceholderText, getByRole } = await renderWithThemeAndRouter(
it('should have its PG select enabled and Create Placement Group button disabled if the region has reached its PG capacity', () => {
const { getByPlaceholderText, getByRole } = renderWithTheme(
<PlacementGroupsDetailPanel
{...defaultProps}
selectedRegionId="us-west"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import userEvent from '@testing-library/user-event';
import * as React from 'react';

import { placementGroupFactory, regionFactory } from 'src/factories';
import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsEditDrawer } from './PlacementGroupsEditDrawer';

Expand Down Expand Up @@ -34,11 +34,7 @@ describe('PlacementGroupsCreateDrawer', () => {
it('should render, have the proper fields populated with PG values, and have uneditable fields disabled', async () => {
queryMocks.useParams.mockReturnValue({ id: '1' });

const {
getByLabelText,
getByRole,
getByText,
} = await renderWithThemeAndRouter(
const { getByLabelText, getByRole, getByText } = renderWithTheme(
<PlacementGroupsEditDrawer
selectedPlacementGroup={placementGroupFactory.build({
id: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
regionFactory,
} from 'src/factories';
import {
renderWithThemeAndRouter,
renderWithTheme,
resizeScreenSize,
wrapWithTableBody,
} from 'src/utilities/testHelpers';
Expand Down Expand Up @@ -43,13 +43,9 @@ const region = regionFactory.build({
});

describe('PlacementGroupsRow', () => {
it('renders the columns with proper data', async () => {
it('renders the columns with proper data', () => {
resizeScreenSize(1200);
const {
getByRole,
getByTestId,
getByText,
} = await renderWithThemeAndRouter(
const { getByRole, getByTestId, getByText } = renderWithTheme(
wrapWithTableBody(
<PlacementGroupsRow
assignedLinodes={[linode]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as React from 'react';

import { linodeFactory } from 'src/factories';
import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsUnassignModal } from './PlacementGroupsUnassignModal';

const queryMocks = vi.hoisted(() => ({
useLinodeQuery: vi.fn().mockReturnValue({}),
useParams: vi.fn().mockReturnValue({}),
}));

Expand All @@ -18,33 +17,23 @@ vi.mock('@tanstack/react-router', async () => {
};
});

vi.mock('src/queries/linodes/linodes', async () => {
const actual = await vi.importActual('src/queries/linodes/linodes');
return {
...actual,
useLinodeQuery: queryMocks.useLinodeQuery,
};
});

describe('PlacementGroupsUnassignModal', () => {
it('should render and have the proper content and CTAs', async () => {
queryMocks.useLinodeQuery.mockReturnValue({
data: linodeFactory.build({
id: 1,
label: 'test-linode',
}),
it('should render and have the proper content and CTAs', () => {
const linode = linodeFactory.build({
id: 1,
label: 'test-linode',
});
queryMocks.useParams.mockReturnValue({
id: '1',
linodeId: '1',
});

const { getByLabelText, getByRole } = await renderWithThemeAndRouter(
const { getByLabelText, getByRole } = renderWithTheme(
<PlacementGroupsUnassignModal
isFetching={false}
onClose={() => null}
open
selectedLinode={undefined}
selectedLinode={linode}
/>
);

Expand Down

0 comments on commit 5e70be5

Please sign in to comment.