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

test: [M3-8485] - Unit Tests for Object Storage Gen2 feature #10862

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { act, waitFor } from '@testing-library/react';
import * as React from 'react';

import { profileFactory } from 'src/factories';
import { http, HttpResponse, server } from 'src/mocks/testServer';
import { HttpResponse, http, server } from 'src/mocks/testServer';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { ObjectDetailsDrawer } from './ObjectDetailsDrawer';
Expand Down Expand Up @@ -64,4 +64,15 @@ describe('ObjectDetailsDrawer', () => {
expect(queryByTestId('lastModified')).not.toBeInTheDocument();
});
});

it("doesn't show the ACL Switch for E2 and E3 buckets", async () => {
const { queryByLabelText } = renderWithTheme(
<ObjectDetailsDrawer {...props} endpointType="E3" />
);
await waitFor(() => {
expect(
queryByLabelText('Access Control List (ACL)')
).not.toBeInTheDocument();
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using renderWithThemeAndHookFormContext is unnecessary since the component doesn't need a Hook Form Context. Use renderWithTheme instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the component doesn't need a Hook Form, but M3-8501(optimzing AccessSelect.tsx using Hook Form) is in progress. Hence, I decided to go with renderWithThemeAndHookFormContext

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh understood. Sounds good!

Copy link
Contributor

@hkhalil-akamai hkhalil-akamai Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, each PR should be self-contained and generally should not include changes for another ticket. This prevents issues when, for example, the other ticket is closed or modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted πŸ—’οΈ

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { vi } from 'vitest';

import {
objectStorageBucketFactory,
objectStorageBucketFactoryGen2,
profileFactory,
regionFactory,
} from 'src/factories';
Expand Down Expand Up @@ -200,3 +201,100 @@ describe('BucketDetailsDrawer: Legacy UI', () => {
});
});
});

describe('BucketDetailDrawer: Gen2 UI', () => {
const e3Bucket = objectStorageBucketFactoryGen2.build();
const e1Bucket = objectStorageBucketFactoryGen2.build({
endpoint_type: 'E1',
});

const region = regionFactory.build({
id: e3Bucket.region,
});

it('renders correctly when open', () => {
renderWithThemeAndHookFormContext({
component: (
<BucketDetailsDrawer
onClose={mockOnClose}
open={true}
selectedBucket={e3Bucket}
/>
),
options: {
flags: { objMultiCluster: false, objectStorageGen2: { enabled: true } },
},
});

expect(screen.getByText(e3Bucket.label)).toBeInTheDocument();
expect(screen.getByTestId('createdTime')).toHaveTextContent(
'Created: 2019-12-12'
);
expect(screen.getByTestId('endpointType')).toHaveTextContent(
`Endpoint Type: E3`
);
expect(screen.getByTestId('cluster')).toHaveTextContent(region.id);
expect(screen.getByText(e3Bucket.hostname)).toBeInTheDocument();
expect(screen.getByText('1 MB')).toBeInTheDocument();
expect(screen.getByText('103 objects')).toBeInTheDocument();
});

it("doesn't show the CORS switch for E2 and E3 buckets", async () => {
const { getByText } = renderWithThemeAndHookFormContext({
component: (
<BucketDetailsDrawer
onClose={mockOnClose}
open={true}
selectedBucket={e3Bucket}
/>
),
options: {
flags: { objMultiCluster: false, objectStorageGen2: { enabled: true } },
},
});

expect(
getByText(
/CORS \(Cross Origin Sharing\) is not available for endpoint types E2 and E3./
)
).toBeInTheDocument();
});

it('renders the Bucket Rate Limit Table for E2 and E3 buckets', async () => {
const { findByTestId } = renderWithThemeAndHookFormContext({
component: (
<BucketDetailsDrawer
onClose={mockOnClose}
open={true}
selectedBucket={e3Bucket}
/>
),
options: {
flags: { objMultiCluster: false, objectStorageGen2: { enabled: true } },
},
});

const rateLimitTable = await findByTestId('bucket-rate-limit-table');
expect(rateLimitTable).toBeVisible();
});

it('renders the Bucket Rate Limit Text for E0 and E1 buckets', async () => {
const { findByText } = renderWithThemeAndHookFormContext({
component: (
<BucketDetailsDrawer
onClose={mockOnClose}
open={true}
selectedBucket={e1Bucket}
/>
),
options: {
flags: { objMultiCluster: false, objectStorageGen2: { enabled: true } },
},
});
expect(
await findByText(
/This endpoint type supports up to 750 Requests Per Second \(RPS\)./
)
).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export const BucketDetailsDrawer = React.memo(
payload
);
}}
endpointType={endpoint_type}
name={label}
variant="bucket"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as React from 'react';

import { objectStorageBucketFactory } from 'src/factories';
import { renderWithTheme, mockMatchMedia } from 'src/utilities/testHelpers';
import {
objectStorageBucketFactory,
objectStorageBucketFactoryGen2,
} from 'src/factories';
import { mockMatchMedia, renderWithTheme } from 'src/utilities/testHelpers';

import { BucketTable } from './BucketTable';

Expand Down Expand Up @@ -43,4 +46,20 @@ describe('BucketTable', () => {
expect(getByText(bucket.label)).toBeVisible();
}
});

it('renders "Endpoint Type" column when Gen 2 is enabled', () => {
const bucket = objectStorageBucketFactoryGen2.buildList(1);
const { getByText } = renderWithTheme(
<BucketTable
data={bucket}
handleClickDetails={vi.fn()}
handleClickRemove={vi.fn()}
handleOrderChange={vi.fn()}
order="asc"
orderBy="label"
/>
);
expect(getByText('Endpoint Type')).toBeVisible();
harsh-akamai marked this conversation as resolved.
Show resolved Hide resolved
expect(getByText('Standard (E3)')).toBeVisible();
});
});
2 changes: 1 addition & 1 deletion packages/manager/src/mocks/serverHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ export const handlers = [
];
return HttpResponse.json(makeResourcePage(objectStorageTypes));
}),
http.get('*/v4/object-storage/endpoints', ({ }) => {
http.get('*/v4/object-storage/endpoints', ({}) => {
const endpoints = [
objectStorageEndpointsFactory.build({
endpoint_type: 'E0',
Expand Down
Loading