Brijesh619 commented on code in PR #697:
URL: https://github.com/apache/atlas/pull/697#discussion_r3774947458
##########
dashboard/src/views/DetailPage/EntityDetailTabs/PropertiesTab/BMAttributes.tsx:
##########
@@ -536,41 +545,48 @@ const BMAttributes = ({ loading, bmAttributes, entity }:
any) => {
justifyContent="center"
>
<span>
- No properties have been created yet. To add a
- property, click{" "}
- <Typography
- className="text-color-green cursor-pointer"
- component="span"
- onClick={(e: { stopPropagation: () => void }) => {
- e.stopPropagation();
- setAddLabel(false);
- }}
- style={{ textDecoration: "underline" }}
- >
- here
- </Typography>
+ {entity?.status === EntityStatus.DELETED ? (
+ "No properties have been created yet."
+ ) : (
+ <>
+ No properties have been created yet. To add a
+ property, click{" "}
+ <Typography
+ className="text-color-green cursor-pointer
text-underline"
+ component="span"
Review Comment:
Fixed the indentation alignment for component='span' and its onClick handler
as requested
##########
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';
+import '@testing-library/jest-dom';
+import BMAttributes from '../BMAttributes';
+import { ThemeProvider, createTheme } from '@mui/material/styles';
+
+const theme = createTheme();
+
+// Mock dependencies
+const mockDispatch = jest.fn();
+jest.mock('@hooks/reducerHook', () => ({
+ useAppDispatch: () => mockDispatch,
+ useAppSelector: jest.fn((selector) => {
+ const state = {
+ entity: {
+ entityData: {
+ entityDefs: [
+ {
+ name: 'DataSet',
+ businessAttributeDefs: {
+ 'Group1': [
+ { name: 'attr1', typeName: 'string' },
+ { name: 'attr2', typeName: 'int' }
+ ]
+ }
+ }
+ ]
+ }
+ },
+ businessMetaData: {
+ businessMetaData: {
+ businessMetadataDefs: [
+ {
+ name: 'Group1',
+ attributeDefs: [
+ { name: 'attr1', typeName: 'string' },
+ { name: 'attr2', typeName: 'int' }
+ ]
+ }
+ ]
+ }
+ }
+ };
+ return selector(state);
+ })
+}));
+
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ useParams: () => ({ guid: 'test-guid-123' })
+}));
+
+const mockGetEntityBusinessMetadata = jest.fn();
+jest.mock('@api/apiMethods/detailpageApiMethod', () => ({
+ getEntityBusinessMetadata: (...args: any[]) =>
mockGetEntityBusinessMetadata(...args)
+}));
+
+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 }))
+}));
+
+// Mock BMAttributesFields to avoid complex form input mocks unless needed
+jest.mock('../BMAttributesFields', () => {
+ return function MockBMAttributesFields(props: any) {
+ return <div data-testid="bm-fields-mock">{props.obj?.name}</div>;
+ };
+});
+
+const TestWrapper: React.FC<React.PropsWithChildren<{}>> = ({ children }) => (
+ <ThemeProvider theme={theme}>{children}</ThemeProvider>
+);
+
+describe('BMAttributes Component', () => {
+ const defaultProps = {
+ loading: false,
+ bmAttributes: {
+ 'Group1': {
+ 'attr1': 'value1',
+ 'attr2': 100
+ }
+ },
+ entity: { guid: 'test-guid-123', status: 'ACTIVE', typeName: 'DataSet' }
+ };
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it('renders existing business metadata correctly', () => {
+ render(<TestWrapper><BMAttributes {...defaultProps} /></TestWrapper>);
+
+ expect(screen.getByText('Business Metadata')).toBeInTheDocument();
+ expect(screen.getByText('Group1')).toBeInTheDocument();
+ expect(screen.getByText('attr1 (string)')).toBeInTheDocument();
+ expect(screen.getByText('attr2 (int)')).toBeInTheDocument();
+ // BMAttributes renders HTML for string values
+ expect(screen.getByText('value1')).toBeInTheDocument();
Review Comment:
Added negative test in BMAttributes.test.tsx to verify that the 'Edit'
button is correctly hidden for DELETED entities even when they contain existing
business metadata.
##########
dashboard/src/views/DetailPage/EntityDetailTabs/PropertiesTab/__tests__/Labels.test.tsx:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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 Labels from '../Labels';
+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 mockGetLabels = jest.fn();
+const mockGetGlobalSearchResult = jest.fn();
+jest.mock('@api/apiMethods/detailpageApiMethod', () => ({
+ getLabels: (...args: any[]) => mockGetLabels(...args)
+}));
+jest.mock('@api/apiMethods/searchApiMethod', () => ({
+ getGlobalSearchResult: (...args: any[]) => mockGetGlobalSearchResult(...args)
+}));
+
+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('Labels Component', () => {
+ const defaultProps = {
+ loading: false,
+ labels: ['Label1', 'Label2'],
+ entity: { status: 'ACTIVE' }
+ };
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it('renders existing labels correctly', () => {
+ render(<TestWrapper><Labels {...defaultProps} /></TestWrapper>);
+
+ // Labels are shown in an accordion that is expanded by default since
labels exist
+ expect(screen.getByText('Labels')).toBeInTheDocument();
+ expect(screen.getByText('Label1')).toBeInTheDocument();
+ expect(screen.getByText('Label2')).toBeInTheDocument();
+ });
+
+ it('shows no labels message when empty', () => {
+ render(<TestWrapper><Labels loading={false} labels={[]} entity={{ status:
'ACTIVE' }} /></TestWrapper>);
+
+ expect(screen.getByText(/No labels have been created
yet/i)).toBeInTheDocument();
+ });
+
Review Comment:
Added negative test in Labels.test.tsx to verify that the 'Edit' button is
correctly hidden for DELETED entities even when they contain existing labels.
--
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]