Skip to content

Commit

Permalink
limit sample size range input to integers
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelolo24 committed Jun 13, 2024
1 parent a38852d commit 5fc208e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,42 @@ describe('UnifiedDataTableAdditionalDisplaySettings', function () {

expect(onChangeSampleSizeMock).not.toHaveBeenCalled();
});

it('should only render integers when a decimal value is provided', async () => {
const invalidDecimalValue = 6.11;
const validIntegerValue = 6;

const onChangeSampleSizeMock = jest.fn();

const component = mountWithIntl(
<UnifiedDataTableAdditionalDisplaySettings
maxAllowedSampleSize={500}
sampleSize={50}
onChangeSampleSize={onChangeSampleSizeMock}
rowHeight={RowHeightMode.custom}
rowHeightLines={10}
headerRowHeight={RowHeightMode.custom}
headerRowHeightLines={5}
/>
);
const input = findTestSubject(component, 'unifiedDataTableSampleSizeInput').last();
expect(input.prop('value')).toBe(50);

await act(async () => {
input.simulate('change', {
target: {
value: invalidDecimalValue,
},
});
});

await new Promise((resolve) => setTimeout(resolve, 0));
component.update();

expect(
findTestSubject(component, 'unifiedDataTableSampleSizeInput').last().prop('value')
).toBe(validIntegerValue);
});
});

describe('rowHeight', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const UnifiedDataTableAdditionalDisplaySettings: React.FC<
return;
}

const newSampleSize = Number(event.target.value);
const newSampleSize = parseInt(event.target.value, 10) ?? RANGE_MIN_SAMPLE_SIZE;

if (newSampleSize >= MIN_ALLOWED_SAMPLE_SIZE) {
setActiveSampleSize(newSampleSize);
Expand Down

0 comments on commit 5fc208e

Please sign in to comment.