{"size": 2124, "ext": "js", "max_stars_repo_path": "src/hooks/__tests__/useCommands.test.js", "max_stars_repo_name": "untemps/react-vocal", "max_stars_repo_stars_event_min_datetime": "2020-06-02T18:37:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-14T20:29:46.000Z", "max_issues_repo_path": "src/hooks/__tests__/useCommands.test.js", "max_issues_repo_name": "untemps/react-vocal", "max_issues_repo_issues_event_min_datetime": "2020-06-04T12:45:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T18:31:49.000Z", "max_forks_repo_path": "src/hooks/__tests__/useCommands.test.js", "max_forks_repo_name": "untemps/react-vocal", "max_forks_repo_forks_event_min_datetime": "2020-12-12T05:51:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-14T20:29:41.000Z"}
{"max_stars_count": 12, "max_issues_count": 58, "max_forks_count": 3, "avg_line_length": 32.6769230769, "max_line_length": 86, "alphanum_fraction": 0.6407721281}
import { renderHook } from '@testing-library/react-hooks'

import useCommands from '../useCommands'

describe('useCommands', () => {
	it('returns triggerCommand function', () => {
		const triggerCommand = renderHook(() => useCommands())
		expect(triggerCommand).toBeDefined()
	})

	it('triggers callback mapped to the exact input', () => {
		const commands = {
			foo: () => 'bar',
		}
		const {
			result: { current: triggerCommand },
		} = renderHook(() => useCommands(commands))
		expect(triggerCommand('foo')).toBe('bar')
	})

	it('passes input as callback argument', () => {
		const commands = {
			foo: (input) => input,
		}
		const {
			result: { current: triggerCommand },
		} = renderHook(() => useCommands(commands))
		expect(triggerCommand('foo')).toBe('foo')
	})

	describe('Approximate inputs', () => {
		const value = 'foo'
		it.each([
			['Change la bordure en vert', 'Change la bordure en verre', value],
			['Change la bordure en vert', 'Change la bordure en verres', value],
			['Change la bordure en vert', 'Change la bordure en vers', value],
			['Change la bordure en vert', 'Change la bordure en vairs', value],
			['Change la bordure en vert', 'Changez la bordure en verre', value],
			['Change la bordure en vert', 'Changez la bodure en verre', null],
			['Change la bordure en vert', 'Change la bordure en rouge', null],
			['Change la bordure en vert', 'Change la bordure en verre de rouge', null],
			['Change la bordure en vert', 'Change la bordure en violet', null],
			['Change la bordure en vert', 'Modifie la bordure en violet', null],
		])('triggers callback mapped to approximate inputs', (command, input, expected) => {
			const commands = {
				[command]: () => value,
			}
			const {
				result: { current: triggerCommand },
			} = renderHook(() => useCommands(commands))
			expect(triggerCommand(input)).toBe(expected)
		})
	})

	it('returns null as no command is mapped to the input', () => {
		const commands = {
			foo: () => 'bar',
		}
		const {
			result: { current: triggerCommand },
		} = renderHook(() => useCommands(commands))
		expect(triggerCommand('gag')).toBeNull()
	})
})
