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
22 changes: 22 additions & 0 deletions static/app/components/arithmeticBuilder/token/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,28 @@ describe('token', () => {
expect(await screen.findByRole('row', {name: '10'})).toBeInTheDocument();
expect(screen.getByTestId(dataTestId)).toBeInTheDocument();
});

it('completes literal on blur', async () => {
const dispatch = jest.fn();
render(<Tokens expression="1" dispatch={dispatch} />);

expect(await screen.findByRole('row', {name: '1'})).toBeInTheDocument();

const input = screen.getByRole('textbox', {
name: 'Add a literal',
});
expect(input).toBeInTheDocument();

await userEvent.click(input);
expect(input).toHaveFocus();
expect(input).toHaveValue('1');
await userEvent.type(input, '00');

// Tab away to trigger blur without pressing Enter
await userEvent.tab();

expect(await screen.findByRole('row', {name: '100'})).toBeInTheDocument();
});
});

describe('ArithmeticTokenOperator', () => {
Expand Down
9 changes: 8 additions & 1 deletion static/app/components/arithmeticBuilder/token/literal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@ function InternalInput({item, state, token}: InternalInputProps) {
}, [updateSelectionIndex]);

const onInputBlur = useCallback(() => {
const trimmed = inputValue.trim();
const text = validateLiteral(trimmed) ? trimmed : token.text;
dispatch({
text,
type: 'REPLACE_TOKEN',
token,
});
resetInputValue();
}, [resetInputValue]);
}, [dispatch, inputValue, token, resetInputValue]);

const onInputChange = useCallback(
(evt: ChangeEvent<HTMLInputElement>) => {
Expand Down
Loading