|
| 1 | +import { render, screen } from '@testing-library/react'; |
| 2 | +import userEvent from '@testing-library/user-event'; |
| 3 | +import { ThemeProvider } from 'styled-components'; |
| 4 | +import { LocationType } from '../../../../js/managementClient/api'; |
| 5 | +import type { LocationInfo } from '../../../next-architecture/adapters/accounts-locations/ILocationsAdapter'; |
| 6 | +import { theme } from '../../../utils/testUtil'; |
| 7 | +import { StorageClassSelector } from '../StorageClassSelector'; |
| 8 | + |
| 9 | +const mockUseLocationsAndEndpoints = jest.fn(); |
| 10 | +jest.mock('../../../next-architecture/domain/business/accounts', () => ({ |
| 11 | + useLocationsAndEndpoints: () => mockUseLocationsAndEndpoints(), |
| 12 | +})); |
| 13 | + |
| 14 | +jest.mock('../../../next-architecture/ui/LocationsEndpointsAdapterProvider', () => ({ |
| 15 | + useLocationsEndpointsAdapter: () => ({}), |
| 16 | +})); |
| 17 | + |
| 18 | +const locations: LocationInfo[] = [ |
| 19 | + { |
| 20 | + id: '1', |
| 21 | + name: 'artesca-s3-location', |
| 22 | + type: LocationType.ScalityArtescaS3V1, |
| 23 | + details: {}, |
| 24 | + }, |
| 25 | + { |
| 26 | + id: '2', |
| 27 | + name: 'crr-location', |
| 28 | + type: LocationType.ScalityCrrV1, |
| 29 | + details: {}, |
| 30 | + }, |
| 31 | + { |
| 32 | + id: '3', |
| 33 | + name: 'storage-service', |
| 34 | + type: LocationType.ScalityHdclientV2, |
| 35 | + details: {}, |
| 36 | + }, |
| 37 | +]; |
| 38 | + |
| 39 | +const renderSelector = (context: 'replication' | 'lifecycle') => |
| 40 | + render( |
| 41 | + <ThemeProvider theme={theme}> |
| 42 | + <StorageClassSelector value="" onChange={jest.fn()} context={context} /> |
| 43 | + </ThemeProvider>, |
| 44 | + ); |
| 45 | + |
| 46 | +describe('StorageClassSelector', () => { |
| 47 | + beforeEach(() => { |
| 48 | + jest.clearAllMocks(); |
| 49 | + mockUseLocationsAndEndpoints.mockReturnValue({ |
| 50 | + locationsAndEndpoints: { locations }, |
| 51 | + status: 'success', |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should not offer CRR nor storage service locations for lifecycle transitions', async () => { |
| 56 | + renderSelector('lifecycle'); |
| 57 | + |
| 58 | + await userEvent.click(screen.getByRole('textbox')); |
| 59 | + |
| 60 | + expect(screen.getByRole('option', { name: 'artesca-s3-location (ARTESCA)' })).toBeInTheDocument(); |
| 61 | + expect(screen.queryByRole('option', { name: /crr-location/ })).not.toBeInTheDocument(); |
| 62 | + expect(screen.queryByRole('option', { name: /storage-service/ })).not.toBeInTheDocument(); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should offer CRR locations as replication destinations', async () => { |
| 66 | + renderSelector('replication'); |
| 67 | + |
| 68 | + await userEvent.click(screen.getByRole('textbox')); |
| 69 | + |
| 70 | + expect(screen.getByRole('option', { name: 'crr-location (CRR)' })).toBeInTheDocument(); |
| 71 | + expect(screen.getByRole('option', { name: 'artesca-s3-location (ARTESCA)' })).toBeInTheDocument(); |
| 72 | + expect(screen.queryByRole('option', { name: /storage-service/ })).not.toBeInTheDocument(); |
| 73 | + }); |
| 74 | +}); |
0 commit comments