From 9d10696b68ecd5d5e02253206f442ac73e4caf5f Mon Sep 17 00:00:00 2001 From: YanJin Date: Mon, 1 Jul 2024 15:31:35 +0200 Subject: [PATCH] ARTESCA-11299: Add test to prevent the edition of Artesca default location --- src/js/mock/managementClientMSWHandlers.ts | 17 ++-- src/react/locations/LocationsList.tsx | 2 +- .../__tests__/LocationEditor.test.tsx | 4 +- .../locations/__tests__/LocationList.test.tsx | 93 +++++++++++++++++++ .../__tests__/TransitionForm.test.tsx | 18 ++-- 5 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 src/react/locations/__tests__/LocationList.test.tsx diff --git a/src/js/mock/managementClientMSWHandlers.ts b/src/js/mock/managementClientMSWHandlers.ts index f02b6a7b7..1cefd7873 100644 --- a/src/js/mock/managementClientMSWHandlers.ts +++ b/src/js/mock/managementClientMSWHandlers.ts @@ -144,17 +144,22 @@ export const LOCATIONS = { name: 'ring-nick', objectId: '99a06f79-c62c-11ec-b993-7e8a0ab79998', }, - 'us-east-1': { - isBuiltin: true, - locationType: 'location-file-v1', - name: 'us-east-1', - objectId: '95dbedf5-9888-11ec-8565-1ac2af7d1e53', - }, [azureblobstorage]: { locationType: 'location-azure-v1', name: azureblobstorage, details: {}, }, + 'us-east-1': { + details: { + bootstrapList: [ + 'artesca-storage-service-hdservice-proxy.xcore.svc:18888', + ], + repoId: null, + }, + locationType: 'location-scality-hdclient-v2', + name: 'us-east-1', + objectId: '22f31240-4bd3-11ee-98b3-1e5b6f897bc7', + }, }; export const ENDPOINTS = [ diff --git a/src/react/locations/LocationsList.tsx b/src/react/locations/LocationsList.tsx index f758c5031..67f21b6b5 100644 --- a/src/react/locations/LocationsList.tsx +++ b/src/react/locations/LocationsList.tsx @@ -178,6 +178,7 @@ const ActionButtons = ({ variant="danger" onClick={() => setShowModal(true)} type="button" + aria-label="Delete Location" tooltip={{ overlay: , overlayStyle: { textAlign: 'left' }, @@ -220,7 +221,6 @@ export function LocationsList() { const loadingBuckets = useSelector( (state: AppState) => state.networkActivity.counter > 0, ); - const SEARCH_QUERY_PARAM = 'search'; const columns = useMemo(() => { const dataUsedColumn = getDataUsedColumn( diff --git a/src/react/locations/__tests__/LocationEditor.test.tsx b/src/react/locations/__tests__/LocationEditor.test.tsx index e5f939060..d837c587f 100644 --- a/src/react/locations/__tests__/LocationEditor.test.tsx +++ b/src/react/locations/__tests__/LocationEditor.test.tsx @@ -49,13 +49,11 @@ describe('LocationEditor', () => { ); await selectClick(selector); await userEvent.keyboard('{arrowup}'); - expect( container.querySelector('.sc-select__option--is-focused')?.textContent, - ).toBe('Storage Service for ARTESCA'); + ).toBe('Scality ARTESCA S3'); [ - 'Scality ARTESCA S3', 'Scality RING with S3 Connector', 'Amazon S3', 'Google Cloud Storage', diff --git a/src/react/locations/__tests__/LocationList.test.tsx b/src/react/locations/__tests__/LocationList.test.tsx new file mode 100644 index 000000000..2807245e7 --- /dev/null +++ b/src/react/locations/__tests__/LocationList.test.tsx @@ -0,0 +1,93 @@ +import { + screen, + waitFor, + waitForElementToBeRemoved, + within, +} from '@testing-library/react'; +import { setupServer } from 'msw/node'; +import { rest } from 'msw'; +import { + ACCOUNT_ID, + getConfigOverlay, + getStorageConsumptionMetricsHandlers, +} from '../../../js/mock/managementClientMSWHandlers'; +import { + TEST_API_BASE_URL, + mockOffsetSize, + renderWithRouterMatch, + zenkoUITestConfig, +} from '../../utils/testUtil'; +import { INSTANCE_ID } from '../../actions/__tests__/utils/testUtil'; +import { LocationsList } from '../LocationsList'; +import { debug } from 'jest-preview'; + +const server = setupServer( + getConfigOverlay(TEST_API_BASE_URL, INSTANCE_ID), + ...getStorageConsumptionMetricsHandlers( + zenkoUITestConfig.managementEndpoint, + INSTANCE_ID, + ), + rest.get( + `${TEST_API_BASE_URL}/api/v1/instance/${INSTANCE_ID}/status`, + (req, res, ctx) => res(ctx.json({})), + ), + rest.post(`${TEST_API_BASE_URL}/`, (req, res, ctx) => { + //@ts-ignore + const params = new URLSearchParams(req.body); + if (params.get('Action') === 'GetRolesForWebIdentity') { + const TEST_ACCOUNT = 'Test Account'; + const TEST_ACCOUNT_CREATION_DATE = '2022-03-18T12:51:44Z'; + return res( + ctx.json({ + IsTruncated: false, + Accounts: [ + { + Name: TEST_ACCOUNT, + CreationDate: TEST_ACCOUNT_CREATION_DATE, + Roles: [ + { + Name: 'storage-manager-role', + Arn: `arn:aws:iam::${ACCOUNT_ID}:role/scality-internal/storage-manager-role`, + }, + ], + }, + ], + }), + ); + } + }), +); + +describe('LocationList', () => { + beforeAll(() => { + jest.setTimeout(20_000); + mockOffsetSize(500, 100); + server.listen({ onUnhandledRequest: 'error' }); + }); + afterEach(() => { + server.resetHandlers(); + }); + afterAll(() => { + server.close(); + }); + it('should disable the delete button for default location', async () => { + //S + renderWithRouterMatch(); + //E + await waitForElementToBeRemoved(() => [ + ...screen.queryAllByText(/Loading/i), + ]); + const hdLocationRow = screen.getByRole('row', { + name: /us-east-1 Storage Service for ARTESCA/i, + }); + //V + await waitFor(() => { + expect( + within(hdLocationRow).getByRole('button', { + name: /Edit Location/i, + }), + ).toBeDisabled(); + }); + debug(); + }); +}); diff --git a/src/react/workflow/__tests__/TransitionForm.test.tsx b/src/react/workflow/__tests__/TransitionForm.test.tsx index 15bd25d5d..9d2989451 100644 --- a/src/react/workflow/__tests__/TransitionForm.test.tsx +++ b/src/react/workflow/__tests__/TransitionForm.test.tsx @@ -200,7 +200,7 @@ describe('TransitionForm', () => { await waitFor(() => screen.getByRole('option', { name: new RegExp( - `${notVersionedBucket} \\(us-east-1 / Local Filesystem \\)`, + `${notVersionedBucket} \\(us-east-1 / Storage Service \\)`, 'i', ), }), @@ -208,7 +208,7 @@ describe('TransitionForm', () => { await userEvent.click( screen.getByRole('option', { name: new RegExp( - `${notVersionedBucket} \\(us-east-1 / Local Filesystem \\)`, + `${notVersionedBucket} \\(us-east-1 / Storage Service \\)`, 'i', ), }), @@ -233,7 +233,7 @@ describe('TransitionForm', () => { await waitFor(() => screen.getByRole('option', { name: new RegExp( - `${versionedBucket} \\(us-east-1 / Local Filesystem \\)`, + `${versionedBucket} \\(us-east-1 / Storage Service \\)`, 'i', ), }), @@ -241,7 +241,7 @@ describe('TransitionForm', () => { await userEvent.click( screen.getByRole('option', { name: new RegExp( - `${versionedBucket} \\(us-east-1 / Local Filesystem \\)`, + `${versionedBucket} \\(us-east-1 / Storage Service \\)`, 'i', ), }), @@ -336,7 +336,7 @@ describe('TransitionForm', () => { await waitFor(() => screen.getByRole('option', { name: new RegExp( - `${notVersionedBucket} \\(us-east-1 / Local Filesystem \\)`, + `${notVersionedBucket} \\(us-east-1 / Storage Service \\)`, 'i', ), }), @@ -344,7 +344,7 @@ describe('TransitionForm', () => { await userEvent.click( screen.getByRole('option', { name: new RegExp( - `${notVersionedBucket} \\(us-east-1 / Local Filesystem \\)`, + `${notVersionedBucket} \\(us-east-1 / Storage Service \\)`, 'i', ), }), @@ -384,7 +384,7 @@ describe('TransitionForm', () => { await waitFor(() => screen.getByRole('option', { name: new RegExp( - `${notVersionedBucket} \\(us-east-1 / Local Filesystem \\)`, + `${notVersionedBucket} \\(us-east-1 / Storage Service \\)`, 'i', ), }), @@ -392,7 +392,7 @@ describe('TransitionForm', () => { await userEvent.click( screen.getByRole('option', { name: new RegExp( - `${notVersionedBucket} \\(us-east-1 / Local Filesystem \\)`, + `${notVersionedBucket} \\(us-east-1 / Storage Service \\)`, 'i', ), }), @@ -435,7 +435,7 @@ describe('TransitionForm', () => { userEvent.click( screen.getByRole('option', { name: new RegExp( - `${versionedBucket} \\(us-east-1 / Local Filesystem \\)`, + `${versionedBucket} \\(us-east-1 / Storage Service \\)`, 'i', ), }),