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,
FeedEditor: forwardRef(
jest.fn().mockImplementation(({ onChangeHandler, onSave }, ref) => {
return ( return (
<div <div
data-testid="feed-editor" data-testid="feed-editor"
ref={ref}
onChange={onChangeHandler} onChange={onChangeHandler}
onClick={onSave}> onClick={onSave}>
FeedEditor FeedEditor
</div> </div>
); );
}), })
),
})); }));
jest.mock('./SendButton', () => ({ jest.mock('./SendButton', () => ({

View File

@ -12,6 +12,7 @@
*/ */
import { import {
act,
findByTestId, findByTestId,
findByText, findByText,
fireEvent, fireEvent,
@ -427,6 +428,7 @@ 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 () => {
await act(async () => {
(getTagCategories as jest.Mock).mockImplementationOnce(() => (getTagCategories as jest.Mock).mockImplementationOnce(() =>
Promise.reject() Promise.reject()
); );
@ -453,3 +455,4 @@ describe('Test DashboardDetails component', () => {
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 () => {
await act(async () => {
(getTagCategories as jest.Mock).mockImplementationOnce(() => (getTagCategories as jest.Mock).mockImplementationOnce(() =>
Promise.reject() Promise.reject()
); );
(fetchGlossaryTerms as jest.Mock).mockImplementationOnce(() => (fetchGlossaryTerms as jest.Mock).mockImplementationOnce(() =>
Promise.reject() Promise.reject()
); );
const { getByTestId, queryByText } = render(
<EntityPageInfo {...mockEntityInfoProp} isTagEditable />,
{
wrapper: MemoryRouter,
}
);
const tagWrapper = getByTestId('tags-wrapper'); render(<EntityPageInfo {...mockEntityInfoProp} isTagEditable />, {
wrapper: MemoryRouter,
});
const tagWrapper = screen.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,6 +1104,7 @@ 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 () => {
await act(async () => {
(patchTableDetails as jest.Mock).mockImplementation(() => (patchTableDetails as jest.Mock).mockImplementation(() =>
Promise.resolve({ data: '' }) Promise.resolve({ data: '' })
); );
@ -1146,7 +1147,10 @@ describe('Test DatasetDetails page', () => {
container, container,
'removeLineageHandler' 'removeLineageHandler'
); );
const postFeedHandler = await findByTestId(container, 'postFeedHandler'); const postFeedHandler = await findByTestId(
container,
'postFeedHandler'
);
const createThread = await findByTestId(container, 'createThread'); const createThread = await findByTestId(container, 'createThread');
expect(ContainerText).toBeInTheDocument(); expect(ContainerText).toBeInTheDocument();
@ -1170,6 +1174,7 @@ describe('Test DatasetDetails page', () => {
fireEvent.click(postFeedHandler); fireEvent.click(postFeedHandler);
fireEvent.click(createThread); 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 () => {
(getUpdatedThread as jest.Mock).mockImplementationOnce(() => (getUpdatedThread as jest.Mock).mockImplementationOnce(() =>

View File

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