forked from open-metadata/OpenMetadata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: unit test cases of right side bar (open-metadata#15123)
* test: unit test cases of announcements widget * test: unit test case of following widget
- Loading branch information
1 parent
f6e5de3
commit 6cfa986
Showing
3 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
...-ui/src/main/resources/ui/src/components/MyData/RightSidebar/AnnouncementsWidget.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,98 @@ | ||
/* | ||
* 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, render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { TaskType, ThreadType } from '../../../generated/api/feed/createThread'; | ||
import AnnouncementsWidget from './AnnouncementsWidget'; | ||
|
||
const mockAnnouncementData = [ | ||
{ | ||
id: 'f0761441-478e-4373-919e-70b8f587c43f', | ||
type: ThreadType.Announcement, | ||
href: 'http://localhost:8585/api/v1/feed/f0761441-478e-4373-919e-70b8f587c43f', | ||
threadTs: 1707475672423, | ||
about: '<#E::tableu>', | ||
entityId: '07f9dc02-9cbd-447c-9fc9-988c419a45e0', | ||
updatedAt: 1707475792808, | ||
resolved: true, | ||
message: 'wertyui', | ||
announcement: { | ||
description: 'description', | ||
startTime: 1707475665, | ||
endTime: 1707648467, | ||
}, | ||
task: { | ||
id: 1, | ||
assignees: [ | ||
{ | ||
id: '1', | ||
type: 'user', | ||
}, | ||
], | ||
type: TaskType.RequestDescription, | ||
}, | ||
}, | ||
]; | ||
|
||
jest.mock( | ||
'../../ActivityFeed/ActivityFeedCard/FeedCardBody/FeedCardBodyV1', | ||
() => { | ||
return jest.fn().mockImplementation(() => <div>FeedCardBodyV1</div>); | ||
} | ||
); | ||
|
||
jest.mock( | ||
'../../ActivityFeed/ActivityFeedCard/FeedCardHeader/FeedCardHeaderV1', | ||
() => { | ||
return jest.fn().mockImplementation(() => <div>FeedCardHeaderV1</div>); | ||
} | ||
); | ||
|
||
jest.mock('../../Loader/Loader', () => | ||
jest.fn().mockReturnValue(<div>Loader</div>) | ||
); | ||
|
||
describe('AnnouncementsWidget', () => { | ||
it('should render Announcements Widget', () => { | ||
const { container } = render(<AnnouncementsWidget widgetKey="testKey" />); | ||
|
||
expect(container).toBeTruthy(); | ||
}); | ||
|
||
it('should render loading state', () => { | ||
render(<AnnouncementsWidget isAnnouncementLoading widgetKey="testKey" />); | ||
|
||
expect(screen.getByText('Loader')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render empty state', () => { | ||
render(<AnnouncementsWidget announcements={[]} widgetKey="testKey" />); | ||
|
||
expect(screen.getByTestId('no-data-placeholder')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render announcements', async () => { | ||
await act(async () => { | ||
render( | ||
<AnnouncementsWidget | ||
announcements={mockAnnouncementData} | ||
widgetKey="testKey" | ||
/> | ||
); | ||
}); | ||
|
||
expect(screen.getByText('FeedCardBodyV1')).toBeInTheDocument(); | ||
expect(screen.getByText('FeedCardHeaderV1')).toBeInTheDocument(); | ||
expect(screen.getByText('label.announcement')).toBeInTheDocument(); | ||
}); | ||
}); |
92 changes: 92 additions & 0 deletions
92
...data-ui/src/main/resources/ui/src/components/MyData/RightSidebar/FollowingWidget.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,92 @@ | ||
/* | ||
* 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 FollowingWidget from './FollowingWidget'; | ||
|
||
jest.mock('../../Auth/AuthProviders/AuthProvider', () => ({ | ||
useAuthContext: jest.fn().mockImplementation(() => ({ | ||
currentUser: { name: 'testUser' }, | ||
})), | ||
})); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
Link: jest | ||
.fn() | ||
.mockImplementation(({ children }: { children: React.ReactNode }) => ( | ||
<p data-testid="link">{children}</p> | ||
)), | ||
})); | ||
|
||
const mockProps = { | ||
followedData: [ | ||
{ | ||
id: '1', | ||
type: 'data', | ||
name: 'Data 1', | ||
description: 'Description 1', | ||
displayName: 'Data 1', | ||
fullyQualifiedName: 'org.data.1', | ||
href: '/entity/1', | ||
deleted: false, | ||
inherited: false, | ||
}, | ||
], | ||
followedDataCount: 1, | ||
isLoadingOwnedData: false, | ||
widgetKey: 'testKey', | ||
}; | ||
|
||
describe('FollowingWidget', () => { | ||
it('should render Following Widget', () => { | ||
render(<FollowingWidget {...mockProps} />); | ||
|
||
expect(screen.getByTestId('following-widget')).toBeInTheDocument(); | ||
expect( | ||
screen.getByTestId('following-data-total-count') | ||
).toBeInTheDocument(); | ||
expect(screen.getByText('label.following')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render loading state', () => { | ||
render(<FollowingWidget {...mockProps} isLoadingOwnedData />); | ||
|
||
expect(screen.getByTestId('entity-list-skeleton')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render empty state', () => { | ||
render(<FollowingWidget {...mockProps} followedData={[]} />); | ||
|
||
expect(screen.getByTestId('no-data-placeholder')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText('message.not-followed-anything') | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should remove widget when close button is clicked', async () => { | ||
const handleRemoveWidget = jest.fn(); | ||
|
||
render( | ||
<FollowingWidget | ||
{...mockProps} | ||
isEditView | ||
handleRemoveWidget={handleRemoveWidget} | ||
/> | ||
); | ||
await act(async () => { | ||
fireEvent.click(screen.getByTestId('remove-widget-button')); | ||
}); | ||
|
||
expect(handleRemoveWidget).toHaveBeenCalledWith('testKey'); | ||
}); | ||
}); |
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