Skip to content

Commit

Permalink
ARTESCA-12108: Disable the version toogle for Veeam bucket and adding…
Browse files Browse the repository at this point in the history
… a tooltip of explaination
  • Loading branch information
ChengYanJin committed May 14, 2024
1 parent 8c89610 commit 37a7f28
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/js/mock/S3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const bucketInfoResponseVersioningDisabled: BucketInfo = {
ObjectLockEnabled: 'Disabled',
},
};

export class MockS3Client implements S3ClientInterface {
listBucketsWithLocation() {
return Promise.resolve({
Expand Down
23 changes: 20 additions & 3 deletions src/js/mock/S3ClientMSWHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,21 @@ export function mockBucketOperations(
slowdown = false,
forceFailure = false,
isVeeamTagged = false,
isObjectLockEnabled = true,
}: {
location?: string | ((bucketName: string) => string);
isVersioningEnabled?: boolean | ((bucketName: string) => boolean);
slowdown?: boolean;
forceFailure?: boolean;
isVeeamTagged?: boolean | ((bucketName: string) => boolean);
isObjectLockEnabled?: boolean;
} = {
location: '',
isVersioningEnabled: false,
slowdown: false,
forceFailure: false,
isVeeamTagged: false,
isObjectLockEnabled: true,
},
) {
return rest.get(
Expand Down Expand Up @@ -152,14 +155,28 @@ export function mockBucketOperations(
}

if (req.url.searchParams.has('object-lock')) {
return res(
ctx.xml(`
if (isObjectLockEnabled) {
return res(
ctx.xml(`
<?xml version="1.0" encoding="UTF-8"?>
<ObjectLockConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<ObjectLockEnabled>Enabled</ObjectLockEnabled>
</ObjectLockConfiguration>
`),
);
);
} else {
return res(
ctx.status(404),
ctx.xml(
`<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>ObjectLockConfigurationNotFoundError</Code>
<Resource></Resource>
<RequestId>771ff09e6b408a3e5ed8</RequestId>
</Error>`,
),
);
}
}

if (req.url.searchParams.has('tagging')) {
Expand Down
30 changes: 23 additions & 7 deletions src/react/databrowser/buckets/details/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ const workflowAttachedError = (count: number, bucketName: string) => (
</div>
);

function VersionningValue({ bucketInfo }: { bucketInfo: BucketInfo }) {
function VersionningValue({
bucketInfo,
isVeeamBucket,
}: {
bucketInfo: BucketInfo;
isVeeamBucket: boolean;
}) {
const dispatch = useDispatch();
const accountsLocationsEndpointsAdapter =
useAccountsLocationsEndpointsAdapter();
Expand All @@ -114,6 +120,11 @@ function VersionningValue({ bucketInfo }: { bucketInfo: BucketInfo }) {
},
});
};
const isVersioningToggleDisabled =
locationsStatus === 'idle' ||
locationsStatus === 'loading' ||
isBucketHostedOnAzureOrGCP ||
isVeeamBucket;

return (
<T.Value>
Expand All @@ -130,15 +141,17 @@ function VersionningValue({ bucketInfo }: { bucketInfo: BucketInfo }) {
Enabling versioning is not possible due to the bucket being
hosted on Google Cloud.
</>
) : isVeeamBucket ? (
<>
Enabling versioning is not possible due to the bucket being
managed by Veeam.
</>
) : null
}
>
<Toggle
disabled={
locationsStatus === 'idle' ||
locationsStatus === 'loading' ||
isBucketHostedOnAzureOrGCP
}
id="versioningToggle"
disabled={isVersioningToggleDisabled}
toggle={bucketInfo.isVersioning}
label={
bucketInfo.versioning === 'Enabled'
Expand Down Expand Up @@ -285,7 +298,10 @@ function Overview({ bucket, ingestionStates }: Props) {
</T.Row>
<T.Row>
<T.Key> Versioning </T.Key>
<VersionningValue bucketInfo={bucketInfo} />
<VersionningValue
bucketInfo={bucketInfo}
isVeeamBucket={isVeeamBucket}
/>
</T.Row>
<T.Row>
<T.Key> Location </T.Key>
Expand Down
71 changes: 42 additions & 29 deletions src/react/databrowser/buckets/details/__tests__/Overview.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
fireEvent,
render,
screen,
waitFor,
Expand Down Expand Up @@ -195,17 +194,8 @@ describe('Overview', () => {
);
await waitForElementToBeRemoved(() => screen.getByText(/loading/i));
await waitFor(() => {
expect(
screen.getByRole('checkbox', {
name: /inactive/i,
}),
).toBeInTheDocument();
});
const versioningToggleItem = screen.getByRole('checkbox', {
name: /inactive/i,
expect(selectors.inActiveVersioningToggle()).toHaveAttribute('disabled');
});
//V
expect(versioningToggleItem).toHaveAttribute('disabled');
});
});

Expand Down Expand Up @@ -302,6 +292,8 @@ const selectors = {
screen.getByRole('generic', {
name: /indicate if object lock is enabled/i,
}),
inActiveVersioningToggle: () =>
screen.getByRole('checkbox', { name: /inactive/i }),
};

describe('Overview', () => {
Expand All @@ -312,32 +304,23 @@ describe('Overview', () => {
useUpdateBucketVersioningMock(req.body);
return res(ctx.status(200));
}),
mockBucketOperations({
isVersioningEnabled: false,
isObjectLockEnabled: false,
}),
);

renderWithRouterMatch(
render(
<Overview
//@ts-expect-error fix this when you are working on it
bucket={BUCKET}
bucket={{ name: bucketName }}
/>,
undefined,
{
...TEST_STATE,
...{ s3: { bucketInfo: bucketInfoResponseVersioningDisabled } },
},
{ wrapper: NewWrapper() },
);

const versioningToggleItem = screen
.getByRole('checkbox', {
name: /inactive/i,
})
.querySelector('input');

await waitFor(() => {
expect(versioningToggleItem).toBeInTheDocument();
expect(selectors.inActiveVersioningToggle()).toBeEnabled();
});

versioningToggleItem && fireEvent.click(versioningToggleItem);

await userEvent.click(selectors.inActiveVersioningToggle());
await waitFor(() => {
expect(useUpdateBucketVersioningMock).toHaveBeenCalledWith(mockResponse);
});
Expand Down Expand Up @@ -411,4 +394,34 @@ describe('Overview', () => {
expect(selectors.bucketTaggingErorToastQuery()).toBe(null);
});
});

it('should disable the versioning toggle for Veeam bucket', async () => {
//S
server.use(
mockBucketOperations({
isVersioningEnabled: false,
isVeeamTagged: true,
isObjectLockEnabled: false,
}),
);
//E
render(
<Overview
//@ts-expect-error fix this when you are working on it
bucket={{ name: bucketName }}
/>,
{ wrapper: NewWrapper() },
);
//V
await waitFor(() => {
expect(selectors.inActiveVersioningToggle()).toBeInTheDocument();
});

// toBeDisabled() works only with the following element, but not with label.
// https://html.spec.whatwg.org/multipage/semantics-other.html#disabled-elements
// https://github.com/testing-library/jest-dom/blob/e8c8b13c6de2a0ccffaa6539809c8c11f141beca/src/to-be-disabled.js#L71
await waitFor(() => {
expect(selectors.inActiveVersioningToggle()).toHaveAttribute('disabled');
});
});
});

0 comments on commit 37a7f28

Please sign in to comment.