Brijesh619 commented on code in PR #697: URL: https://github.com/apache/atlas/pull/697#discussion_r3774948993
########## dashboard/src/views/DetailPage/EntityDetailTabs/PropertiesTab/__tests__/UserDefinedProperties.test.tsx: ########## @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { render, screen, fireEvent, waitFor, act } from '@utils/test-utils'; +import userEvent from '@testing-library/user-event'; +import '@testing-library/jest-dom'; +import UserDefinedProperties from '../UserDefinedProperties'; +import { ThemeProvider, createTheme } from '@mui/material/styles'; + +const theme = createTheme(); + +// Mock dependencies +const mockDispatch = jest.fn(); +jest.mock('@hooks/reducerHook', () => ({ + useAppDispatch: () => mockDispatch +})); + +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useParams: () => ({ guid: 'test-guid-123' }) +})); + +const mockCreateEntity = jest.fn(); +jest.mock('@api/apiMethods/entityFormApiMethod', () => ({ + createEntity: (...args: any[]) => mockCreateEntity(...args) +})); + +jest.mock('@utils/entityPayloadEnrichmentUtils', () => ({ + enrichEntityPayloadForRelationshipSave: jest.fn(async (entity) => entity) +})); + +jest.mock('react-toastify', () => ({ + toast: { + dismiss: jest.fn(), + success: jest.fn(() => 'toast-id'), + error: jest.fn(() => 'toast-id') + } +})); + +jest.mock('@utils/Utils', () => ({ + ...jest.requireActual('@utils/Utils'), + serverError: jest.fn() +})); + +jest.mock('@redux/slice/detailPageSlice', () => ({ + fetchDetailPageData: jest.fn((guid: string) => ({ type: 'fetchDetailPageData', payload: guid })) +})); + +const TestWrapper: React.FC<React.PropsWithChildren<{}>> = ({ children }) => ( + <ThemeProvider theme={theme}>{children}</ThemeProvider> +); + +describe('UserDefinedProperties Component', () => { + const defaultProps = { + loading: false, + customAttributes: { key1: 'value1', key2: 'value2' }, + entity: { guid: 'test-guid-123', status: 'ACTIVE', customAttributes: {} } + }; + + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('renders existing properties correctly', () => { + render(<TestWrapper><UserDefinedProperties {...defaultProps} /></TestWrapper>); + + expect(screen.getByText('User-defined properties')).toBeInTheDocument(); + expect(screen.getByText('key1')).toBeInTheDocument(); + expect(screen.getByText('value1')).toBeInTheDocument(); + expect(screen.getByText('key2')).toBeInTheDocument(); + expect(screen.getByText('value2')).toBeInTheDocument(); + }); + + it('shows empty state message when empty', () => { + render(<TestWrapper><UserDefinedProperties loading={false} customAttributes={{}} entity={{ status: 'ACTIVE' }} /></TestWrapper>); + + expect(screen.getByText(/No properties have been created yet/i)).toBeInTheDocument(); + }); + Review Comment: Added negative test in UserDefinedProperties.test.tsx to verify that the 'Edit' button is correctly hidden for DELETED entities even when they contain existing user-defined properties. ########## dashboard/src/utils/EntityStatus.ts: ########## @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export enum EntityStatus { + ACTIVE = "ACTIVE", + DELETED = "DELETED" Review Comment: Confirmed that PURGED entities should also block modifications. I've added PURGED to the EntityStatus enum and introduced an isEntityModificationAllowed(status) helper to centrally manage these guards. ########## dashboard/src/components/EntityDisplayImage.tsx: ########## Review Comment: Renamed the unused error variable in the catch block to _error as per ESLint conventions. ########## dashboard/src/views/DetailPage/EntityDetailTabs/PropertiesTab/__tests__/BMAttributes.test.tsx: ########## @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { render, screen, fireEvent, waitFor, act } from '@utils/test-utils'; +import userEvent from '@testing-library/user-event'; Review Comment: Removed unused userEvent imports from BMAttributes.test.tsx, Labels.test.tsx, and UserDefinedProperties.test.tsx -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
