Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/artesca 14165 capacity decimals issue #791

Merged
merged 2 commits into from
Dec 19, 2024
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
11 changes: 11 additions & 0 deletions src/react/ui-elements/Veeam/VeeamCapacityModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { bucketName } from '../../../js/mock/S3Client';
import { NewWrapper, TEST_API_BASE_URL } from '../../utils/testUtil';
import { VeeamCapacityModal } from './VeeamCapacityModal';
import { VEEAM_XML_PREFIX } from './VeeamConstants';
import userEvent from '@testing-library/user-event';

describe('VeeamCapacityModal', () => {
const mockMutate = jest.fn();
Expand Down Expand Up @@ -52,6 +53,16 @@ describe('VeeamCapacityModal', () => {
expect(selectors.modalTitle()).toBeInTheDocument();
});

it('should enabled edit button when value is valid', async () => {
await userEvent.click(selectors.editBtn());

await userEvent.clear(selectors.capacityInput());
expect(selectors.editModalBtn()).toBeDisabled();
await userEvent.type(selectors.capacityInput(), '2.2');

expect(selectors.editModalBtn()).toBeEnabled();
});
JeanMarcMilletScality marked this conversation as resolved.
Show resolved Hide resolved

it('should call mutate function when edit button is clicked', async () => {
fireEvent.click(selectors.editBtn());
fireEvent.change(selectors.capacityInput(), { target: { value: '200' } });
Expand Down
8 changes: 2 additions & 6 deletions src/react/ui-elements/Veeam/VeeamCapacityModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ import {
VEEAM_XML_PREFIX,
} from './VeeamConstants';
import { getCapacityBytes, useCapacityUnit } from './useCapacityUnit';
import { checkDecimals } from './VeeamConfiguration';

const schema = Joi.object({
capacity: Joi.number()
.required()
.min(1)
.max(1024)
.custom((value, helpers) => {
if (!Number.isInteger(value * 100)) {
return helpers.message({
custom: '"capacity" must have at most 2 decimals',
});
}
return value;
return checkDecimals(value, helpers);
}),
capacityUnit: Joi.string().required(),
});
Expand Down
13 changes: 13 additions & 0 deletions src/react/ui-elements/Veeam/VeeamConfiguration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ describe('Veeam Configuration UI', () => {
expect(selectors.accountNameInput()).toHaveValue('Veeam');
});
});
it('should enabled continnue button if capacity value is valid', async () => {
//S
mockUseAccountsImplementation();
renderVeeamConfigurationForm();
await userEvent.type(selectors.accountNameInput(), 'Veeam');
await userEvent.type(selectors.repositoryInput(), 'veeam-bucket');
//E
await userEvent.clear(selectors.maxCapacityInput());
expect(selectors.continueButton()).toBeDisabled();
await userEvent.type(selectors.maxCapacityInput(), '2.2');
//V
expect(selectors.continueButton()).toBeEnabled();
});
it('should show validation error if the max capacity is less than 1', async () => {
//S
mockUseAccountsImplementation();
Expand Down
22 changes: 14 additions & 8 deletions src/react/ui-elements/Veeam/VeeamConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ import { useAccountsLocationsAndEndpoints } from '../../../react/next-architectu
import { useAccountsLocationsEndpointsAdapter } from '../../..//react/next-architecture/ui/AccountsLocationsEndpointsAdapterProvider';
import { VeeamLogo } from './VeeamLogo';

export const checkDecimals = (value: number, helpers: Joi.CustomHelpers) => {
const stringValue = value.toString();
if (stringValue.includes('.')) {
const decimals = stringValue.split('.')[1];
if (decimals.length > 2) {
return helpers.message({
custom: '"capacity" must have at most 2 decimals',
});
}
}
return value;
};

const schema = Joi.object({
accountName: accountNameValidationSchema,
bucketName: bucketNameValidationSchema,
Expand All @@ -50,14 +63,7 @@ const schema = Joi.object({
.required()
.min(1)
.max(1024)
.custom((value, helpers) => {
if (!Number.isInteger(value * 100)) {
return helpers.message({
custom: '"capacity" must have at most 2 decimals',
});
}
return value;
}),
.custom((value, helpers) => checkDecimals(value, helpers)),
otherwise: Joi.valid(),
}),
capacityUnit: Joi.when('application', {
Expand Down
Loading