Skip to content

Commit

Permalink
Add test to cover the max capacity to only one decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengYanJin committed Mar 21, 2024
1 parent f9f67f0 commit 867c61e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/react/ui-elements/Veeam/VeeamConfiguration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down Expand Up @@ -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');
Expand All @@ -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();
});

Expand Down Expand Up @@ -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();
});
});
2 changes: 1 addition & 1 deletion src/react/ui-elements/Veeam/VeeamSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const VeeamSummary = ({
<Separator />

<Text isEmphazed>{CREDENTIALS_SECTION_TITLE}</Text>
<Banner icon={<Icon name="Exclamation-triangle" />} variant="warning">
<Banner icon={<Icon name="Exclamation-circle" />} variant="warning">
The Secret Access key cannot be retrieved afterwards, so make sure to
keep and secure it now. <br />
You will be able to create new Access keys at any time.
Expand Down
2 changes: 2 additions & 0 deletions src/react/ui-elements/Veeam/useCapacityUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 867c61e

Please sign in to comment.