|
@@ -1,8 +1,9 @@ |
|
|
import * as React from 'react'; |
|
|
import * as React from 'react'; |
|
|
import { |
|
|
import { |
|
|
cleanup, |
|
|
|
|
|
render, |
|
|
|
|
|
screen, |
|
|
|
|
|
|
|
|
cleanup, fireEvent, |
|
|
|
|
|
render, |
|
|
|
|
|
screen, |
|
|
|
|
|
act, waitFor, |
|
|
} from '@testing-library/react'; |
|
|
} from '@testing-library/react'; |
|
|
import userEvent from '@testing-library/user-event'; |
|
|
import userEvent from '@testing-library/user-event'; |
|
|
import { TextControl } from '@tesseract-design/web-base'; |
|
|
import { TextControl } from '@tesseract-design/web-base'; |
|
@@ -91,6 +92,102 @@ describe('MaskedTextInput', () => { |
|
|
expect(indicator).toBeInTheDocument(); |
|
|
expect(indicator).toBeInTheDocument(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('renders the indicator changing when switching visibility state', async () => { |
|
|
|
|
|
render( |
|
|
|
|
|
<MaskedTextInput |
|
|
|
|
|
enhanced |
|
|
|
|
|
/>, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const indicator = screen.getByTestId('indicator'); |
|
|
|
|
|
|
|
|
|
|
|
await userEvent.click(indicator); |
|
|
|
|
|
expect(indicator).toHaveTextContent('Hide'); |
|
|
|
|
|
|
|
|
|
|
|
await userEvent.click(indicator); |
|
|
|
|
|
expect(indicator).toHaveTextContent('Show'); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('renders the indicator changing when switching visibility state using function ref', async () => { |
|
|
|
|
|
render( |
|
|
|
|
|
<MaskedTextInput |
|
|
|
|
|
enhanced |
|
|
|
|
|
ref={vi.fn()} |
|
|
|
|
|
/>, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const indicator = screen.getByTestId('indicator'); |
|
|
|
|
|
|
|
|
|
|
|
await userEvent.click(indicator); |
|
|
|
|
|
expect(indicator).toHaveTextContent('Hide'); |
|
|
|
|
|
|
|
|
|
|
|
await userEvent.click(indicator); |
|
|
|
|
|
expect(indicator).toHaveTextContent('Show'); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('highlights the indicator when visibility is toggled via keyboard', async () => { |
|
|
|
|
|
render( |
|
|
|
|
|
<MaskedTextInput |
|
|
|
|
|
enhanced |
|
|
|
|
|
/>, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const input = screen.getByTestId('input'); |
|
|
|
|
|
const indicator = screen.getByTestId('indicator'); |
|
|
|
|
|
|
|
|
|
|
|
input.focus(); |
|
|
|
|
|
fireEvent.keyDown(input, { code: 'Space', ctrlKey: true }); |
|
|
|
|
|
expect(indicator).toHaveClass('text-tertiary'); |
|
|
|
|
|
|
|
|
|
|
|
fireEvent.keyUp(input, { code: 'Space', ctrlKey: true }); |
|
|
|
|
|
expect(indicator).toHaveClass('text-primary'); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles keydown events', async () => { |
|
|
|
|
|
const onKeyDown = vi.fn(); |
|
|
|
|
|
render( |
|
|
|
|
|
<MaskedTextInput |
|
|
|
|
|
enhanced |
|
|
|
|
|
onKeyDown={onKeyDown} |
|
|
|
|
|
/>, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const input = screen.getByTestId('input'); |
|
|
|
|
|
|
|
|
|
|
|
input.focus(); |
|
|
|
|
|
fireEvent.keyDown(input, { code: 'Space', ctrlKey: true }); |
|
|
|
|
|
expect(onKeyDown).toBeCalled(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles keyup events', async () => { |
|
|
|
|
|
const onKeyUp = vi.fn(); |
|
|
|
|
|
render( |
|
|
|
|
|
<MaskedTextInput |
|
|
|
|
|
enhanced |
|
|
|
|
|
onKeyUp={onKeyUp} |
|
|
|
|
|
/>, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const input = screen.getByTestId('input'); |
|
|
|
|
|
|
|
|
|
|
|
input.focus(); |
|
|
|
|
|
fireEvent.keyUp(input, { code: 'Space', ctrlKey: true }); |
|
|
|
|
|
expect(onKeyUp).toBeCalled(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('accepts a function ref', () => { |
|
|
|
|
|
const ref = vi.fn(); |
|
|
|
|
|
|
|
|
|
|
|
render( |
|
|
|
|
|
<MaskedTextInput |
|
|
|
|
|
enhanced |
|
|
|
|
|
ref={ref} |
|
|
|
|
|
/>, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
expect(ref).toBeCalled(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
describe.each` |
|
|
describe.each` |
|
|
size | inputClassName | hintClassName | indicatorClassName |
|
|
size | inputClassName | hintClassName | indicatorClassName |
|
|
${'small'} | ${'h-10'} | ${'pr-10'} | ${'w-10'} |
|
|
${'small'} | ${'h-10'} | ${'pr-10'} | ${'w-10'} |
|
|