Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into fix-date-range
Browse files Browse the repository at this point in the history
  • Loading branch information
ilsanchez authored Nov 20, 2023
2 parents 9933229 + 98c3c66 commit 7b394a7
Show file tree
Hide file tree
Showing 5 changed files with 517 additions and 1 deletion.
175 changes: 175 additions & 0 deletions cypress/component/GeographicLocationWidget.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import React from 'react'

import { GeographicLocationWidget, TooltipProvider } from '../../src'

const Form = ({
children,
handleSubmit
}: {
children: React.ReactNode
handleSubmit?: (...args: any) => void
}) => {
return (
<form
onSubmit={ev => {
ev.preventDefault()
const formData = new FormData(ev.currentTarget)
handleSubmit([...formData.entries()])
}}
>
{children}
<button>submit</button>
</form>
)
}

const Wrapper = ({
children,
handleSubmit
}: {
children: React.ReactNode
handleSubmit?: (...args: any) => void
}) => {
return (
<TooltipProvider>
<Form>{children}</Form>
</TooltipProvider>
)
}

describe('<GeographicLocationWidget />', () => {
afterEach(() => {
cy.clearLocalStorage()
})

it('renders a GeographicLocationWidget', () => {
cy.mount(
<Wrapper>
<GeographicLocationWidget
configuration={{
type: 'GeographicLocationWidget',
name: 'name',
label: 'The label',
required: true,
details: {},
help: 'The help'
}}
/>
</Wrapper>
)
})

it('can write', () => {
cy.mount(
<Wrapper>
<GeographicLocationWidget
configuration={{
type: 'GeographicLocationWidget',
name: 'dataposition',
label: 'The label',
required: true,
details: {},
help: 'The help'
}}
/>
</Wrapper>
)

// Get input with name 'dataposition[0]'
cy.get('input[name="dataposition[0]"]').type('1')
cy.get('input[name="dataposition[0]"]').should('have.value', '1')

// Get input with name 'dataposition[1]'
cy.get('input[name="dataposition[1]"]').type('2')
cy.get('input[name="dataposition[1]"]').should('have.value', '2')
})

/*
* hydration tests
*/

it('hydrates its selection (string)', () => {
localStorage.setItem(
'formSelection',
JSON.stringify({
dataset: 'fake',
inputs: { dataposition: [10, 20] }
})
)

cy.mount(
<Wrapper>
<GeographicLocationWidget
configuration={{
type: 'GeographicLocationWidget',
name: 'dataposition',
label: 'The label',
required: true,
details: {},
help: 'The help'
}}
/>
</Wrapper>
)

cy.get('input[name="dataposition[0]"]').should('have.value', '10')
cy.get('input[name="dataposition[1]"]').should('have.value', '20')
})

/*
* Test to prevent setting values outside of the range
* < -180 or > 180 for X (default)
* < -90 or > 90 for Y (default)
*/

it('Test to prevent setting values outside of the range', () => {
localStorage.setItem(
'formSelection',
JSON.stringify({
dataset: 'fake',
inputs: { dataposition: [10, 20] }
})
)

cy.mount(
<Wrapper>
<GeographicLocationWidget
configuration={{
type: 'GeographicLocationWidget',
name: 'dataposition',
label: 'The label',
required: true,
details: {
minX: -20,
maxX: 20,
minY: -10,
maxY: 10
},
help: 'The help'
}}
/>
</Wrapper>
)

cy.get('input[name="dataposition[0]"]').should('have.value', '10')
cy.get('input[name="dataposition[1]"]').should('have.value', '20')

// Has an error message
cy.get('span[role="alert"]').should('exist')
cy.get('span[role="alert"]').should(
'have.text',
'Latitude must be less than 10.\n'
)

// Check for input aria-invalid="true"
cy.get('input[name="dataposition[1]"]').should(
'have.attr',
'aria-invalid',
'true'
)

// The error message is removed when the value is changed
cy.get('input[name="dataposition[1]"]').clear().type('5')
cy.get('span[role="alert"]').should('not.exist')
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ecmwf-projects/cads-ui-library",
"version": "7.1.2",
"version": "8.0.6",
"description": "Common UI kit library",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export { LicenceWidget } from './widgets/LicenceWidget'
export { TextWidget } from './widgets/TextWidget'
export { KeywordSearchWidget } from './widgets/KeywordSearchWidget'
export { GeographicExtentWidget } from './widgets/GeographicExtentWidget'
export { GeographicLocationWidget } from './widgets/GeographicLocationWidget'
export { ExclusiveGroupWidget } from './widgets/ExclusiveGroupWidget'
export { StringListWidget } from './widgets/StringListWidget'
export { StringChoiceWidget } from './widgets/StringChoiceWidget'
Expand Down
2 changes: 2 additions & 0 deletions src/types/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LicenceWidgetConfiguration } from '../widgets/LicenceWidget'
import { ExclusiveGroupWidgetConfiguration } from '../widgets/ExclusiveGroupWidget'
import { FreeformInputWidgetConfiguration } from '../widgets/FreeformInputWidget'
import { DateRangeWidgetConfiguration } from '../widgets/DateRangeWidget'
import { GeographicLocationWidgetConfiguration } from '../widgets/GeographicLocationWidget'

export type FormConfiguration =
| ExclusiveGroupWidgetConfiguration
Expand All @@ -18,3 +19,4 @@ export type FormConfiguration =
| LicenceWidgetConfiguration
| FreeformInputWidgetConfiguration
| DateRangeWidgetConfiguration
| GeographicLocationWidgetConfiguration
Loading

0 comments on commit 7b394a7

Please sign in to comment.