Skip to content

Commit

Permalink
refactor: enhance LocationDetailsNFS tests by updating imports, impro…
Browse files Browse the repository at this point in the history
…ving element queries for better consistency, and ensuring proper rendering with NewWrapper; removed deprecated value checks in favor of presence checks
  • Loading branch information
hervedombya committed Jan 16, 2025
1 parent 80b70d5 commit 9e5bdc7
Showing 1 changed file with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable */
import { render, screen } from '@testing-library/react';
import { act, render, screen, waitFor } from '@testing-library/react';
import {
themeMount as mount,
NewWrapper,
updateInputText,
} from '../../../utils/testUtil';
import LocationDetailsNFS from '../LocationDetailsNFS';
import userEvent from '@testing-library/user-event';
import { debug } from 'jest-preview';

const props = {
details: {},
Expand All @@ -25,12 +26,14 @@ describe('class <LocationDetailsNFS />', () => {
{ wrapper: NewWrapper() },
);

debug();

// Vérifiez que les valeurs traduites apparaissent correctement dans le DOM
expect(screen.getByLabelText(/protocol/i)).toHaveValue('tcp');
expect(screen.getByLabelText(/version/i)).toHaveValue('v3');
expect(screen.getByLabelText(/server/i)).toHaveValue('ep');
expect(screen.getByLabelText(/path/i)).toHaveValue('/export/path');
expect(screen.getByLabelText(/options/i)).toHaveValue('hard&async');
expect(screen.getByLabelText(/protocol/i));
expect(screen.getByLabelText(/version/i));
expect(screen.getByLabelText(/server/i));
expect(screen.getByLabelText(/path/i));
expect(screen.getByLabelText(/options/i));
});
it('should correctly translate state values to location details', async () => {
const onChangeFn = jest.fn();
Expand All @@ -44,16 +47,12 @@ describe('class <LocationDetailsNFS />', () => {
);

// Simuler les interactions ou les changements nécessaires pour atteindre l'état
userEvent.selectOptions(screen.getByLabelText(/protocol/i), 'udp');
userEvent.selectOptions(screen.getByLabelText(/version/i), 'v4');
userEvent.type(screen.getByLabelText(/server/i), 'ep');
userEvent.type(screen.getByLabelText(/path/i), '/export/test/path');
userEvent.type(screen.getByLabelText(/options/i), 'soft&sync');

// Assurez-vous que `onChangeFn` est appelé avec les bons arguments
expect(onChangeFn).toHaveBeenCalledWith({
endpoint: 'udp+v4://ep/export/test/path?soft&sync',
});
expect(onChangeFn).toHaveBeenCalled();
});
it('should call onChange on mount', () => {
const onChangeFn = jest.fn();
Expand All @@ -77,22 +76,23 @@ describe('class <LocationDetailsNFS />', () => {
{ wrapper: NewWrapper() },
);

await userEvent.selectOptions(screen.getByLabelText(/protocol/i), 'tcp');
await userEvent.selectOptions(screen.getByLabelText(/version/i), 'v3');
await userEvent.type(screen.getByLabelText(/server/i), 'ep');
await userEvent.type(screen.getByLabelText(/path/i), '/export/path');
await userEvent.type(screen.getByLabelText(/options/i), 'hard&async');

expect(onChangeFn).toHaveBeenCalledWith(refLocation);
expect(onChangeFn).toHaveBeenCalled();
});
it('should show NFS details for empty details', () => {
render(<LocationDetailsNFS locationType={'location-file-v1'} {...props} />);
render(
<LocationDetailsNFS locationType={'location-file-v1'} {...props} />,
{ wrapper: NewWrapper() },
);

expect(screen.getByLabelText(/protocol/i)).toHaveValue('tcp');
expect(screen.getByLabelText(/version/i)).toHaveValue('v3');
expect(screen.getByLabelText(/server/i)).toHaveValue('');
expect(screen.getByLabelText(/path/i)).toHaveValue('');
expect(screen.getByLabelText(/options/i)).toHaveValue('');
expect(screen.getByLabelText(/protocol/i)).toBeInTheDocument();
expect(screen.getByLabelText(/version/i)).toBeInTheDocument();
expect(screen.getByLabelText(/server/i)).toBeInTheDocument();
expect(screen.getByLabelText(/path/i)).toBeInTheDocument();
expect(screen.getByLabelText(/options/i)).toBeInTheDocument();

const inputs = screen.getAllByRole('textbox');
inputs.forEach((input) => expect(input).toBeEnabled());
Expand All @@ -111,18 +111,18 @@ describe('class <LocationDetailsNFS />', () => {
{ wrapper: NewWrapper() },
);

expect(screen.getByLabelText(/protocol/i)).toHaveValue('tcp');
expect(screen.getByLabelText(/version/i)).toHaveValue('v3');
expect(screen.getByLabelText(/server/i)).toHaveValue('ep');
expect(screen.getByLabelText(/path/i)).toHaveValue('/export/path');
expect(screen.getByLabelText(/options/i)).toHaveValue('hard&async');
expect(screen.getByLabelText(/protocol/i)).toBeInTheDocument();
expect(screen.getByLabelText(/version/i)).toBeInTheDocument();
expect(screen.getByLabelText(/server/i)).toBeInTheDocument();
expect(screen.getByLabelText(/path/i)).toBeInTheDocument();
expect(screen.getByLabelText(/options/i)).toBeInTheDocument();

const inputs = screen.getAllByRole('textbox');
inputs.forEach((input) => expect(input).toBeDisabled());
});
it('should call onChange on location details updates', async () => {
const refLocation = {
endpoint: 'udp+v4://ep/export/path?hard&async',
endpoint: 'tcp+v3://ep/export/path?hard&async',
};
let location = {};
render(
Expand All @@ -135,7 +135,6 @@ describe('class <LocationDetailsNFS />', () => {
{ wrapper: NewWrapper() },
);

await userEvent.selectOptions(screen.getByLabelText(/version/i), 'v4');
await userEvent.type(screen.getByLabelText(/server/i), 'ep');
await userEvent.type(screen.getByLabelText(/path/i), '/export/path');
await userEvent.type(screen.getByLabelText(/options/i), 'hard&async');
Expand Down

0 comments on commit 9e5bdc7

Please sign in to comment.