Skip to content

Commit

Permalink
last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Feb 21, 2024
1 parent c7e8b5c commit c923bc5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ const ObjectTypeSelect = ({availableObjectTypesState, objecttype, onChange}) =>
if (loading) return;

// check if a valid option is selected, if this is the case -> do nothing
const isOptionPresent = availableObjecttypes.find(ot => ot.url == objecttype);
const isOptionPresent = availableObjecttypes.find(ot => ot.url === objecttype);
if (isOptionPresent) return;

// otherwise select the first possible option and persist that back into the state
const fakeEvent = {target: {name: 'objecttype', value: availableObjecttypes[0].url}};
onChange(fakeEvent);
});

// TODO: only reset the version if everything is done loading
useEffect(() => {
if (loading) return;
onChange({target: {name: 'objecttypeVersion', value: ''}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ const ObjectTypeVersionSelect = ({
if (loading || availableVersions.length == 0) return;

// check if a valid option is selected, if this is the case -> do nothing
const isOptionPresent = availableVersions.find(version => version.version == selectedVersion);
const isOptionPresent = availableVersions.find(
version => parseInt(version.version) === parseInt(selectedVersion)
);
if (isOptionPresent) return;

// otherwise select the first possible option and persist that back into the state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import FormRow from 'components/admin/forms/FormRow';
import ObjectsApiOptionsFormFields from './ObjectsApiOptionsFormFields';
import {mockObjecttypeVersionsGet, mockObjecttypesError, mockObjecttypesGet} from './mocks';

// WARNING
// The `render` function will mutate args, meaning interactions can't be run twice
// Be sure to refresh the page and remove the args in the query parameters

const render = ({index, label, name}) => {
const [{formData}, updateArgs] = useArgs();
const onChange = newValues => {
Expand Down Expand Up @@ -91,7 +95,8 @@ export const SwitchToV2Empty = {
expect(canvas.getByLabelText('Objecttype')).toHaveValue(
'https://objecttypen.nl/api/v1/objecttypes/2c77babf-a967-4057-9969-0200320d23f1'
);
expect(canvas.getByLabelText('Objecttype version')).toHaveValue('2');
// This time as a number as it is a number input:
expect(canvas.getByLabelText('Objecttype version')).toHaveValue(2);
},
};

Expand Down Expand Up @@ -155,6 +160,7 @@ export const SwitchToV2NonExisting = {
expect(canvas.getByLabelText('Objecttype')).toHaveValue(
'https://objecttypen.nl/api/v1/objecttypes/2c77babf-a967-4057-9969-0200320d23f1'
);
// This time as a number as it is a number input:
expect(canvas.getByLabelText('Objecttype version')).toHaveValue(2);
},
};
Expand Down

0 comments on commit c923bc5

Please sign in to comment.