Skip to content

Commit

Permalink
MMT-3926: Fix for Science Keyword Picker Adds An Additional Science K…
Browse files Browse the repository at this point in the history
…eyword That Was Not Originally Selected (#1324)

* MMT-3926: Fix for Science Keyword Picker Adds An Additional Science Keyword That Was Not Originally Selected
  • Loading branch information
cgokey authored Dec 9, 2024
1 parent 30375f8 commit 94ad25e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
9 changes: 8 additions & 1 deletion static/src/js/components/KeywordPicker/KeywordPicker.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import React, { useEffect, useState } from 'react'
import React, {
useEffect,
useRef,
useState
} from 'react'
import PropTypes from 'prop-types'
import { cloneDeep, isEmpty } from 'lodash-es'
import { Typeahead } from 'react-bootstrap-typeahead'
Expand Down Expand Up @@ -48,6 +52,7 @@ const KeywordPicker = ({

const [marginTop, setMarginTop] = useState(0)
const [marginLeft, setMarginLeft] = useState(0)
const typeaheadRef = useRef(null)

const filterKeywords = (path) => {
const filteredPath = []
Expand Down Expand Up @@ -272,6 +277,7 @@ const KeywordPicker = ({
}

onChange(formData)
typeaheadRef.current.clear()
}

const displayItems = (item) => {
Expand Down Expand Up @@ -427,6 +433,7 @@ const KeywordPicker = ({
<div className="eui-item-list-pane" style={{ marginTop }}>
<div className="keyword-picker__search-keywords">
<Typeahead
ref={typeaheadRef}
clearButton
id="keyword-picker-search"
isLoading={loading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import React from 'react'

import { test } from 'vitest'
import useControlledKeywords from '../../../hooks/useControlledKeywords'

import parseCmrResponse from '../../../utils/parseCmrResponse'
Expand Down Expand Up @@ -346,24 +347,39 @@ describe('when removing selected keyword', () => {
})

describe('when searching for a keyword', () => {
test('adds the searched keyword', async () => {
const { props, user } = setup()
describe('and user selects a keyword', () => {
test('adds the searched keyword', async () => {
const { props, user } = setup()

const searchBox = screen.getByRole('combobox')

await user.type(searchBox, 'Earth')
const option = screen.getByRole('option', { name: 'EARTH SCIENCE SERVICES>DATA ANALYSIS AND VISUALIZATION>GEOGRAPHIC INFORMATION SYSTEMS>DESKTOP GEOGRAPHIC INFORMATION SYSTEMS' })
await user.click(option)

expect(props.onChange).toHaveBeenCalledTimes(1)
expect(props.onChange).toHaveBeenCalledWith([
{
ToolCategory: 'EARTH SCIENCE SERVICES',
ToolTopic: 'DATA ANALYSIS AND VISUALIZATION',
ToolTerm: 'GEOGRAPHIC INFORMATION SYSTEMS',
ToolSpecificTerm: 'DESKTOP GEOGRAPHIC INFORMATION SYSTEMS'
}
])
})

const searchBox = screen.getByRole('combobox')
test('clears the search box after the selection', async () => {
const { user } = setup()

await user.type(searchBox, 'Earth')
const option = screen.getByRole('option', { name: 'EARTH SCIENCE SERVICES>DATA ANALYSIS AND VISUALIZATION>GEOGRAPHIC INFORMATION SYSTEMS>DESKTOP GEOGRAPHIC INFORMATION SYSTEMS' })
await user.click(option)
const searchBox = screen.getByRole('combobox')

expect(props.onChange).toHaveBeenCalledTimes(1)
expect(props.onChange).not.toHaveBeenCalledWith([
{
ToolCategory: 'EARTH SCIENCE SERVICES',
ToolTopic: 'DATA ANALYSIS AND VISUALIZATION',
ToolTerm: 'CALIBRATION/VALIDATION',
ToolSpecificTerm: undefined
}
])
await user.type(searchBox, 'Earth')

expect(searchBox).toHaveValue('Earth')
const option = screen.getByRole('option', { name: 'EARTH SCIENCE SERVICES>DATA ANALYSIS AND VISUALIZATION>GEOGRAPHIC INFORMATION SYSTEMS>DESKTOP GEOGRAPHIC INFORMATION SYSTEMS' })
await user.click(option)
expect(searchBox).toHaveValue('')
})
})

describe('when keyword recommender is included', () => {
Expand Down

0 comments on commit 94ad25e

Please sign in to comment.