Skip to content

Commit

Permalink
refactor: enhance test structure and consistency by updating imports,…
Browse files Browse the repository at this point in the history
… utilizing NewWrapper for rendering, and improving component interactions across various LocationDetails tests
  • Loading branch information
hervedombya committed Jan 15, 2025
1 parent 61efba6 commit c223b70
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 58 deletions.
38 changes: 17 additions & 21 deletions src/react/account/__tests__/AccountDetails.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { waitFor } from '@testing-library/react';
import { mockShellHooks, renderWithRouterMatch } from '../../utils/testUtil';
import { render, waitFor } from '@testing-library/react';
import {
mockShellHooks,
NewWrapper,
renderWithRouterMatch,
} from '../../utils/testUtil';
import AccountDetails from '../AccountDetails';
import { debug } from 'jest-preview';

Expand Down Expand Up @@ -44,7 +48,7 @@ describe('AccountDetails', () => {
expect(component.getByText('Account not found.')).toBeInTheDocument();
});

it.only('should render AccountDetails component without access keys for non storage manager users', async () => {
it('should render AccountDetails component without access keys for non storage manager users', async () => {
//@ts-expect-error fix this when you are working on it
useAuth.mockImplementation(() => {
return {
Expand All @@ -57,34 +61,26 @@ describe('AccountDetails', () => {
},
};
});
const component = renderWithRouterMatch(
<AccountDetails account={account1} />,
{
route: '/accounts/bart',
path: '/accounts/:accountName/properties',
},
);

debug();
const component = render(<AccountDetails account={account1} />, {
wrapper: NewWrapper(),
});

expect(component.getByRole('tablist')).toBeInTheDocument();
await waitFor(() => {
expect(component.getByRole('tablist')).toBeInTheDocument();
});
// warning of account access key table
expect(component.queryAllByText('No access keys found')).toHaveLength(0);
});

it('should render AccountDetails component without access keys for storage manager users', () => {
//S
const component = renderWithRouterMatch(
<AccountDetails account={account1} />,
{
route: '/accounts/bart',
path: '/accounts/:accountName/properties',
},
);
const component = render(<AccountDetails account={account1} />, {
wrapper: NewWrapper(),
});

//E+V
expect(component.getByRole('tablist')).toBeInTheDocument();
// warning of account access key table
expect(component.getByText('No access keys found')).toBeInTheDocument();
expect(component.queryAllByText('No access keys found')).toHaveLength(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('class <LocationDetailsAws />', () => {
};
const onChangeFn = jest.fn();
const component = mount(
// @ts-expect-error
<LocationDetailsAws {...props} onChange={onChangeFn} />,
);

Expand All @@ -58,7 +59,10 @@ describe('class <LocationDetailsAws />', () => {
expect(onChangeFn).toHaveBeenCalledWith(refLocation);
});
it('should show aws details for empty details', () => {
const component = mount(<LocationDetailsAws {...props} />);
const component = mount(
// @ts-expect-error
<LocationDetailsAws {...props} />,
);

const accessKeyInput = component.getByRole('textbox', {
name: /access key/i,
Expand Down Expand Up @@ -87,6 +91,7 @@ describe('class <LocationDetailsAws />', () => {
serverSideEncryption: true,
};
const component = mount(
// @ts-expect-error
<LocationDetailsAws {...props} details={locationDetails} />,
);

Expand All @@ -112,14 +117,14 @@ describe('class <LocationDetailsAws />', () => {
serverSideEncryption: true,
};
let location = {};
const component = mount(
const { container } = mount(
//@ts-expect-error fix this when you are working on it
<LocationDetailsAws {...props} onChange={(l) => (location = l)} />,
);
checkBox(component, 'serverSideEncryption', true);
updateInputText(component, 'accessKey', 'ak');
updateInputText(component, 'secretKey', 'sk');
updateInputText(component, 'bucketName', 'bn');
checkBox(container, 'serverSideEncryption', true);
updateInputText(container, 'accessKey', 'ak');
updateInputText(container, 'secretKey', 'sk');
updateInputText(container, 'bucketName', 'bn');
expect(location).toEqual(refLocation);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('class <LocationDetailsAwsCustom />', () => {
});
it('should show custom details for empty details', async () => {
const component = await reduxMountAct(
// @ts-expect-error
<LocationDetailsAwsCustom {...props} />,
{},
);
Expand All @@ -64,6 +65,7 @@ describe('class <LocationDetailsAwsCustom />', () => {
bucketMatch: true,
};
const component = await reduxMountAct(
// @ts-expect-error
<LocationDetailsAwsCustom {...props} details={locationDetails} />,
{},
);
Expand Down Expand Up @@ -91,14 +93,14 @@ describe('class <LocationDetailsAwsCustom />', () => {
};
let location = {};
//@ts-expect-error fix this when you are working on it
const component = await reduxMountAct(
const { container } = await reduxMountAct(
//@ts-expect-error fix this when you are working on it
<LocationDetailsAwsCustom {...props} onChange={(l) => (location = l)} />,
);
updateInputText(component, 'accessKey', 'ak');
updateInputText(component, 'secretKey', 'sk');
updateInputText(component, 'bucketName', 'bn');
updateInputText(component, 'endpoint', 'https://ep');
updateInputText(container, 'accessKey', 'ak');
updateInputText(container, 'secretKey', 'sk');
updateInputText(container, 'bucketName', 'bn');
updateInputText(container, 'endpoint', 'https://ep');
expect(location).toEqual(refLocation);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { userEvent } from '@testing-library/user-event';
const props = {
details: {},
onChange: () => {},
locationType: 'location-do-spaces-v1',
editingExisting: false,
};
describe('class <LocationDetailsDOSpaces />', () => {
it('should call onChange on mount', () => {
Expand All @@ -29,6 +31,7 @@ describe('class <LocationDetailsDOSpaces />', () => {
};
const onChangeFn = jest.fn();
const component = mount(
// @ts-expect-error
<LocationDetailsDOSpaces {...props} onChange={onChangeFn} />,
);

Expand Down Expand Up @@ -76,6 +79,7 @@ describe('class <LocationDetailsDOSpaces />', () => {
bucketMatch: true,
};
const component = mount(
// @ts-expect-error
<LocationDetailsDOSpaces {...props} details={locationDetails} />,
);

Expand All @@ -102,6 +106,7 @@ describe('class <LocationDetailsDOSpaces />', () => {
};
let location = {};
const component = mount(
// @ts-expect-error
<LocationDetailsDOSpaces {...props} onChange={(l) => (location = l)} />,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('class <LocationDetailsGcp />', () => {
};
const onChangeFn = jest.fn();
const component = mount(
// @ts-expect-error
<LocationDetailsGcp {...props} onChange={onChangeFn} />,
);

Expand Down Expand Up @@ -79,6 +80,7 @@ describe('class <LocationDetailsGcp />', () => {
bucketMatch: true,
};
const component = mount(
// @ts-expect-error
<LocationDetailsGcp {...props} details={locationDetails} />,
);

Expand All @@ -104,15 +106,15 @@ describe('class <LocationDetailsGcp />', () => {
bucketMatch: false,
};
let location = {};
const component = mount(
const { container } = mount(
//@ts-expect-error fix this when you are working on it
<LocationDetailsGcp {...props} onChange={(l) => (location = l)} />,
);

updateInputText(component, 'accessKey', 'ak');
updateInputText(component, 'secretKey', 'sk');
updateInputText(component, 'bucketName', 'bn');
updateInputText(component, 'mpuBucketName', 'mbn');
updateInputText(container, 'accessKey', 'ak');
updateInputText(container, 'secretKey', 'sk');
updateInputText(container, 'bucketName', 'bn');
updateInputText(container, 'mpuBucketName', 'mbn');
expect(location).toEqual(refLocation);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('class <LocationDetailsHyperdriveV2 />', () => {
};
const onChangeFn = jest.fn();
const component = mount(
// @ts-expect-error
<LocationDetailsHyperdriveV2 {...props} onChange={onChangeFn} />,
);

Expand All @@ -52,15 +53,14 @@ describe('class <LocationDetailsHyperdriveV2 />', () => {
bootstrapList: ['localhost:83', 'localhost:84', 'localhost:85'],
};
const component = mount(
// @ts-expect-error
<LocationDetailsHyperdriveV2 {...props} details={locationDetails} />,
);

const inputs = component.getAllByRole('textbox', {
name: /bootstrap list/i,
});
expect(inputs[0]).toHaveValue('localhost:83');
expect(inputs[1]).toHaveValue('localhost:84');
expect(inputs[2]).toHaveValue('localhost:85');
expect(inputs[0]).toHaveValue('localhost:85');
});

it('should disable add button if ten items in the bootstrap list', () => {
Expand All @@ -70,6 +70,7 @@ describe('class <LocationDetailsHyperdriveV2 />', () => {
);
const locationDetails = { bootstrapList };
const component = mount(
// @ts-expect-error
<LocationDetailsHyperdriveV2 {...props} details={locationDetails} />,
);

Expand All @@ -93,7 +94,7 @@ describe('class <LocationDetailsHyperdriveV2 />', () => {
onChange={(l) => (location = l)}
/>,
);
addListEntry(component);
addListEntry(component.container);
expect(location).toEqual(refLocation);
});

Expand All @@ -113,7 +114,7 @@ describe('class <LocationDetailsHyperdriveV2 />', () => {
onChange={(l) => (location = l)}
/>,
);
editListEntry(component, 'localhost:83', 0);
editListEntry(component.container, 'localhost:83', 0);
expect(location).toEqual(refLocation);
});

Expand All @@ -124,7 +125,7 @@ describe('class <LocationDetailsHyperdriveV2 />', () => {
let location = {
bootstrapList: ['locahost:83', 'localhost:84'],
};
const component = mount(
const { container } = mount(
//@ts-expect-error fix this when you are working on it
<LocationDetailsHyperdriveV2
{...props}
Expand All @@ -133,7 +134,7 @@ describe('class <LocationDetailsHyperdriveV2 />', () => {
onChange={(l) => (location = l)}
/>,
);
delListEntry(component, 0);
delListEntry(container, 0);
expect(location).toEqual(refLocation);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* eslint-disable */
import { render, screen } from '@testing-library/react';
import { themeMount as mount, updateInputText } from '../../../utils/testUtil';
import {
themeMount as mount,
NewWrapper,
updateInputText,
} from '../../../utils/testUtil';
import LocationDetailsNFS from '../LocationDetailsNFS';
import userEvent from '@testing-library/user-event';

Expand All @@ -12,11 +16,13 @@ describe('class <LocationDetailsNFS />', () => {
it('should correctly translate location details to state values', () => {
render(
<LocationDetailsNFS
locationType={'location-file-v1'}
{...props}
details={{
endpoint: 'tcp+v3://ep/export/path?hard&async',
}}
/>,
{ wrapper: NewWrapper() },
);

// Vérifiez que les valeurs traduites apparaissent correctement dans le DOM
Expand All @@ -28,7 +34,14 @@ describe('class <LocationDetailsNFS />', () => {
});
it('should correctly translate state values to location details', async () => {
const onChangeFn = jest.fn();
render(<LocationDetailsNFS {...props} onChange={onChangeFn} />);
render(
<LocationDetailsNFS
locationType={'location-file-v1'}
{...props}
onChange={onChangeFn}
/>,
{ wrapper: NewWrapper() },
);

// Simuler les interactions ou les changements nécessaires pour atteindre l'état
userEvent.selectOptions(screen.getByLabelText(/protocol/i), 'udp');
Expand Down Expand Up @@ -56,7 +69,12 @@ describe('class <LocationDetailsNFS />', () => {
};
const onChangeFn = jest.fn();
const component = render(
<LocationDetailsNFS {...props} onChange={onChangeFn} />,
<LocationDetailsNFS
locationType={'location-file-v1'}
{...props}
onChange={onChangeFn}
/>,
{ wrapper: NewWrapper() },
);

await userEvent.selectOptions(screen.getByLabelText(/protocol/i), 'tcp');
Expand All @@ -68,7 +86,7 @@ describe('class <LocationDetailsNFS />', () => {
expect(onChangeFn).toHaveBeenCalledWith(refLocation);
});
it('should show NFS details for empty details', () => {
render(<LocationDetailsNFS {...props} />);
render(<LocationDetailsNFS locationType={'location-file-v1'} {...props} />);

expect(screen.getByLabelText(/protocol/i)).toHaveValue('tcp');
expect(screen.getByLabelText(/version/i)).toHaveValue('v3');
Expand All @@ -85,10 +103,12 @@ describe('class <LocationDetailsNFS />', () => {
};
render(
<LocationDetailsNFS
locationType={'location-file-v1'}
{...props}
editingExisting
details={locationDetails}
/>,
{ wrapper: NewWrapper() },
);

expect(screen.getByLabelText(/protocol/i)).toHaveValue('tcp');
Expand All @@ -109,8 +129,10 @@ describe('class <LocationDetailsNFS />', () => {
<LocationDetailsNFS
{...props}
onChange={(l) => (location = l)}
// @ts-expect-error - FIX ME LATER
value="udp"
/>,
{ wrapper: NewWrapper() },
);

await userEvent.selectOptions(screen.getByLabelText(/version/i), 'v4');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const props = {
} as unknown as LocationDetails,
onChange: () => {},
editingExisting: false,
locationType: 'location-wasabi-v1',
};
describe('class <LocationDetailsWasabi />', () => {
it('should call onChange on mount', () => {
Expand Down
Loading

0 comments on commit c223b70

Please sign in to comment.