diff --git a/openmetadata-ui/src/main/resources/ui/src/components/MyData/RightSidebar/AnnouncementsWidget.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/MyData/RightSidebar/AnnouncementsWidget.test.tsx new file mode 100644 index 000000000000..951bf2f8d025 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/components/MyData/RightSidebar/AnnouncementsWidget.test.tsx @@ -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(() =>
FeedCardBodyV1
); + } +); + +jest.mock( + '../../ActivityFeed/ActivityFeedCard/FeedCardHeader/FeedCardHeaderV1', + () => { + return jest.fn().mockImplementation(() =>
FeedCardHeaderV1
); + } +); + +jest.mock('../../Loader/Loader', () => + jest.fn().mockReturnValue(
Loader
) +); + +describe('AnnouncementsWidget', () => { + it('should render Announcements Widget', () => { + const { container } = render(); + + expect(container).toBeTruthy(); + }); + + it('should render loading state', () => { + render(); + + expect(screen.getByText('Loader')).toBeInTheDocument(); + }); + + it('should render empty state', () => { + render(); + + expect(screen.getByTestId('no-data-placeholder')).toBeInTheDocument(); + }); + + it('should render announcements', async () => { + await act(async () => { + render( + + ); + }); + + expect(screen.getByText('FeedCardBodyV1')).toBeInTheDocument(); + expect(screen.getByText('FeedCardHeaderV1')).toBeInTheDocument(); + expect(screen.getByText('label.announcement')).toBeInTheDocument(); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/MyData/RightSidebar/FollowingWidget.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/MyData/RightSidebar/FollowingWidget.test.tsx new file mode 100644 index 000000000000..2983fa5304b7 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/components/MyData/RightSidebar/FollowingWidget.test.tsx @@ -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 }) => ( +

{children}

+ )), +})); + +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(); + + 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(); + + expect(screen.getByTestId('entity-list-skeleton')).toBeInTheDocument(); + }); + + it('should render empty state', () => { + render(); + + 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( + + ); + await act(async () => { + fireEvent.click(screen.getByTestId('remove-widget-button')); + }); + + expect(handleRemoveWidget).toHaveBeenCalledWith('testKey'); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Skeleton/MyData/EntityListSkeleton/EntityListSkeleton.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Skeleton/MyData/EntityListSkeleton/EntityListSkeleton.component.tsx index a1abfb692bdf..d1e0402810ef 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Skeleton/MyData/EntityListSkeleton/EntityListSkeleton.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Skeleton/MyData/EntityListSkeleton/EntityListSkeleton.component.tsx @@ -27,7 +27,7 @@ const EntityListSkeleton = ({ ...props }: EntityListSkeletonProps) => { return loading ? ( -
+
{getSkeletonMockData(dataLength).map(() => (