Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.
Open
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
13 changes: 12 additions & 1 deletion cypress/integration/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ context('Calls tests', () => {
);
});

it('A user-officer should not be able to set negative availability time on instrument per call', () => {
it('A user-officer should not be able to set negative or too high availability time on instrument per call', () => {
cy.assignInstrumentToCall({
callId: createdCallId,
instrumentIds: [createdInstrumentId],
Expand All @@ -516,6 +516,17 @@ context('Calls tests', () => {
.click();

cy.notification({ variant: 'error', text: 'must be positive number' });
cy.get('[data-cy="availability-time"]').type('2147483648');

cy.contains(instrumentAssignedToCall.shortCode)
.parent()
.find('[aria-label="Save"]')
.click();

cy.notification({
variant: 'error',
text: 'Availability time can not be grater than 2147483647',
});
});

it('A user-officer should be able to set availability time on instrument per call', () => {
Expand Down
20 changes: 20 additions & 0 deletions src/components/call/AssignedInstrumentsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const AssignedInstrumentsTable: React.FC<AssignedInstrumentsTableProps> = ({
type: 'numeric',
emptyValue: '-',
editComponent: availabilityTimeInput,
align: 'left',
},
];

Expand Down Expand Up @@ -147,6 +148,25 @@ const AssignedInstrumentsTable: React.FC<AssignedInstrumentsTableProps> = ({
instrumentUpdatedData.availabilityTime &&
+instrumentUpdatedData.availabilityTime > 0
) {
// NOTE: Preventing inputs grater than 32-bit integer.
const max32BitInteger = Math.pow(2, 31);
if (
+instrumentUpdatedData.availabilityTime >= max32BitInteger
) {
enqueueSnackbar(
`Availability time can not be grater than ${
max32BitInteger - 1
}`,
{
variant: 'error',
className: 'snackbar-error',
}
);
reject();

return;
}

await updateInstrument({
id: instrumentUpdatedData.id,
availabilityTime: instrumentUpdatedData.availabilityTime,
Expand Down