Skip to content

Commit

Permalink
Remove unused variables from test files.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yadav committed May 12, 2024
1 parent a44af92 commit 824bcd9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 50 deletions.
28 changes: 13 additions & 15 deletions test/library/input.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ describe('NumberFormat as input', () => {
});

it('should render input as type text by default', async () => {
const { input, user } = await render(<NumericFormat />);
const { input } = await render(<NumericFormat />);
expect(input.getAttribute('type')).toBe('text');
});

it('should render input as defined type', async () => {
const { input, user } = await render(<NumericFormat type="tel" />);
const { input } = await render(<NumericFormat type="tel" />);
expect(input.getAttribute('type')).toBe('tel');
});

it('should add inputMode numeric to non Iphone/IPad device by default to input element', async () => {
const { input, user, rerender } = await render(<NumericFormat />);
const { input, rerender } = await render(<NumericFormat />);
expect(input.getAttribute('inputmode')).toBe('numeric');

//should allow updating the inputMode value
Expand All @@ -60,14 +60,14 @@ describe('NumberFormat as input', () => {
});

it('should have initial value', async () => {
const { input, user } = await render(
const { input } = await render(
<NumericFormat value={2456981} thousandSeparator={true} prefix={'$'} />,
);
expect(input).toHaveValue('$2,456,981');
});

it('should load the default value when initial value is null', async () => {
const { input, user } = await render(<NumericFormat value={null} defaultValue={89} />);
const { input } = await render(<NumericFormat value={null} defaultValue={89} />);
expect(input).toHaveValue('89');
});

Expand All @@ -82,7 +82,7 @@ describe('NumberFormat as input', () => {
});

it('should use defaultValue as initial value', async () => {
const { input, user } = await render(
const { input } = await render(
<NumericFormat defaultValue={2456981} thousandSeparator={true} prefix={'$'} />,
);
expect(input).toHaveValue('$2,456,981');
Expand Down Expand Up @@ -331,30 +331,30 @@ describe('NumberFormat as input', () => {

it('should format value when input value is empty and allowEmptyFormatting is true', async () => {
expect(async () => {
const { input, user } = await render(<PatternFormat format="##/##/####" value="" />);
const { input } = await render(<PatternFormat format="##/##/####" value="" />);

expect(input).toHaveValue(' / / ');
});
});

it('should format value when input value is not set and allowEmptyFormatting is true', async () => {
expect(async () => {
const { input, user } = await render(<PatternFormat format="##/##/####" />);
const { input } = await render(<PatternFormat format="##/##/####" />);

expect(input).toHaveValue(' / / ');
});
});

it('should not convert empty string to 0 if valueIsNumericString is true', async () => {
const { input, user } = await render(
const { input } = await render(
<NumericFormat valueIsNumericString={true} value={''} decimalScale={2} />,
);

expect(input).toHaveValue('');
});

it('should not break if null or NaN is provided as value', async () => {
const { input, user, rerender } = await render(<NumericFormat value={null} decimalScale={2} />);
const { input, rerender } = await render(<NumericFormat value={null} decimalScale={2} />);
expect(input).toHaveValue('');

rerender(<NumericFormat value={NaN} decimalScale={2} />);
Expand Down Expand Up @@ -442,9 +442,7 @@ describe('NumberFormat as input', () => {
it('should not call onValueChange if no formatting is applied', async () => {
const mockOnValueChange = vi.fn();

const { input, user, rerender } = await render(
<NumericFormat value="" onValueChange={mockOnValueChange} />,
);
const { rerender } = await render(<NumericFormat value="" onValueChange={mockOnValueChange} />);

expect(mockOnValueChange).not.toHaveBeenCalled();

Expand Down Expand Up @@ -552,7 +550,7 @@ describe('NumberFormat as input', () => {
});

it('should treat Infinity value as empty string', async () => {
const { input, user } = await render(<NumericFormat value={Infinity} />);
const { input } = await render(<NumericFormat value={Infinity} />);

expect(input).toHaveValue('');
});
Expand Down Expand Up @@ -760,7 +758,7 @@ describe('NumberFormat as input', () => {
});

it('should correctly show the decimal values', async () => {
const { input, user, rerender } = await render(
const { input, rerender } = await render(
<NumericFormat
value="123.123"
decimalScale={18}
Expand Down
26 changes: 12 additions & 14 deletions test/library/input_numeric_format.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ import {
*/
describe('Test NumberFormat as input with numeric format options', () => {
it('should show the initial value as $0 when number 0 is passed', async () => {
const { input, user } = await render(
const { input } = await render(
<NumericFormat value={0} thousandSeparator={true} prefix={'$'} />,
);
expect(input).toHaveValue('$0');
});

it('should show the initial value as empty string when empty string is passed and decimalScale is set', async () => {
const { input, user } = await render(
const { input } = await render(
<NumericFormat value="" thousandSeparator={true} decimalScale={2} />,
);
expect(input).toHaveValue('');
});

it('should show the initial value as empty string when empty string is passed and decimalScale is not set', async () => {
const { input, user } = await render(<NumericFormat value="" thousandSeparator={true} />);
const { input } = await render(<NumericFormat value="" thousandSeparator={true} />);
expect(input).toHaveValue('');
});

Expand Down Expand Up @@ -146,7 +146,7 @@ describe('Test NumberFormat as input with numeric format options', () => {
});

it('should update formatted value if any of the props changes', async () => {
const { input, user, rerender } = await render(<NumericFormat value={12345.67} />);
const { input, rerender } = await render(<NumericFormat value={12345.67} />);
expect(input).toHaveValue('12345.67');

rerender(<NumericFormat value={12345.67} thousandSeparator />);
Expand Down Expand Up @@ -220,24 +220,22 @@ describe('Test NumberFormat as input with numeric format options', () => {
});

it('should not add zeros to fixedDecimalScale is not set', async () => {
const { input, user, rerender } = await render(
<NumericFormat decimalScale={4} value={24.45} />,
);
const { input, rerender } = await render(<NumericFormat decimalScale={4} value={24.45} />);
expect(input).toHaveValue('24.45');

rerender(<NumericFormat decimalScale={4} value={24.45678} />);
expect(input).toHaveValue('24.4568');
});

it('should handle fixedDecimalScale correctly #670', async () => {
const { input, user } = await render(
const { input } = await render(
<NumericFormat thousandSeparator value={12} decimalScale={2} fixedDecimalScale />,
);
expect(input).toHaveValue('12.00');
});

it('should not round the initial if decimalScale is not provided', async () => {
const { input, user, rerender } = await render(<NumericFormat value={123213.7535} />);
const { input, rerender } = await render(<NumericFormat value={123213.7535} />);
expect(input).toHaveValue('123213.7535');

rerender(<NumericFormat value={123213.7535} thousandSeparator />);
Expand All @@ -255,7 +253,7 @@ describe('Test NumberFormat as input with numeric format options', () => {
});

it('should round the initial value to given decimalScale', async () => {
const { input, user, rerender } = await render(
const { input, rerender } = await render(
<NumericFormat value={'123213.7536'} valueIsNumericString={true} decimalScale={1} />,
);
expect(input).toHaveValue('123213.8');
Expand Down Expand Up @@ -438,7 +436,7 @@ describe('Test NumberFormat as input with numeric format options', () => {
});

it('should allow decimal separator and thousand separator on suffix prefix', async () => {
const { input, user, rerender } = await render(
const { input, rerender } = await render(
<NumericFormat
value={1231237.56}
thousandSeparator={','}
Expand Down Expand Up @@ -650,7 +648,7 @@ describe('Test NumberFormat as input with numeric format options', () => {

//Issue #140
it('should not give NaN zeros, when decimalScale is 0 and roundedValue will be multiple of 10s, Issue #140', async () => {
const { input, user, rerender } = await render(<NumericFormat value={-9.5} decimalScale={0} />);
const { input, rerender } = await render(<NumericFormat value={-9.5} decimalScale={0} />);
expect(input).toHaveValue('-10');

rerender(<NumericFormat value={-99.5} decimalScale={0} />);
Expand All @@ -677,7 +675,7 @@ describe('Test NumberFormat as input with numeric format options', () => {

it(`should give correct formatted value when decimal value is passed as prop and
decimal scale is set to zero and fixedDecimalScale is true, issue #183`, async () => {
const { input, user } = await render(
const { input } = await render(
<NumericFormat decimalScale={0} fixedDecimalScale={true} value={1.333333333} />,
);
expect(input).toHaveValue('1');
Expand Down Expand Up @@ -760,7 +758,7 @@ describe('Test NumberFormat as input with numeric format options', () => {
});

it('should handle exponential value as prop correctly #506', async () => {
const { input, user } = await render(<NumericFormat value={0.00000001} />);
const { input } = await render(<NumericFormat value={0.00000001} />);
expect(input).toHaveValue('0.00000001');
});

Expand Down
38 changes: 17 additions & 21 deletions test/library/keypress_and_caret.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, vi } from 'vitest';
import { vi } from 'vitest';
import React, { useState } from 'react';
import NumericFormat from '../../src/numeric_format';
import PatternFormat from '../../src/pattern_format';
Expand All @@ -10,10 +10,8 @@ import {
simulateBlurEvent,
simulateKeyInput,
simulateMouseUpEvent,
simulateClickToFocus,
render,
simulatePaste,
clearInput,
simulateTripleClick,
simulateFocus,
} from '../test_util';
Expand Down Expand Up @@ -56,7 +54,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should maintain caret position when isAllowed returns false', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat
isAllowed={({ floatValue }) => {
return floatValue < 100;
Expand All @@ -73,7 +71,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should update caret position when any of the decimal separator is pressed just before the decimal separator #711', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat
value={12}
allowedDecimalSeparators={[',', '.']}
Expand Down Expand Up @@ -320,9 +318,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should bring caret to correct position if user types same number used in format pattern', async () => {
const { input, rerender, user } = await render(
<PatternFormat format="+1 (###) 2##-####" mask="_" />,
);
const { input, user } = await render(<PatternFormat format="+1 (###) 2##-####" mask="_" />);

await simulateKeyInput(user, input, '1', 0, 0);
expect(input.selectionStart).toEqual(5);
Expand All @@ -346,7 +342,7 @@ describe('Test keypress and caret position changes', () => {
});

it('caret position should not change if its on end of input area', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<PatternFormat format="+1 (###) ### # ## US" value="+1 (123) 456 7 89 US" />,
);
await simulateKeyInput(user, input, '{Delete}', 17, 17);
Expand All @@ -355,7 +351,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should remove the numeric part irrespective of the cursor position', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<PatternFormat format="+1 (###) ### # ## US" mask="_" value="+1 (123) 456 7 89 US" />,
);
await simulateKeyInput(user, input, '{Backspace}', 10, 10);
Expand All @@ -378,7 +374,7 @@ describe('Test keypress and caret position changes', () => {

describe('Test delete/backspace with numeric format', () => {
it('should not remove prefix', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat
thousandSeparator=","
prefix="Rs. "
Expand All @@ -392,7 +388,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should not remove suffix', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat
thousandSeparator=","
prefix="Rs. "
Expand All @@ -406,7 +402,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should remove number, irrespective of the cursor position', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat
thousandSeparator=","
prefix="Rs. "
Expand Down Expand Up @@ -438,7 +434,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should maintain correct caret positon while removing the last character and suffix is not defined. Issue #105', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat thousandSeparator="," prefix="$" suffix="" value="$2,342,343" />,
);

Expand All @@ -448,7 +444,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should maintain correct caret position while removing the second last character and suffix is not defined, Issue #116', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat thousandSeparator="," prefix="" suffix="" value="1,000" />,
);

Expand All @@ -460,7 +456,7 @@ describe('Test keypress and caret position changes', () => {
it('should allow removing negation(-), even if its before prefix', async () => {
const spy = vi.fn();

const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat
thousandSeparator=","
suffix=""
Expand All @@ -478,7 +474,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should maintain correct caret position if one of thousand separator is removed due to backspace. #695', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat value={1234567.8901} thousandSeparator="." decimalSeparator="," />,
);

Expand All @@ -490,7 +486,7 @@ describe('Test keypress and caret position changes', () => {

describe('Test arrow keys', () => {
it('should keep caret position between the prefix and suffix', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat
thousandSeparator=","
prefix="Rs. "
Expand Down Expand Up @@ -578,7 +574,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should always keep caret position between suffix and prefix', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat
thousandSeparator=","
prefix="Rs. "
Expand All @@ -595,7 +591,7 @@ describe('Test keypress and caret position changes', () => {
});

it('should correct wrong caret position on focus', async () => {
const { input, rerender, user } = await render(
const { input, user } = await render(
<NumericFormat
thousandSeparator=","
prefix="Rs. "
Expand All @@ -616,7 +612,7 @@ describe('Test keypress and caret position changes', () => {

const onFocus = vi.fn();

const { input, user, unmount } = await render(<NumericFormat onFocus={onFocus} />);
const { input, unmount } = await render(<NumericFormat onFocus={onFocus} />);

// Fails if input receives focus by clicking.
// await simulateClickToFocus(user, input);
Expand Down

0 comments on commit 824bcd9

Please sign in to comment.