From 867c61e446056a1af56dea535d081aaa6df8a856 Mon Sep 17 00:00:00 2001 From: YanJin Date: Thu, 21 Mar 2024 11:52:16 +0100 Subject: [PATCH] Add test to cover the max capacity to only one decimal --- .../Veeam/VeeamConfiguration.test.tsx | 19 +++++++++++++++++-- src/react/ui-elements/Veeam/VeeamSummary.tsx | 2 +- .../ui-elements/Veeam/useCapacityUnit.ts | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/react/ui-elements/Veeam/VeeamConfiguration.test.tsx b/src/react/ui-elements/Veeam/VeeamConfiguration.test.tsx index 97890be08..f6e4a8971 100644 --- a/src/react/ui-elements/Veeam/VeeamConfiguration.test.tsx +++ b/src/react/ui-elements/Veeam/VeeamConfiguration.test.tsx @@ -26,6 +26,8 @@ describe('Veeam Configuration UI', () => { const selectors = { accountNameInput: () => screen.getByLabelText(/account/i), repositoryInput: () => screen.getByLabelText(/bucket name/i), + maxCapacityInput: () => + screen.getByLabelText(/Max Veeam Repository Capacity/i), continueButton: () => screen.getByRole('button', { name: /Continue/i }), skipButton: () => screen.getByRole('button', { name: /Skip Use case configuration/i }), @@ -81,7 +83,7 @@ describe('Veeam Configuration UI', () => { screen.getByPlaceholderText(/example: veeam-backup/i), ).toBeInTheDocument(); //E - await userEvent.type(selectors.accountNameInput(), 'Veeam'); + await userEvent.type(selectors.accountNameInput(), 'Veeam-test'); await userEvent.type(selectors.repositoryInput(), 'veeam-bucket'); //V expect(selectors.repositoryInput()).toHaveValue('veeam-bucket'); @@ -100,7 +102,7 @@ describe('Veeam Configuration UI', () => { it('should display clusterCapacity in default value with unit', async () => { mockUseAccountsImplementation(); renderVeeamConfigurationForm(); - expect(screen.getByDisplayValue(/4.66/i)).toBeInTheDocument(); + expect(screen.getByDisplayValue(/4.7/i)).toBeInTheDocument(); expect(screen.getByText(/GiB/i)).toBeInTheDocument(); }); @@ -185,4 +187,17 @@ describe('Veeam Configuration UI', () => { expect(selectors.accountNameInput()).toHaveValue('Veeam'); }); }); + + it('should throw validation error if the max capacity has more than 1 decimal', async () => { + //S + mockUseAccountsImplementation(); + renderVeeamConfigurationForm(); + //E + await userEvent.clear(selectors.maxCapacityInput()); + await userEvent.type(selectors.maxCapacityInput(), '4.666'); + //V + expect( + screen.getByText(/"capacity" must have no more than 1 decimal places/i), + ).toBeInTheDocument(); + }); }); diff --git a/src/react/ui-elements/Veeam/VeeamSummary.tsx b/src/react/ui-elements/Veeam/VeeamSummary.tsx index a8f516d1a..b5f4e50f3 100644 --- a/src/react/ui-elements/Veeam/VeeamSummary.tsx +++ b/src/react/ui-elements/Veeam/VeeamSummary.tsx @@ -172,7 +172,7 @@ export const VeeamSummary = ({ {CREDENTIALS_SECTION_TITLE} - } variant="warning"> + } variant="warning"> The Secret Access key cannot be retrieved afterwards, so make sure to keep and secure it now.
You will be able to create new Access keys at any time. diff --git a/src/react/ui-elements/Veeam/useCapacityUnit.ts b/src/react/ui-elements/Veeam/useCapacityUnit.ts index dbf14cbf5..37c9b5557 100644 --- a/src/react/ui-elements/Veeam/useCapacityUnit.ts +++ b/src/react/ui-elements/Veeam/useCapacityUnit.ts @@ -8,6 +8,8 @@ export const useCapacityUnit = (capacity: string, pBytes = false) => { ? prettyBytes(parseInt(capacity, 10), { locale: 'en', binary: true, + maximumFractionDigits: 1, + minimumFractionDigits: 1, }) : capacity; const capacityValue = pBytesCapacity.split(' ')[0];