Skip to content

Commit

Permalink
fix(CameraView): Minimum FOV check introduced (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwills-jdubs authored Oct 20, 2022
1 parent c74d1dc commit 720b8e8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/scene-composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@
"jest": {
"coverageThreshold": {
"global": {
"lines": 77.47,
"statements": 76.6,
"lines": 77.48,
"statements": 76.61,
"functions": 77.57,
"branches": 63.58,
"branches": 63.62,
"branchesTrue": 100
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ describe('CameraComponentEditor', () => {
expect(innerHTML.includes(`${expectedCamera.getFocalLength().toFixed(2)}mm`)).toEqual(true);
});

it('should not update if FOV is below the minimum value', () => {
useStore('default').setState(baseState);

const { container } = render(<CameraComponentEditor node={mockNode} component={cameraComponent} />);

const polarisWrapper = wrapper(container);
const input = polarisWrapper.find('[data-testid="camera-fov-field"]')?.findInput();

expect(input).not.toBeUndefined();
input!.focus();
input!.setInputValue('1');
input!.blur();
expect(updateComponentInternalFn).not.toBeCalled();
});

it('should update camera node when updating far', () => {
useStore('default').setState(baseState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const CameraComponentEditor: React.FC<ICameraComponentEditorProps> = ({
const updateSceneNodeInternal = useStore(sceneComposerId)((state) => state.updateSceneNodeInternal);
const getObject3DBySceneNodeRef = useStore(sceneComposerId)((state) => state.getObject3DBySceneNodeRef);

const [fovError, setFovError] = useState<boolean>(false);

const cameraComponent = component as ICameraComponentInternal;

const focalLengthIntlMessages = {
Expand Down Expand Up @@ -306,7 +308,17 @@ const CameraComponentEditor: React.FC<ICameraComponentEditorProps> = ({
{intl.formatMessage({ defaultMessage: 'FOV', description: 'Form field label' })}
</div>
</TextContent>
<FormField data-testid={'camera-fov-field'}>
<FormField
data-testid={'camera-fov-field'}
errorText={
fovError
? intl.formatMessage({
defaultMessage: 'FOV cannot be less than 10',
description: 'Form field errorText',
})
: undefined
}
>
<NumericInput
value={cameraSettings.fov!}
toStr={(val) => val.toFixed(2)}
Expand All @@ -317,6 +329,9 @@ const CameraComponentEditor: React.FC<ICameraComponentEditorProps> = ({
fov: value,
});

setFovError(value < 10);
if (value < 10) return;

updateSettings(updatedSettings);
}
}, [])}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@
"note": "75mm lens",
"text": "75mm"
},
"NXP1Hm": {
"note": "Form field errorText",
"text": "FOV cannot be less than 10"
},
"Nj6Ob1": {
"note": "Select Color type option",
"text": "Define arrow color"
Expand Down

0 comments on commit 720b8e8

Please sign in to comment.