mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-19 12:50:20 +00:00
test(ui): unit tests for my data widget (#11841)
* test(ui): unit tests for my data widget * update testid * fix mock * update no data placeholder message
This commit is contained in:
parent
6e0546d008
commit
2bff63fa18
@ -70,7 +70,7 @@ const MyDataWidgetInternal = () => {
|
|||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
{data.length ? (
|
{data.length ? (
|
||||||
<Link
|
<Link
|
||||||
data-testid="my-data"
|
data-testid="view-all-link"
|
||||||
to={getUserPath(currentUserDetails?.name || '', 'mydata')}>
|
to={getUserPath(currentUserDetails?.name || '', 'mydata')}>
|
||||||
<span className="tw-text-info font-normal text-xs">
|
<span className="tw-text-info font-normal text-xs">
|
||||||
{t('label.view-all')}{' '}
|
{t('label.view-all')}{' '}
|
||||||
@ -120,7 +120,7 @@ const MyDataWidgetInternal = () => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
: t('message.no-recently-viewed-date')}
|
: t('server.no-owned-entities')}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
</EntityListSkeleton>
|
</EntityListSkeleton>
|
||||||
|
@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 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 { MemoryRouter } from 'react-router-dom';
|
||||||
|
import { getUserById } from 'rest/userAPI';
|
||||||
|
import { MyDataWidget } from './MyDataWidget.component';
|
||||||
|
|
||||||
|
const userDetails = {
|
||||||
|
id: '123',
|
||||||
|
};
|
||||||
|
|
||||||
|
jest.mock('rest/userAPI', () => ({
|
||||||
|
getUserById: jest.fn().mockImplementation(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
owns: [],
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('utils/EntityUtils', () => ({
|
||||||
|
getEntityName: jest.fn().mockImplementation((obj) => obj.name),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('utils/TableUtils', () => ({
|
||||||
|
getEntityLink: jest.fn().mockImplementation((link) => link),
|
||||||
|
getEntityIcon: jest.fn().mockImplementation((obj) => obj.name),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('./../../../AppState', () => ({
|
||||||
|
getCurrentUserDetails: jest.fn().mockImplementation(() => {
|
||||||
|
return userDetails;
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock(
|
||||||
|
'components/Skeleton/MyData/EntityListSkeleton/EntityListSkeleton.component',
|
||||||
|
() => {
|
||||||
|
return jest.fn().mockImplementation(({ children }) => <>{children}</>);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('MyDataWidget component', () => {
|
||||||
|
it('should fetch data', () => {
|
||||||
|
act(() => {
|
||||||
|
render(<MyDataWidget />);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(getUserById).toHaveBeenCalledWith('123', 'owns');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render header', () => {
|
||||||
|
act(() => {
|
||||||
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<MyDataWidget />
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(screen.getByText('label.my-data')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not render view all for 0 length data', () => {
|
||||||
|
act(() => {
|
||||||
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<MyDataWidget />
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(screen.queryByTestId('view-all-link')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render view all for data present', async () => {
|
||||||
|
(getUserById as jest.Mock).mockImplementationOnce(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
owns: [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
name: 'test 1',
|
||||||
|
fullyQualifiedName: 'test-1',
|
||||||
|
type: 'table',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
name: 'test 2',
|
||||||
|
fullyQualifiedName: 'test-2',
|
||||||
|
type: 'table',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
act(() => {
|
||||||
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<MyDataWidget />
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await screen.findByText('label.view-all')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render table names', async () => {
|
||||||
|
(getUserById as jest.Mock).mockResolvedValueOnce({
|
||||||
|
owns: [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
name: 'test 1',
|
||||||
|
fullyQualifiedName: 'test-1',
|
||||||
|
type: 'table',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
name: 'test 2',
|
||||||
|
fullyQualifiedName: 'test-2',
|
||||||
|
type: 'table',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
act(() => {
|
||||||
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<MyDataWidget />
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await screen.findByText('test 1')).toBeInTheDocument();
|
||||||
|
expect(await screen.findByText('test 2')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
@ -336,7 +336,7 @@ const NavBar = ({
|
|||||||
<Input
|
<Input
|
||||||
addonBefore={entitiesSelect}
|
addonBefore={entitiesSelect}
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
className="search-grey rounded-4 appbar-search min-w"
|
className="search-grey rounded-4 appbar-search"
|
||||||
data-testid="searchBox"
|
data-testid="searchBox"
|
||||||
id="searchBox"
|
id="searchBox"
|
||||||
placeholder={t('message.search-for-entity-types')}
|
placeholder={t('message.search-for-entity-types')}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user