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

View File

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

View File

@ -12,11 +12,13 @@
*/ */
import { import {
act,
findByTestId, findByTestId,
findByText, findByText,
fireEvent, fireEvent,
queryByTestId, queryByTestId,
render, render,
screen,
} from '@testing-library/react'; } from '@testing-library/react';
import { flatten } from 'lodash'; import { flatten } from 'lodash';
import { FormattedGlossaryTermData, TagOption } from 'Models'; import { FormattedGlossaryTermData, TagOption } from 'Models';
@ -613,29 +615,29 @@ describe('Test EntityPageInfo component', () => {
}); });
it('Check that tags and glossary terms are not present', async () => { it('Check that tags and glossary terms are not present', async () => {
(getTagCategories as jest.Mock).mockImplementationOnce(() => await act(async () => {
Promise.reject() (getTagCategories as jest.Mock).mockImplementationOnce(() =>
); Promise.reject()
(fetchGlossaryTerms as jest.Mock).mockImplementationOnce(() => );
Promise.reject() (fetchGlossaryTerms as jest.Mock).mockImplementationOnce(() =>
); Promise.reject()
const { getByTestId, queryByText } = render( );
<EntityPageInfo {...mockEntityInfoProp} isTagEditable />,
{ render(<EntityPageInfo {...mockEntityInfoProp} isTagEditable />, {
wrapper: MemoryRouter, wrapper: MemoryRouter,
} });
); const tagWrapper = screen.getByTestId('tags-wrapper');
const tagWrapper = getByTestId('tags-wrapper'); fireEvent.click(
fireEvent.click( tagWrapper,
tagWrapper, new MouseEvent('click', { bubbles: true, cancelable: true })
new MouseEvent('click', { bubbles: true, cancelable: true }) );
);
const tag1 = queryByText('TagCat1.Tag1'); const tag1 = screen.queryByText('TagCat1.Tag1');
const glossaryTerm1 = queryByText('Glossary.Tag1'); const glossaryTerm1 = screen.queryByText('Glossary.Tag1');
expect(tag1).not.toBeInTheDocument(); expect(tag1).not.toBeInTheDocument();
expect(glossaryTerm1).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 () => { it('Show error message on resolve of CTA api without response data', async () => {
(patchTableDetails as jest.Mock).mockImplementation(() => await act(async () => {
Promise.resolve({ data: '' }) (patchTableDetails as jest.Mock).mockImplementation(() =>
); Promise.resolve({ data: '' })
(addFollower as jest.Mock).mockImplementation(() => );
Promise.resolve({ data: '' }) (addFollower as jest.Mock).mockImplementation(() =>
); Promise.resolve({ data: '' })
(removeFollower as jest.Mock).mockImplementation(() => );
Promise.resolve({ data: '' }) (removeFollower as jest.Mock).mockImplementation(() =>
); Promise.resolve({ data: '' })
(addLineage as jest.Mock).mockImplementation(() => );
Promise.resolve({ data: '' }) (addLineage as jest.Mock).mockImplementation(() =>
); Promise.resolve({ data: '' })
(deleteLineageEdge as jest.Mock).mockImplementation(() => );
Promise.resolve({ data: '' }) (deleteLineageEdge as jest.Mock).mockImplementation(() =>
); Promise.resolve({ data: '' })
(postFeedById as jest.Mock).mockImplementation(() => );
Promise.resolve({ data: '' }) (postFeedById as jest.Mock).mockImplementation(() =>
); Promise.resolve({ data: '' })
(postThread as jest.Mock).mockImplementation(() => );
Promise.resolve({ data: '' }) (postThread as jest.Mock).mockImplementation(() =>
); Promise.resolve({ data: '' })
);
const { container } = render(<DatasetDetailsPage />, { const { container } = render(<DatasetDetailsPage />, {
wrapper: MemoryRouter, 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 () => { 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 () => { 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 glossaryComponent = await screen.findByText(/Glossary.component/i);
const handleAddGlossaryClick = await screen.findByTestId( const handleAddGlossaryClick = await screen.findByTestId(
'handleAddGlossaryClick' 'handleAddGlossaryClick'
); );
const handleAddGlossaryTermClick = await screen.findByTestId( const handleAddGlossaryTermClick = await screen.findByTestId(
'handleAddGlossaryTermClick' 'handleAddGlossaryTermClick'
); );
const handleChildLoading = await screen.findByTestId('handleChildLoading'); const handleChildLoading = await screen.findByTestId(
const handleExpandedKey = await screen.findByTestId('handleExpandedKey'); 'handleChildLoading'
const handleGlossaryDelete = await screen.findByTestId( );
'handleGlossaryDelete' const handleExpandedKey = await screen.findByTestId('handleExpandedKey');
); const handleGlossaryDelete = await screen.findByTestId(
const handleGlossaryTermUpdate = await screen.findByTestId( 'handleGlossaryDelete'
'handleGlossaryTermUpdate' );
); const handleGlossaryTermUpdate = await screen.findByTestId(
const handleGlossaryTermDelete = await screen.findByTestId( 'handleGlossaryTermUpdate'
'handleGlossaryTermDelete' );
); const handleGlossaryTermDelete = await screen.findByTestId(
const handleSearchText = await screen.findByTestId('handleSearchText'); 'handleGlossaryTermDelete'
);
const handleSearchText = await screen.findByTestId('handleSearchText');
expect(glossaryComponent).toBeInTheDocument(); expect(glossaryComponent).toBeInTheDocument();
fireEvent.click(handleAddGlossaryClick); fireEvent.click(handleAddGlossaryClick);
fireEvent.click(handleAddGlossaryTermClick); fireEvent.click(handleAddGlossaryTermClick);
fireEvent.click(handleChildLoading); fireEvent.click(handleChildLoading);
fireEvent.click(handleExpandedKey); fireEvent.click(handleExpandedKey);
fireEvent.click(handleGlossaryDelete); fireEvent.click(handleGlossaryDelete);
fireEvent.click(handleGlossaryTermUpdate); fireEvent.click(handleGlossaryTermUpdate);
fireEvent.click(handleGlossaryTermDelete); fireEvent.click(handleGlossaryTermDelete);
fireEvent.click(handleSearchText); fireEvent.click(handleSearchText);
});
}); });
describe('Render Sad Paths', () => { describe('Render Sad Paths', () => {
@ -261,7 +265,9 @@ describe('Test GlossaryComponent page', () => {
expect(handleGlossaryTermDelete).toBeInTheDocument(); expect(handleGlossaryTermDelete).toBeInTheDocument();
fireEvent.click(handleGlossaryTermDelete); await act(async () => {
fireEvent.click(handleGlossaryTermDelete);
});
}); });
it('show error if deleteGlossary API fails', async () => { it('show error if deleteGlossary API fails', async () => {
@ -275,7 +281,9 @@ describe('Test GlossaryComponent page', () => {
expect(handleGlossaryDelete).toBeInTheDocument(); expect(handleGlossaryDelete).toBeInTheDocument();
fireEvent.click(handleGlossaryDelete); await act(async () => {
fireEvent.click(handleGlossaryDelete);
});
}); });
it('show error if patchGlossaryTerm API resolves without data', async () => { it('show error if patchGlossaryTerm API resolves without data', async () => {
@ -289,7 +297,9 @@ describe('Test GlossaryComponent page', () => {
expect(handleGlossaryTermUpdate).toBeInTheDocument(); expect(handleGlossaryTermUpdate).toBeInTheDocument();
fireEvent.click(handleGlossaryTermUpdate); await act(async () => {
fireEvent.click(handleGlossaryTermUpdate);
});
}); });
}); });
}); });