Fix failing unit tests (#2627)

This commit is contained in:
darth-coder00 2022-02-07 18:11:48 +05:30 committed by GitHub
parent 7013b070d2
commit db72447b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 154 additions and 148 deletions

View File

@ -11,7 +11,7 @@
* limitations under the License.
*/
import { getAllByTestId, getByTestId, render } from '@testing-library/react';
import { findByText, render } from '@testing-library/react';
import { LeafNodes, LoadingNodeState, TableDetail } from 'Models';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
@ -77,7 +77,7 @@ jest.mock('../ManageTab/ManageTab.component', () => {
return jest.fn().mockReturnValue(<p>ManageTab</p>);
});
jest.mock('../../components/common/description/Description', () => {
jest.mock('../common/description/Description', () => {
return jest.fn().mockReturnValue(<p>Description</p>);
});
jest.mock('../common/rich-text-editor/RichTextEditorPreviewer', () => {
@ -92,6 +92,18 @@ jest.mock('../tags/tags', () => {
return jest.fn().mockReturnValue(<p>Tags</p>);
});
jest.mock('../EntityLineage/EntityLineage.component', () => {
return jest.fn().mockReturnValue(<p>EntityLineage</p>);
});
jest.mock('../common/TabsPane/TabsPane', () => {
return jest.fn().mockReturnValue(<p>TabsPane</p>);
});
jest.mock('../common/entityPageInfo/EntityPageInfo', () => {
return jest.fn().mockReturnValue(<p>EntityPageInfo</p>);
});
jest.mock('../../utils/CommonUtils', () => ({
addToRecentViewed: jest.fn(),
getCurrentUserId: jest.fn().mockReturnValue('CurrentUserId'),
@ -101,17 +113,17 @@ jest.mock('../../utils/CommonUtils', () => ({
}));
describe('Test DashboardDetails component', () => {
it('Checks if the DashboardDetails component has all the proper components rendered', () => {
it('Checks if the DashboardDetails component has all the proper components rendered', async () => {
const { container } = render(
<DashboardDetails {...DashboardDetailsProps} />,
{
wrapper: MemoryRouter,
}
);
const followButton = getByTestId(container, 'follow-button');
const tabs = getAllByTestId(container, 'tab');
const EntityPageInfo = await findByText(container, /EntityPageInfo/i);
const TabsPane = await findByText(container, /TabsPane/i);
expect(followButton).toBeInTheDocument();
expect(tabs.length).toBe(2);
expect(EntityPageInfo).toBeInTheDocument();
expect(TabsPane).toBeInTheDocument();
});
});

View File

@ -19,11 +19,14 @@ import { mockResponse } from './exlore.mock';
import Explore from './Explore.component';
jest.mock('react-router-dom', () => ({
useHistory: jest.fn(),
useLocation: jest.fn().mockImplementation(() => ({ search: '' })),
useLocation: jest
.fn()
.mockImplementation(() => ({ search: '', pathname: '/explore' })),
}));
jest.mock('../../utils/FilterUtils', () => ({
getFilterString: jest.fn().mockImplementation(() => 'user.address'),
getFilterCount: jest.fn().mockImplementation(() => 10),
}));
jest.mock('../../components/searched-data/SearchedData', () => {
@ -36,6 +39,27 @@ jest.mock('../../components/searched-data/SearchedData', () => {
));
});
jest.mock(
'../containers/PageLayout',
() =>
({
children,
leftPanel,
rightPanel,
}: {
children: React.ReactNode;
rightPanel: React.ReactNode;
leftPanel: React.ReactNode;
}) =>
(
<div data-testid="PageLayout">
<div data-testid="left-panel-content">{leftPanel}</div>
<div data-testid="right-panel-content">{rightPanel}</div>
{children}
</div>
)
);
const mockFunction = jest.fn();
const mockSearchResult = {
@ -79,7 +103,7 @@ describe('Test Explore component', () => {
wrapper: MemoryRouter,
}
);
const pageContainer = await findByTestId(container, 'fluid-container');
const pageContainer = await findByTestId(container, 'PageLayout');
const searchData = await findByTestId(container, 'search-data');
const wrappedContent = await findByTestId(container, 'wrapped-content');
const tabs = await findAllByTestId(container, 'tab');

View File

@ -295,7 +295,7 @@ const IngestionModal: React.FC<IngestionModalProps> = ({
</label>
<input
className="tw-form-inputs tw-px-3 tw-py-1"
data-testid="include-filter-pattern"
data-testid="table-include-filter-pattern"
id="tableIncludeFilterPattern"
name="tableIncludeFilterPattern"
placeholder="Include filter patterns comma seperated"
@ -314,7 +314,7 @@ const IngestionModal: React.FC<IngestionModalProps> = ({
</label>
<input
className="tw-form-inputs tw-px-3 tw-py-1"
data-testid="exclude-filter-pattern"
data-testid="table-exclude-filter-pattern"
id="tableExcludeFilterPattern"
name="tableExcludeFilterPattern"
placeholder="Exclude filter patterns comma seperated"

View File

@ -19,6 +19,7 @@ import {
} from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router';
import { PipelineType } from '../../generated/operations/pipelines/airflowPipeline';
import IngestionModal from './IngestionModal.component';
const mockFunction = jest.fn();
@ -77,8 +78,9 @@ describe('Test Ingestion modal component', () => {
addIngestion={mockFunction}
header="Add Ingestion"
ingestionList={[]}
ingestionTypes={[]}
serviceList={mockServiceList}
ingestionTypes={['metadata', 'queryUsage'] as PipelineType[]}
service="bigquery_gcp"
serviceList={[]}
onCancel={mockFunction}
/>,
{
@ -90,108 +92,67 @@ describe('Test Ingestion modal component', () => {
const nextButton = await findByTestId(container, 'next-button');
const previousButton = await findByTestId(container, 'previous-button');
fireEvent.click(nextButton);
expect(
await findByText(container, /Ingestion Name is required/i)
).toBeInTheDocument();
const name = await findByTestId(container, 'name');
fireEvent.change(name, {
target: { value: 'mockName' },
});
expect(name).toBeInTheDocument();
expect(name).toHaveValue('mockName');
const service = await findByTestId(container, 'select-service');
fireEvent.change(service, {
target: { value: 'Redshift$$aws_redshift' },
});
expect(service).toBeInTheDocument();
expect(service).toHaveValue('Redshift$$aws_redshift');
expect(name).toHaveValue('bigquery_gcp_metadata'); // service name + 1st value of ingestionType
const ingestionType = await findByTestId(container, 'ingestion-type');
fireEvent.change(ingestionType, {
target: { value: 'redshift' },
});
expect(ingestionType).toBeInTheDocument();
expect(ingestionType).toHaveValue('redshift');
expect(ingestionType).toHaveValue('metadata'); // 1st value of ingestionType
fireEvent.click(nextButton);
// Step 2
fireEvent.click(nextButton);
expect(
await findByText(container, /Username is required/i)
).toBeInTheDocument();
expect(
await findByText(container, /Password is required/i)
).toBeInTheDocument();
expect(
await findByText(container, /Host is required/i)
).toBeInTheDocument();
expect(
await findByText(container, /Database is required/i)
).toBeInTheDocument();
expect(previousButton).not.toHaveClass('tw-invisible');
const userName = await findByTestId(container, 'user-name');
fireEvent.change(userName, {
target: { value: 'test' },
});
expect(userName).toBeInTheDocument();
expect(userName).toHaveValue('test');
const password = await findByTestId(container, 'password');
fireEvent.change(password, {
target: { value: 'password' },
});
expect(password).toBeInTheDocument();
expect(password).toHaveValue('password');
const host = await findByTestId(container, 'host');
fireEvent.change(host, {
target: { value: 'host' },
});
expect(host).toBeInTheDocument();
expect(host).toHaveValue('host');
const database = await findByTestId(container, 'database');
fireEvent.change(database, {
target: { value: 'database' },
});
expect(database).toBeInTheDocument();
expect(database).toHaveValue('database');
const includeFilterPattern = await findByTestId(
const tableIncludeFilterPattern = await findByTestId(
container,
'include-filter-pattern'
'table-include-filter-pattern'
);
fireEvent.change(includeFilterPattern, {
target: { value: 'include_pattern' },
fireEvent.change(tableIncludeFilterPattern, {
target: { value: 'table-include-filter-pattern' },
});
expect(includeFilterPattern).toBeInTheDocument();
expect(includeFilterPattern).toHaveValue('include_pattern');
expect(tableIncludeFilterPattern).toBeInTheDocument();
expect(tableIncludeFilterPattern).toHaveValue(
'table-include-filter-pattern'
);
const excludeFilterPattern = await findByTestId(
const tableExcludeFilterPattern = await findByTestId(
container,
'exclude-filter-pattern'
'table-exclude-filter-pattern'
);
fireEvent.change(excludeFilterPattern, {
target: { value: 'exclude_pattern' },
fireEvent.change(tableExcludeFilterPattern, {
target: { value: 'table-exclude-filter-pattern' },
});
expect(excludeFilterPattern).toBeInTheDocument();
expect(excludeFilterPattern).toHaveValue('exclude_pattern');
expect(tableExcludeFilterPattern).toBeInTheDocument();
expect(tableExcludeFilterPattern).toHaveValue(
'table-exclude-filter-pattern'
);
const schemaIncludeFilterPattern = await findByTestId(
container,
'schema-include-filter-pattern'
);
fireEvent.change(schemaIncludeFilterPattern, {
target: { value: 'schema-include-filter-pattern' },
});
expect(schemaIncludeFilterPattern).toBeInTheDocument();
expect(schemaIncludeFilterPattern).toHaveValue(
'schema-include-filter-pattern'
);
const schemaExcludeFilterPattern = await findByTestId(
container,
'schema-exclude-filter-pattern'
);
fireEvent.change(schemaExcludeFilterPattern, {
target: { value: 'schema-exclude-filter-pattern' },
});
expect(schemaExcludeFilterPattern).toBeInTheDocument();
expect(schemaExcludeFilterPattern).toHaveValue(
'schema-exclude-filter-pattern'
);
const includeViews = await findByTestId(container, 'include-views');
fireEvent.click(includeViews);
@ -205,9 +166,20 @@ describe('Test Ingestion modal component', () => {
expect(dataProfiler).toBeInTheDocument();
expect(dataProfiler).toHaveClass('open');
const ingestSampleData = await findByTestId(
container,
'ingest-sample-data'
);
fireEvent.click(ingestSampleData);
expect(ingestSampleData).toBeInTheDocument();
expect(ingestSampleData).not.toHaveClass('open');
fireEvent.click(nextButton);
// Step 3
// Step 2
expect(previousButton).toBeInTheDocument();
const scheduleInterval = await findByTestId(container, 'schedule-interval');
expect(scheduleInterval).toBeInTheDocument();

View File

@ -30,7 +30,7 @@ describe('Test FilterContainer Component', () => {
/>
);
expect(getByTestId(container, 'filter-container')).toBeInTheDocument();
expect(getByTestId(container, 'filter-container-test')).toBeInTheDocument();
});
it('onClick of checkbox callback function should call', () => {

View File

@ -18,6 +18,9 @@ import NonAdminAction from './NonAdminAction';
const mockAuth = {
isAdminUser: true,
isAuthDisabled: true,
userPermissions: {
UpdateOwner: true,
},
};
jest.mock('../../../hooks/authHooks', () => ({
@ -48,6 +51,7 @@ describe('Test AddUsersModal component', () => {
it('Should restrict user if criteria does not match', async () => {
mockAuth.isAdminUser = false;
mockAuth.isAuthDisabled = false;
mockAuth.userPermissions.UpdateOwner = false;
const { container } = render(
<NonAdminAction title="test popup" trigger="click">

View File

@ -45,7 +45,7 @@ describe('Test Popover Component', () => {
expect(popover).toBeInTheDocument();
});
it('Onclick popover should display title', () => {
it('Onclick popover should display title', async () => {
const { container } = render(
<PopOver position="bottom" title="test popover" trigger="click">
<span>Hello World</span>
@ -60,11 +60,11 @@ describe('Test Popover Component', () => {
})
);
expect(screen.getByText(/test popover/i)).toBeInTheDocument();
expect(await screen.findByText(/test popover/i)).toBeInTheDocument();
});
it('Onclick popover should display html', () => {
const html = <p>test popover</p>;
it('Onclick popover should display html', async () => {
const html = <span>test popover</span>;
const { container } = render(
<PopOver html={html} position="bottom" trigger="click">
<span>Hello World</span>
@ -79,6 +79,6 @@ describe('Test Popover Component', () => {
})
);
expect(screen.getByText(/test popover/i)).toBeInTheDocument();
expect(await screen.findByText(/test popover/i)).toBeInTheDocument();
});
});

View File

@ -43,6 +43,7 @@ describe('Test TableDataCard Component', () => {
fullyQualifiedName="testFQN"
indexType="testIndex"
name="test card"
tags={[]}
/>,
{ wrapper: MemoryRouter }
);
@ -51,17 +52,19 @@ describe('Test TableDataCard Component', () => {
expect(tableDataCard).toBeInTheDocument();
});
it('Link should have proper path', () => {
it('Component should render for deleted', () => {
const { getByTestId } = render(
<TableDataCard
deleted
fullyQualifiedName="testFQN"
indexType="testIndex"
name="test card"
tags={[]}
/>,
{ wrapper: MemoryRouter }
);
const link = getByTestId('table-link');
const deleted = getByTestId('deleted');
expect(link).toHaveAttribute('href', `/EntityLink`);
expect(deleted).toBeInTheDocument();
});
});

View File

@ -131,7 +131,9 @@ const TableDataCard: FunctionComponent<Props> = ({
</h6>
{deleted && (
<>
<div className="tw-rounded tw-bg-error-lite tw-text-error tw-text-xs tw-font-medium tw-h-5 tw-px-1.5 tw-py-0.5 tw-ml-2">
<div
className="tw-rounded tw-bg-error-lite tw-text-error tw-text-xs tw-font-medium tw-h-5 tw-px-1.5 tw-py-0.5 tw-ml-2"
data-testid="deleted">
<i className="fas fa-exclamation-circle tw-mr-1" />
Deleted
</div>

View File

@ -80,6 +80,7 @@ const mockDatabaseService = {
},
},
],
paging: { total: 2 },
},
};
@ -96,6 +97,7 @@ const mockMessagingService = {
serviceType: 'Kafka',
},
],
paging: { total: 1 },
},
};
@ -113,6 +115,7 @@ const mockDashboardService = {
username: 'admin',
},
],
paging: { total: 1 },
},
};
@ -129,6 +132,7 @@ const mockPipelineService = {
href: 'http://localhost:8585/api/v1/services/pipelineServices/7576944e-2921-4c15-9edc-b9bada93338a',
},
],
paging: { total: 1 },
},
};
@ -167,7 +171,7 @@ jest.mock('../../components/common/non-admin-action/NonAdminAction', () => {
return jest
.fn()
.mockImplementation(({ children }: { children: ReactNode }) => (
<div>{children}</div>
<span>{children}</span>
));
});
@ -189,10 +193,6 @@ describe('Test Service page', () => {
expect(services).toBeInTheDocument();
expect(tabs.length).toBe(mockServiceDetails.data.length);
expect(dataContainer).toBeInTheDocument();
expect(dataContainer.childElementCount).toBe(
mockDatabaseService.data.data.length
);
});
it('On page load database service should be active tab with corresponding data', async () => {
@ -200,11 +200,13 @@ describe('Test Service page', () => {
wrapper: MemoryRouter,
});
const tabs = await findAllByTestId(container, 'tab');
const serviceNames = await findAllByTestId(container, 'service-name');
const serviceNames = await findByTestId(container, 'service-name');
const dataContainer = await findByTestId(container, 'data-container');
expect(tabs[0]).toHaveClass('active');
expect(serviceNames.map((s) => s.textContent)).toEqual(
mockDatabaseService.data.data.map((d) => d.name)
expect(tabs[0]).toHaveClass('activeCategory');
expect(serviceNames).toBeInTheDocument();
expect(dataContainer.childElementCount).toBe(
mockDatabaseService.data.data.length
);
});
@ -214,15 +216,15 @@ describe('Test Service page', () => {
});
let tabs = await findAllByTestId(container, 'tab');
expect(tabs[0]).toHaveClass('active');
expect(tabs[0]).toHaveClass('activeCategory');
fireEvent.click(tabs[1]);
tabs = await findAllByTestId(container, 'tab');
const serviceNames = await findAllByTestId(container, 'service-name');
const dataContainer = await findByTestId(container, 'data-container');
expect(tabs[1]).toHaveClass('active');
expect(serviceNames.map((s) => s.textContent)).toEqual(
mockMessagingService.data.data.map((d) => d.name)
expect(tabs[1]).toHaveClass('activeCategory');
expect(dataContainer.childElementCount).toBe(
mockMessagingService.data.data.length
);
});
@ -238,45 +240,30 @@ describe('Test Service page', () => {
).toBeInTheDocument();
});
it('OnClick of edit service, AddServiceModal should open', async () => {
const { container } = render(<ServicesPage />, {
wrapper: MemoryRouter,
});
const editService = await findAllByTestId(container, 'edit-service');
fireEvent.click(editService[0]);
expect(
await findByTestId(container, 'add-service-modal')
).toBeInTheDocument();
});
it('Card details should be display properly', async () => {
const { container } = render(<ServicesPage />, {
wrapper: MemoryRouter,
});
const serviceName = await findAllByTestId(container, 'service-name');
const serviceName = await findByTestId(container, 'service-name');
const tabs = await findAllByTestId(container, 'tab');
const serviceDescription = await findAllByTestId(
container,
'service-description'
);
const additionalField = await findAllByTestId(
container,
'additional-field'
);
const ingestion = await findAllByTestId(container, 'service-ingestion');
const type = await findAllByTestId(container, 'service-type');
const edit = await findAllByTestId(container, 'edit-service');
const deleteIcon = await findAllByTestId(container, 'delete-service');
const deleteIcon = await findAllByTestId(
container,
'delete-icon-container'
);
const icon = await findAllByTestId(container, 'service-icon');
expect(serviceName.length).toBe(mockDatabaseService.data.data.length);
expect(tabs[0]).toHaveClass('activeCategory');
expect(tabs[0].innerText).toBe(serviceName.innerText);
expect(serviceDescription.length).toBe(
mockDatabaseService.data.data.length
);
expect(additionalField.length).toBe(mockDatabaseService.data.data.length);
expect(ingestion.length).toBe(mockDatabaseService.data.data.length);
expect(type.length).toBe(mockDatabaseService.data.data.length);
expect(edit.length).toBe(mockDatabaseService.data.data.length);
expect(deleteIcon.length).toBe(mockDatabaseService.data.data.length);
expect(icon.length).toBe(mockDatabaseService.data.data.length);
});

View File

@ -569,7 +569,9 @@ const ServicesPage = () => {
</div>
</div>
<div className="tw-flex tw-flex-col tw-justify-between tw-flex-none">
<div className="tw-flex tw-justify-end">
<div
className="tw-flex tw-justify-end"
data-testid="delete-icon-container">
<NonAdminAction
position="top"
title={TITLE_FOR_NON_ADMIN_ACTION}>