Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMT-3891: Existing country should be displayed in draft form. #1307

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ const CustomCountrySelectWidget = ({
// Removes a country from the country list
const remove = (list, aValue) => list.filter((item) => (item.value !== aValue))

// Returns first country from the country list
// Returns first country from the country list,
// should pick up both forms of country name: short (example 'US') and long form (example 'United States')
const getInitialCountrySelection = () => {
const [selected] = countryData.filter((item) => (item.value === value))
const [selected] = countryData.filter((item) => (item.label === value || item.value === value))

return selected
}
Expand All @@ -84,7 +85,8 @@ const CustomCountrySelectWidget = ({
// Selects a country and propagates onChange
const selectCountry = (val) => {
setSelectedCountry(val)
onChange(val.value)
// Propagates the label (long form of country name)
onChange(val.label)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you confirm with Erich or someone that the long form is what is expected in the json?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only Scott replied to my question (Asked Eric, Scott and Tyler): 'I am thinking long form. Do you all agree?'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tyler also think that long form makes sense

}

// Handles country select event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const setup = (overrideProps = {}) => {
description: 'Test Description'
},
uiSchema: {},
value: 'TZ',
value: 'Tanzania, United Republic of',
...overrideProps
}

Expand Down Expand Up @@ -49,6 +49,19 @@ describe('CustomCountrySelectWidget', () => {
})
})

describe('when existing data has country in short form', () => {
test('renders the component with selected country ', () => {
setup({
value: 'TZ'
})

expect(screen.getByText('My Test Data Label')).toBeInTheDocument()
expect(screen.getByText('Tanzania, United Republic of').className).toContain('singleValue')

expect(screen.queryByText('Select MyTestDataLabel')).not.toBeInTheDocument()
})
})

describe('when title is given by uiSchema', () => {
test('renders the component with title ', () => {
setup({
Expand Down Expand Up @@ -87,7 +100,7 @@ describe('CustomCountrySelectWidget', () => {
const option = screen.getByRole('option', { name: 'United States' })
await user.click(option)

expect(props.onChange).toHaveBeenCalledWith('US')
expect(props.onChange).toHaveBeenCalledWith('United States')
})
})

Expand Down