Skip to content

Commit

Permalink
update number input testing
Browse files Browse the repository at this point in the history
  • Loading branch information
eburdekin committed Jul 29, 2024
1 parent 54c499c commit e7e03c9
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions products/statement-generator/src/tests/inputs.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from '@testing-library/react';
import { render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';

Expand Down Expand Up @@ -33,8 +33,8 @@ describe('Input component', () => {
<Input
id="test"
handleChange={() => {}}
defaultValue="0"
placeholder="0"
defaultValue="0"
type="number"
/>
</ThemeProvider>
Expand All @@ -43,8 +43,8 @@ describe('Input component', () => {
const input = getByRole(/spinbutton/i) as HTMLInputElement;

// number inputs don't allow numbers < 0
//
//
fireEvent.keyDown(input, { key: 'ArrowDown', code: 'ArrowDown' });
expect(input).toHaveValue(0);

// valid responses show valid icon
userEvent.type(input, '35');
Expand All @@ -60,13 +60,7 @@ describe('Input component', () => {
test('Inputs validate text responses', () => {
const { getByTestId, getByRole } = render(
<ThemeProvider theme={customMuiTheme}>
<Input
id="test"
handleChange={() => {}}
defaultValue="0"
placeholder="0"
type="text"
/>
<Input id="test" handleChange={() => {}} placeholder="" type="text" />
</ThemeProvider>
);

Expand Down Expand Up @@ -94,9 +88,14 @@ describe('Input component', () => {
input: HTMLElement,
expectedProps: ExpectedProps
) => {
expect(input).toHaveAttribute('placeholder', expectedProps.placeholder);
expect(input).toHaveAttribute('id', expectedProps.id);
expect(input).toHaveAttribute('type', expectedProps.type);
const attributes: (keyof typeof expectedProps)[] = [
'placeholder',
'id',
'type',
];
attributes.forEach((attr) => {
expect(input).toHaveAttribute(attr, expectedProps[attr]);
});
};

const { getByPlaceholderText } = render(
Expand Down

0 comments on commit e7e03c9

Please sign in to comment.