-
Notifications
You must be signed in to change notification settings - Fork 383
upcoming: [M3-9691] - Quotas for Object Storage #12071
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
Changes from all commits
31e49d5
d3e21b4
5cb5d75
10ed747
c42b4bf
48b61e7
1e2f7c3
0b05205
19d7953
6e55b86
683f78e
f25a442
5a97b6d
c13794c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import { regionFactory } from '@linode/utilities'; | ||
import { QueryClient } from '@tanstack/react-query'; | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
@@ -12,12 +11,9 @@ | |
getQuotasFilters: vi.fn().mockReturnValue({}), | ||
useFlags: vi.fn().mockReturnValue({}), | ||
useGetLocationsForQuotaService: vi.fn().mockReturnValue({}), | ||
useGetRegionsQuery: vi.fn().mockReturnValue({}), | ||
})); | ||
|
||
vi.mock('@linode/queries', async (importOriginal) => ({ | ||
...(await importOriginal()), | ||
useRegionsQuery: queryMocks.useGetRegionsQuery, | ||
useObjectStorageEndpoints: vi.fn().mockReturnValue({}), | ||
convertResourceMetric: vi.fn().mockReturnValue({}), | ||
pluralizeMetric: vi.fn().mockReturnValue({}), | ||
})); | ||
|
||
vi.mock('src/hooks/useFlags', () => { | ||
|
@@ -28,28 +24,22 @@ | |
}; | ||
}); | ||
|
||
vi.mock('@linode/queries', async () => { | ||
const actual = await vi.importActual('@linode/queries'); | ||
return { | ||
...actual, | ||
useObjectStorageEndpoints: queryMocks.useObjectStorageEndpoints, | ||
}; | ||
}); | ||
|
||
vi.mock('./utils', () => ({ | ||
getQuotasFilters: queryMocks.getQuotasFilters, | ||
useGetLocationsForQuotaService: queryMocks.useGetLocationsForQuotaService, | ||
convertResourceMetric: queryMocks.convertResourceMetric, | ||
pluralizeMetric: queryMocks.pluralizeMetric, | ||
})); | ||
|
||
describe('Quotas', () => { | ||
beforeEach(() => { | ||
queryMocks.useGetLocationsForQuotaService.mockReturnValue({ | ||
isFetchingRegions: false, | ||
regions: [ | ||
regionFactory.build({ id: 'global', label: 'Global (Account level)' }), | ||
], | ||
}); | ||
queryMocks.useGetRegionsQuery.mockReturnValue({ | ||
data: [ | ||
regionFactory.build({ id: 'global', label: 'Global (Account level)' }), | ||
regionFactory.build({ id: 'us-east', label: 'Newark, NJ' }), | ||
], | ||
isFetching: false, | ||
}); | ||
}); | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
|
@@ -64,89 +54,64 @@ | |
}); | ||
|
||
expect(getByText('Quotas')).toBeInTheDocument(); | ||
expect(getByText('Learn More About Quotas')).toBeInTheDocument(); | ||
expect(getByText('Select a Service')).toBeInTheDocument(); | ||
expect(getByText('Learn more about quotas')).toBeInTheDocument(); | ||
Check warning on line 57 in packages/manager/src/features/Account/Quotas/Quotas.test.tsx
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those test linting rules will get straightened out soon |
||
expect(getByText('Object Storage Endpoint')).toBeInTheDocument(); | ||
Check warning on line 58 in packages/manager/src/features/Account/Quotas/Quotas.test.tsx
|
||
expect( | ||
screen.getByPlaceholderText('Select an Object Storage S3 endpoint') | ||
Check warning on line 60 in packages/manager/src/features/Account/Quotas/Quotas.test.tsx
|
||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByPlaceholderText('Select a region for Linodes') | ||
getByText('Apply filters above to see quotas and current usage.') | ||
Check warning on line 63 in packages/manager/src/features/Account/Quotas/Quotas.test.tsx
|
||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('allows service selection', async () => { | ||
it('allows endpoint selection', async () => { | ||
queryMocks.useGetLocationsForQuotaService.mockReturnValue({ | ||
isFetchingS3Endpoints: false, | ||
regions: null, | ||
s3Endpoints: [{ label: 'endpoint1 (Standard E0)', value: 'endpoint1' }], | ||
Check warning on line 71 in packages/manager/src/features/Account/Quotas/Quotas.test.tsx
|
||
service: 'object-storage', | ||
}); | ||
|
||
const { getByPlaceholderText, getByRole } = renderWithTheme(<Quotas />, { | ||
queryClient, | ||
}); | ||
|
||
const serviceSelect = getByPlaceholderText('Select a service'); | ||
|
||
await waitFor(() => { | ||
expect(serviceSelect).toHaveValue('Linodes'); | ||
expect( | ||
getByPlaceholderText('Select a region for Linodes') | ||
).toBeInTheDocument(); | ||
}); | ||
const endpointSelect = getByPlaceholderText( | ||
Check warning on line 79 in packages/manager/src/features/Account/Quotas/Quotas.test.tsx
|
||
'Select an Object Storage S3 endpoint' | ||
); | ||
|
||
userEvent.click(serviceSelect); | ||
await waitFor(() => { | ||
const kubernetesOption = getByRole('option', { name: 'Kubernetes' }); | ||
userEvent.click(kubernetesOption); | ||
expect(endpointSelect).not.toHaveValue(null); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(serviceSelect).toHaveValue('Kubernetes'); | ||
expect( | ||
getByPlaceholderText('Select a region for Kubernetes') | ||
).toBeInTheDocument(); | ||
expect(endpointSelect).toBeInTheDocument(); | ||
}); | ||
|
||
userEvent.click(serviceSelect); | ||
await waitFor(() => { | ||
const objectStorageOption = getByRole('option', { | ||
name: 'Object Storage', | ||
await userEvent.click(endpointSelect); | ||
await waitFor(async () => { | ||
const endpointOption = getByRole('option', { | ||
Check warning on line 93 in packages/manager/src/features/Account/Quotas/Quotas.test.tsx
|
||
name: 'endpoint1 (Standard E0)', | ||
}); | ||
userEvent.click(objectStorageOption); | ||
await userEvent.click(endpointOption); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(serviceSelect).toHaveValue('Object Storage'); | ||
expect( | ||
getByPlaceholderText('Select an Object Storage S3 endpoint') | ||
).toBeInTheDocument(); | ||
expect(endpointSelect).toHaveValue('endpoint1 (Standard E0)'); | ||
}); | ||
}); | ||
|
||
it('shows loading state when fetching data', () => { | ||
queryMocks.useGetLocationsForQuotaService.mockReturnValue({ | ||
isFetchingRegions: true, | ||
regions: [], | ||
isFetchingS3Endpoints: true, | ||
s3Endpoints: null, | ||
service: 'object-storage', | ||
}); | ||
|
||
const { getByPlaceholderText } = renderWithTheme(<Quotas />, { | ||
queryClient, | ||
}); | ||
|
||
expect( | ||
getByPlaceholderText('Loading Linodes regions...') | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows a global option for regions', async () => { | ||
const { getByPlaceholderText, getByRole } = renderWithTheme(<Quotas />, { | ||
queryClient, | ||
}); | ||
|
||
const regionSelect = getByPlaceholderText('Select a region for Linodes'); | ||
expect(regionSelect).toHaveValue(''); | ||
|
||
userEvent.click(regionSelect); | ||
await waitFor(() => { | ||
const globalOption = getByRole('option', { | ||
name: 'Global (Account level) (global)', | ||
}); | ||
userEvent.click(globalOption); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(regionSelect).toHaveValue('Global (Account level) (global)'); | ||
}); | ||
expect(getByPlaceholderText('Loading S3 endpoints...')).toBeInTheDocument(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main change here - APIv4 gave us a different key than the expected one from the specs. This will be reflected through this PR