Explorar el Código

fix: goto-anything command filter should only match shortcut (#23862)

tags/1.8.0
lyzno1 hace 2 meses
padre
commit
e0fe0e1a3e
No account linked to committer's email address

+ 16
- 16
web/__tests__/goto-anything/command-selector.test.tsx Ver fichero

}, },
knowledge: { knowledge: {
key: '@knowledge', key: '@knowledge',
shortcut: '@knowledge',
shortcut: '@kb',
title: 'Search Knowledge', title: 'Search Knowledge',
description: 'Search knowledge bases', description: 'Search knowledge bases',
search: jest.fn(), search: jest.fn(),
) )


expect(screen.getByTestId('command-item-@app')).toBeInTheDocument() expect(screen.getByTestId('command-item-@app')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@knowledge')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@kb')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument() expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@node')).toBeInTheDocument() expect(screen.getByTestId('command-item-@node')).toBeInTheDocument()
}) })
) )


expect(screen.getByTestId('command-item-@app')).toBeInTheDocument() expect(screen.getByTestId('command-item-@app')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@knowledge')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@kb')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument() expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@node')).toBeInTheDocument() expect(screen.getByTestId('command-item-@node')).toBeInTheDocument()
}) })
) )


expect(screen.queryByTestId('command-item-@app')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@app')).not.toBeInTheDocument()
expect(screen.getByTestId('command-item-@knowledge')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@kb')).toBeInTheDocument()
expect(screen.queryByTestId('command-item-@plugin')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@plugin')).not.toBeInTheDocument()
expect(screen.queryByTestId('command-item-@node')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@node')).not.toBeInTheDocument()
}) })
) )


expect(screen.getByTestId('command-item-@app')).toBeInTheDocument() expect(screen.getByTestId('command-item-@app')).toBeInTheDocument()
expect(screen.queryByTestId('command-item-@knowledge')).not.toBeInTheDocument()
expect(screen.queryByTestId('command-item-@kb')).not.toBeInTheDocument()
expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument() expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument()
expect(screen.queryByTestId('command-item-@node')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@node')).not.toBeInTheDocument()
}) })
) )


expect(screen.getByTestId('command-item-@app')).toBeInTheDocument() expect(screen.getByTestId('command-item-@app')).toBeInTheDocument()
expect(screen.queryByTestId('command-item-@knowledge')).not.toBeInTheDocument()
expect(screen.queryByTestId('command-item-@kb')).not.toBeInTheDocument()
}) })


it('should match partial strings', () => { it('should match partial strings', () => {
<CommandSelector <CommandSelector
actions={mockActions} actions={mockActions}
onCommandSelect={mockOnCommandSelect} onCommandSelect={mockOnCommandSelect}
searchFilter="nowl"
searchFilter="od"
/>, />,
) )


expect(screen.queryByTestId('command-item-@app')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@app')).not.toBeInTheDocument()
expect(screen.getByTestId('command-item-@knowledge')).toBeInTheDocument()
expect(screen.queryByTestId('command-item-@kb')).not.toBeInTheDocument()
expect(screen.queryByTestId('command-item-@plugin')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@plugin')).not.toBeInTheDocument()
expect(screen.queryByTestId('command-item-@node')).not.toBeInTheDocument()
expect(screen.getByTestId('command-item-@node')).toBeInTheDocument()
}) })
}) })


) )


expect(screen.queryByTestId('command-item-@app')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@app')).not.toBeInTheDocument()
expect(screen.queryByTestId('command-item-@knowledge')).not.toBeInTheDocument()
expect(screen.queryByTestId('command-item-@kb')).not.toBeInTheDocument()
expect(screen.queryByTestId('command-item-@plugin')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@plugin')).not.toBeInTheDocument()
expect(screen.queryByTestId('command-item-@node')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@node')).not.toBeInTheDocument()


/>, />,
) )


expect(mockOnCommandValueChange).toHaveBeenCalledWith('@knowledge')
expect(mockOnCommandValueChange).toHaveBeenCalledWith('@kb')
}) })


it('should not call onCommandValueChange if current value still exists', () => { it('should not call onCommandValueChange if current value still exists', () => {
/>, />,
) )


const knowledgeItem = screen.getByTestId('command-item-@knowledge')
const knowledgeItem = screen.getByTestId('command-item-@kb')
fireEvent.click(knowledgeItem) fireEvent.click(knowledgeItem)


expect(mockOnCommandSelect).toHaveBeenCalledWith('@knowledge')
expect(mockOnCommandSelect).toHaveBeenCalledWith('@kb')
}) })
}) })


) )


expect(screen.getByTestId('command-item-@app')).toBeInTheDocument() expect(screen.getByTestId('command-item-@app')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@knowledge')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@kb')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument() expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@node')).toBeInTheDocument() expect(screen.getByTestId('command-item-@node')).toBeInTheDocument()
}) })
) )


expect(screen.getByTestId('command-item-@app')).toBeInTheDocument() expect(screen.getByTestId('command-item-@app')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@knowledge')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@kb')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument() expect(screen.getByTestId('command-item-@plugin')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@node')).toBeInTheDocument() expect(screen.getByTestId('command-item-@node')).toBeInTheDocument()
}) })
/>, />,
) )


expect(screen.getByTestId('command-item-@knowledge')).toBeInTheDocument()
expect(screen.getByTestId('command-item-@kb')).toBeInTheDocument()
expect(screen.queryByTestId('command-item-@app')).not.toBeInTheDocument() expect(screen.queryByTestId('command-item-@app')).not.toBeInTheDocument()
}) })
}) })

+ 0
- 1
web/app/components/goto-anything/command-selector.tsx Ver fichero

return true return true
const filterLower = searchFilter.toLowerCase() const filterLower = searchFilter.toLowerCase()
return action.shortcut.toLowerCase().includes(filterLower) return action.shortcut.toLowerCase().includes(filterLower)
|| action.key.toLowerCase().includes(filterLower)
}) })


useEffect(() => { useEffect(() => {

Cargando…
Cancelar
Guardar