fix(ui): unit tests console error cleanups (#7368)

* fix(ui): unit tests console error cleanups

* fix forward ref error
This commit is contained in:
Chirag Madlani 2022-09-12 17:42:28 +05:30 committed by GitHub
parent 41f53dab3f
commit 0e512afea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 171 additions and 147 deletions

View File

@ -12,7 +12,7 @@
*/
import { findByTestId, render } from '@testing-library/react';
import React from 'react';
import React, { forwardRef } from 'react';
import { MemoryRouter } from 'react-router-dom';
import ActivityFeedEditor from './ActivityFeedEditor';
@ -28,16 +28,20 @@ jest.mock('../../../utils/FeedUtils', () => ({
}));
jest.mock('../../FeedEditor/FeedEditor', () => ({
FeedEditor: jest.fn().mockImplementation(({ onChangeHandler, onSave }) => {
return (
<div
data-testid="feed-editor"
onChange={onChangeHandler}
onClick={onSave}>
FeedEditor
</div>
);
}),
__esModule: true,
FeedEditor: forwardRef(
jest.fn().mockImplementation(({ onChangeHandler, onSave }, ref) => {
return (
<div
data-testid="feed-editor"
ref={ref}
onChange={onChangeHandler}
onClick={onSave}>
FeedEditor
</div>
);
})
),
}));
jest.mock('./SendButton', () => ({

View File

@ -12,6 +12,7 @@
*/
import {
act,
findByTestId,
findByText,
fireEvent,
@ -427,29 +428,31 @@ describe('Test DashboardDetails component', () => {
});
it('Check that tags and glossary terms are not present', async () => {
(getTagCategories as jest.Mock).mockImplementationOnce(() =>
Promise.reject()
);
(fetchGlossaryTerms as jest.Mock).mockImplementationOnce(() =>
Promise.reject()
);
const { getByTestId, queryByText } = render(
<DashboardDetails {...DashboardDetailsProps} />,
{
wrapper: MemoryRouter,
}
);
await act(async () => {
(getTagCategories as jest.Mock).mockImplementationOnce(() =>
Promise.reject()
);
(fetchGlossaryTerms as jest.Mock).mockImplementationOnce(() =>
Promise.reject()
);
const { getByTestId, queryByText } = render(
<DashboardDetails {...DashboardDetailsProps} />,
{
wrapper: MemoryRouter,
}
);
const tagWrapper = getByTestId('tags-wrapper');
fireEvent.click(
tagWrapper,
new MouseEvent('click', { bubbles: true, cancelable: true })
);
const tagWrapper = getByTestId('tags-wrapper');
fireEvent.click(
tagWrapper,
new MouseEvent('click', { bubbles: true, cancelable: true })
);
const tag1 = queryByText('TagCat1.Tag1');
const glossaryTerm1 = queryByText('Glossary.Tag1');
const tag1 = queryByText('TagCat1.Tag1');
const glossaryTerm1 = queryByText('Glossary.Tag1');
expect(tag1).not.toBeInTheDocument();
expect(glossaryTerm1).not.toBeInTheDocument();
expect(tag1).not.toBeInTheDocument();
expect(glossaryTerm1).not.toBeInTheDocument();
});
});
});

View File

@ -12,11 +12,13 @@
*/
import {
act,
findByTestId,
findByText,
fireEvent,
queryByTestId,
render,
screen,
} from '@testing-library/react';
import { flatten } from 'lodash';
import { FormattedGlossaryTermData, TagOption } from 'Models';
@ -613,29 +615,29 @@ describe('Test EntityPageInfo component', () => {
});
it('Check that tags and glossary terms are not present', async () => {
(getTagCategories as jest.Mock).mockImplementationOnce(() =>
Promise.reject()
);
(fetchGlossaryTerms as jest.Mock).mockImplementationOnce(() =>
Promise.reject()
);
const { getByTestId, queryByText } = render(
<EntityPageInfo {...mockEntityInfoProp} isTagEditable />,
{
await act(async () => {
(getTagCategories as jest.Mock).mockImplementationOnce(() =>
Promise.reject()
);
(fetchGlossaryTerms as jest.Mock).mockImplementationOnce(() =>
Promise.reject()
);
render(<EntityPageInfo {...mockEntityInfoProp} isTagEditable />, {
wrapper: MemoryRouter,
}
);
});
const tagWrapper = screen.getByTestId('tags-wrapper');
const tagWrapper = getByTestId('tags-wrapper');
fireEvent.click(
tagWrapper,
new MouseEvent('click', { bubbles: true, cancelable: true })
);
fireEvent.click(
tagWrapper,
new MouseEvent('click', { bubbles: true, cancelable: true })
);
const tag1 = queryByText('TagCat1.Tag1');
const glossaryTerm1 = queryByText('Glossary.Tag1');
const tag1 = screen.queryByText('TagCat1.Tag1');
const glossaryTerm1 = screen.queryByText('Glossary.Tag1');
expect(tag1).not.toBeInTheDocument();
expect(glossaryTerm1).not.toBeInTheDocument();
expect(tag1).not.toBeInTheDocument();
expect(glossaryTerm1).not.toBeInTheDocument();
});
});
});

View File

@ -1104,71 +1104,76 @@ describe('Test DatasetDetails page', () => {
});
it('Show error message on resolve of CTA api without response data', async () => {
(patchTableDetails as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(addFollower as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(removeFollower as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(addLineage as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(deleteLineageEdge as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(postFeedById as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(postThread as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
await act(async () => {
(patchTableDetails as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(addFollower as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(removeFollower as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(addLineage as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(deleteLineageEdge as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(postFeedById as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
(postThread as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' })
);
const { container } = render(<DatasetDetailsPage />, {
wrapper: MemoryRouter,
const { container } = render(<DatasetDetailsPage />, {
wrapper: MemoryRouter,
});
const ContainerText = await findByTestId(
container,
'datasetdetails-component'
);
const followButton = await findByTestId(container, 'follow-button');
const unfollowButton = await findByTestId(container, 'unfollow-button');
const tag = await findByTestId(container, 'tag');
const description = await findByTestId(container, 'description');
const columnUpdate = await findByTestId(container, 'columnUpdate');
const addLineageHandler = await findByTestId(
container,
'addLineageHandler'
);
const removeLineageHandler = await findByTestId(
container,
'removeLineageHandler'
);
const postFeedHandler = await findByTestId(
container,
'postFeedHandler'
);
const createThread = await findByTestId(container, 'createThread');
expect(ContainerText).toBeInTheDocument();
expect(addLineageHandler).toBeInTheDocument();
expect(removeLineageHandler).toBeInTheDocument();
expect(followButton).toBeInTheDocument();
expect(unfollowButton).toBeInTheDocument();
expect(description).toBeInTheDocument();
expect(tag).toBeInTheDocument();
expect(columnUpdate).toBeInTheDocument();
expect(postFeedHandler).toBeInTheDocument();
expect(createThread).toBeInTheDocument();
fireEvent.click(followButton);
fireEvent.click(unfollowButton);
fireEvent.click(tag);
fireEvent.click(columnUpdate);
fireEvent.click(description);
fireEvent.click(addLineageHandler);
fireEvent.click(removeLineageHandler);
fireEvent.click(postFeedHandler);
fireEvent.click(createThread);
});
const ContainerText = await findByTestId(
container,
'datasetdetails-component'
);
const followButton = await findByTestId(container, 'follow-button');
const unfollowButton = await findByTestId(container, 'unfollow-button');
const tag = await findByTestId(container, 'tag');
const description = await findByTestId(container, 'description');
const columnUpdate = await findByTestId(container, 'columnUpdate');
const addLineageHandler = await findByTestId(
container,
'addLineageHandler'
);
const removeLineageHandler = await findByTestId(
container,
'removeLineageHandler'
);
const postFeedHandler = await findByTestId(container, 'postFeedHandler');
const createThread = await findByTestId(container, 'createThread');
expect(ContainerText).toBeInTheDocument();
expect(addLineageHandler).toBeInTheDocument();
expect(removeLineageHandler).toBeInTheDocument();
expect(followButton).toBeInTheDocument();
expect(unfollowButton).toBeInTheDocument();
expect(description).toBeInTheDocument();
expect(tag).toBeInTheDocument();
expect(columnUpdate).toBeInTheDocument();
expect(postFeedHandler).toBeInTheDocument();
expect(createThread).toBeInTheDocument();
fireEvent.click(followButton);
fireEvent.click(unfollowButton);
fireEvent.click(tag);
fireEvent.click(columnUpdate);
fireEvent.click(description);
fireEvent.click(addLineageHandler);
fireEvent.click(removeLineageHandler);
fireEvent.click(postFeedHandler);
fireEvent.click(createThread);
});
it('Show error message on resolve of getUpdatedThread api without response data', async () => {

View File

@ -213,40 +213,44 @@ describe('Test GlossaryComponent page', () => {
});
it('All Function call should work properly - part 2', async () => {
render(<GlossaryPageV1 />);
await act(async () => {
render(<GlossaryPageV1 />);
const glossaryComponent = await screen.findByText(/Glossary.component/i);
const handleAddGlossaryClick = await screen.findByTestId(
'handleAddGlossaryClick'
);
const handleAddGlossaryTermClick = await screen.findByTestId(
'handleAddGlossaryTermClick'
);
const handleChildLoading = await screen.findByTestId('handleChildLoading');
const handleExpandedKey = await screen.findByTestId('handleExpandedKey');
const handleGlossaryDelete = await screen.findByTestId(
'handleGlossaryDelete'
);
const handleGlossaryTermUpdate = await screen.findByTestId(
'handleGlossaryTermUpdate'
);
const handleGlossaryTermDelete = await screen.findByTestId(
'handleGlossaryTermDelete'
);
const handleSearchText = await screen.findByTestId('handleSearchText');
const glossaryComponent = await screen.findByText(/Glossary.component/i);
const handleAddGlossaryClick = await screen.findByTestId(
'handleAddGlossaryClick'
);
const handleAddGlossaryTermClick = await screen.findByTestId(
'handleAddGlossaryTermClick'
);
const handleChildLoading = await screen.findByTestId(
'handleChildLoading'
);
const handleExpandedKey = await screen.findByTestId('handleExpandedKey');
const handleGlossaryDelete = await screen.findByTestId(
'handleGlossaryDelete'
);
const handleGlossaryTermUpdate = await screen.findByTestId(
'handleGlossaryTermUpdate'
);
const handleGlossaryTermDelete = await screen.findByTestId(
'handleGlossaryTermDelete'
);
const handleSearchText = await screen.findByTestId('handleSearchText');
expect(glossaryComponent).toBeInTheDocument();
expect(glossaryComponent).toBeInTheDocument();
fireEvent.click(handleAddGlossaryClick);
fireEvent.click(handleAddGlossaryTermClick);
fireEvent.click(handleChildLoading);
fireEvent.click(handleExpandedKey);
fireEvent.click(handleGlossaryDelete);
fireEvent.click(handleAddGlossaryClick);
fireEvent.click(handleAddGlossaryTermClick);
fireEvent.click(handleChildLoading);
fireEvent.click(handleExpandedKey);
fireEvent.click(handleGlossaryDelete);
fireEvent.click(handleGlossaryTermUpdate);
fireEvent.click(handleGlossaryTermDelete);
fireEvent.click(handleGlossaryTermUpdate);
fireEvent.click(handleGlossaryTermDelete);
fireEvent.click(handleSearchText);
fireEvent.click(handleSearchText);
});
});
describe('Render Sad Paths', () => {
@ -261,7 +265,9 @@ describe('Test GlossaryComponent page', () => {
expect(handleGlossaryTermDelete).toBeInTheDocument();
fireEvent.click(handleGlossaryTermDelete);
await act(async () => {
fireEvent.click(handleGlossaryTermDelete);
});
});
it('show error if deleteGlossary API fails', async () => {
@ -275,7 +281,9 @@ describe('Test GlossaryComponent page', () => {
expect(handleGlossaryDelete).toBeInTheDocument();
fireEvent.click(handleGlossaryDelete);
await act(async () => {
fireEvent.click(handleGlossaryDelete);
});
});
it('show error if patchGlossaryTerm API resolves without data', async () => {
@ -289,7 +297,9 @@ describe('Test GlossaryComponent page', () => {
expect(handleGlossaryTermUpdate).toBeInTheDocument();
fireEvent.click(handleGlossaryTermUpdate);
await act(async () => {
fireEvent.click(handleGlossaryTermUpdate);
});
});
});
});