Skip to content
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 @@ -20,4 +20,48 @@ describe('TableColumnSearchTrigger', () => {
})
expect(searchInput).toHaveValue('*1*')
})

it('should call "handleOpenState" on search blur if input is empty', () => {
const handleOpenState = jest.fn()

render(
<TableColumnSearchTrigger
{...instance(mockedProps)}
isOpen
handleOpenState={handleOpenState}
/>,
)

const searchInput = screen.getByTestId('search')
expect(searchInput).toBeInTheDocument()
expect(searchInput).toHaveValue('')

fireEvent.blur(searchInput)
expect(handleOpenState).toHaveBeenCalledWith(false)
})

it('should not call "handleOpenState" on search blur if input has value', () => {
const handleOpenState = jest.fn()

render(
<TableColumnSearchTrigger
{...instance(mockedProps)}
isOpen
handleOpenState={handleOpenState}
/>,
)

const searchInput = screen.getByTestId('search')
expect(searchInput).toBeInTheDocument()
expect(searchInput).toHaveValue('')

fireEvent.change(searchInput, {
target: { value: '*1*' },
})

expect(searchInput).toHaveValue('*1*')

fireEvent.blur(searchInput)
expect(handleOpenState).not.toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@
}
}

const onKeyDown = (e: React.KeyboardEvent) => {
if (e.key === keys.ENTER) {
const onKeyDown = (event: React.KeyboardEvent) => {

Check warning on line 55 in redisinsight/ui/src/components/table-column-search-trigger/TableColumnSearchTrigger.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
if (event.key === keys.ENTER) {
handleApply(value)
}

Check warning on line 58 in redisinsight/ui/src/components/table-column-search-trigger/TableColumnSearchTrigger.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 58 in redisinsight/ui/src/components/table-column-search-trigger/TableColumnSearchTrigger.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

const handleOnBlur = (event?: React.FocusEvent<HTMLInputElement>) => {
const target = event?.target as HTMLInputElement

if (!target.value) {
handleOpenState(false)
}
}

return (
<div style={{ paddingRight: 10 }}>
<IconButton
Expand All @@ -72,13 +80,14 @@
>
<SearchInput
onKeyDown={onKeyDown}
// onBlur={handleOnBlur}
onBlur={handleOnBlur}
ref={setInputEl}
name={fieldName}
placeholder="Search"
value={value || ''}
onChange={handleChangeValue}
data-testid="search"
style={{ width: '100%' }}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
right: 0;
top: 0;
bottom: 0;
padding: 0;
padding: 8px;
align-items: center;
}
Loading