Skip to content

Commit

Permalink
test(fields): add tests to dms and dd coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Feb 14, 2025
1 parent 7a627dc commit f069969
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions e2e/base/fields/CoordinatesInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { mount } from 'cypress/react18'

import { StoryBox } from '../../../.storybook/components/StoryBox'
import { CoordinatesFormat } from '../../../src'
import { _CoordinatesInput as CoordinatesInputStory } from '../../../stories/fields/CoordinatesInput.stories'
Expand Down Expand Up @@ -67,4 +69,50 @@ context('Story', () => {

outputShouldBe([-2.986111, -17.414444])
})

it('Should round the default value for DMS coordinates to 6 decimals', () => {
const props: CoordinatesInputProps = {
coordinatesFormat: CoordinatesFormat.DEGREES_MINUTES_SECONDS,
defaultValue: [47.53916721151114, -0.2598992997646015],
label: 'Coordinates',
name: 'myCoordinatesInput'
}

mountAndWait(
<StoryBox>
<CoordinatesInputStory {...props} />
</StoryBox>
)

outputShouldBe([47.539167, -0.26])
})

it('Should modify the value for DD coordinates', () => {
const props: CoordinatesInputProps = {
coordinatesFormat: CoordinatesFormat.DECIMAL_DEGREES,
defaultValue: [47.53916721151114, -0.2598992997646015],
label: 'Coordinates',
name: 'myCoordinatesInput'
}

mount(
<StoryBox>
<CoordinatesInputStory {...props} />
</StoryBox>
).then(({ rerender }) => {
cy.getDataCy('coordinates-dd-input-lat').should('have.value', '47.539167')

const nextProps = {
...props,
defaultValue: [47.123, -0.123]
}
rerender(
<StoryBox>
<CoordinatesInputStory {...nextProps} />

Check failure on line 111 in e2e/base/fields/CoordinatesInput.spec.tsx

View workflow job for this annotation

GitHub Actions / Type

Type '{ defaultValue: number[]; className?: string | undefined; coordinatesFormat: CoordinatesFormat; disabled?: boolean | undefined; error?: string | undefined; isErrorMessageHidden?: boolean | undefined; ... 9 more ...; style?: CSSProperties | undefined; }' is not assignable to type 'CoordinatesInputProps' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
</StoryBox>
)

cy.getDataCy('coordinates-dd-input-lat').should('have.value', '47.123000')
})
})
})

0 comments on commit f069969

Please sign in to comment.