-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: edit display name * refactor: logic and style changes * fix: minor changes * style: update style for edit button * style: remove inline styles and update hover effect * refactor: remove edit permission for version page and fix handleEditDisplayName function * refactor: updated displayName * fix: data-testid for the Link --------- Co-authored-by: Shailesh Parmar <shailesh.parmar.webdev@gmail.com>
- Loading branch information
1 parent
cb33f27
commit 9d37ff0
Showing
10 changed files
with
550 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ | |
|
||
export interface DatabaseSchemaTableProps { | ||
isDatabaseDeleted?: boolean; | ||
isVersionPage?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...adata-ui/src/main/resources/ui/src/components/common/DisplayName/DisplayName.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2024 Collate. | ||
* Licensed 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 { EntityName } from '../../Modals/EntityNameModal/EntityNameModal.interface'; | ||
|
||
export interface DisplayNameProps { | ||
id: string; | ||
name?: string; | ||
displayName?: string; | ||
link: string; | ||
onEditDisplayName?: (data: EntityName, id?: string) => Promise<void>; | ||
allowRename?: boolean; | ||
} |
102 changes: 102 additions & 0 deletions
102
openmetadata-ui/src/main/resources/ui/src/components/common/DisplayName/DisplayName.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2024 Collate. | ||
* Licensed 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 { act, fireEvent, render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import DisplayName from './DisplayName'; | ||
import { DisplayNameProps } from './DisplayName.interface'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
Link: jest | ||
.fn() | ||
.mockImplementation(({ children, ...props }) => ( | ||
<span {...props}>{children}</span> | ||
)), | ||
})); | ||
|
||
jest.mock('../../../constants/constants', () => ({ | ||
DE_ACTIVE_COLOR: '#BFBFBF', | ||
ICON_DIMENSION: { width: 16, height: 16 }, | ||
})); | ||
|
||
jest.mock('../../Modals/EntityNameModal/EntityNameModal.component', () => | ||
jest.fn().mockImplementation(() => <p>Mocked Modal</p>) | ||
); | ||
|
||
const mockOnEditDisplayName = jest.fn(); | ||
|
||
const mockProps: DisplayNameProps = { | ||
id: '1', | ||
name: 'Sample Entity', | ||
displayName: 'Sample Display Name', | ||
link: '/entity/1', | ||
allowRename: true, | ||
onEditDisplayName: mockOnEditDisplayName, | ||
}; | ||
|
||
describe('Test DisplayName Component', () => { | ||
it('Should render the component with the display name', async () => { | ||
await act(async () => { | ||
render( | ||
<MemoryRouter> | ||
<DisplayName {...mockProps} /> | ||
</MemoryRouter> | ||
); | ||
|
||
const displayNameField = await screen.getByTestId('column-display-name'); | ||
|
||
expect(displayNameField).toBeInTheDocument(); | ||
expect(displayNameField).toHaveTextContent('Sample Display Name'); | ||
|
||
const editButton = screen.queryByTestId('edit-displayName-button'); | ||
|
||
expect(editButton).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('Should render the component with name when display name is empty', async () => { | ||
await act(async () => { | ||
render( | ||
<MemoryRouter> | ||
<DisplayName {...mockProps} displayName={undefined} /> | ||
</MemoryRouter> | ||
); | ||
|
||
const nameField = screen.getByTestId('column-name'); | ||
|
||
expect(nameField).toBeInTheDocument(); | ||
expect(nameField).toHaveTextContent('Sample Entity'); | ||
}); | ||
}); | ||
|
||
it('Should open the edit modal on edit button click', async () => { | ||
await act(async () => { | ||
render( | ||
<MemoryRouter> | ||
<DisplayName {...mockProps} /> | ||
</MemoryRouter> | ||
); | ||
const editButton = screen.getByTestId('edit-displayName-button'); | ||
fireEvent.click(editButton); | ||
|
||
const nameField = await screen.findByTestId('column-name'); | ||
|
||
expect(nameField).toBeInTheDocument(); | ||
|
||
const displayNameField = await screen.findByTestId('column-display-name'); | ||
|
||
expect(displayNameField).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.