Test: added test suits for ingestionPage and ingestion component (#1374)

* Test: unit test for ingestionpage and ingestion component

* updated ingestion component test

* miner change
This commit is contained in:
Shailesh Parmar 2021-11-25 14:30:05 +05:30 committed by GitHub
parent dc627bd1a3
commit 9c01d574fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 342 additions and 3 deletions

View File

@ -226,7 +226,7 @@ const Ingestion: React.FC<Props> = ({
return ( return (
<PageContainer className="tw-bg-white"> <PageContainer className="tw-bg-white">
<div className="tw-px-4"> <div className="tw-px-4" data-testid="ingestion-container">
<div className="tw-flex"> <div className="tw-flex">
<div className="tw-w-4/12"> <div className="tw-w-4/12">
{searchText || getSearchedIngestions().length > 0 ? ( {searchText || getSearchedIngestions().length > 0 ? (
@ -246,7 +246,7 @@ const Ingestion: React.FC<Props> = ({
className={classNames('tw-h-8 tw-rounded tw-mb-2', { className={classNames('tw-h-8 tw-rounded tw-mb-2', {
'tw-opacity-40': !isAdminUser && !isAuthDisabled, 'tw-opacity-40': !isAdminUser && !isAuthDisabled,
})} })}
data-testid="add-new-user-button" data-testid="add-new-ingestion-button"
size="small" size="small"
theme="primary" theme="primary"
variant="contained" variant="contained"
@ -260,7 +260,7 @@ const Ingestion: React.FC<Props> = ({
<div className="tw-table-responsive tw-my-6"> <div className="tw-table-responsive tw-my-6">
<table className="tw-w-full" data-testid="ingestion-table"> <table className="tw-w-full" data-testid="ingestion-table">
<thead> <thead>
<tr className="tableHead-row"> <tr className="tableHead-row" data-testid="table-header">
<th className="tableHead-cell">Name</th> <th className="tableHead-cell">Name</th>
<th className="tableHead-cell">Type</th> <th className="tableHead-cell">Type</th>
<th className="tableHead-cell">Service</th> <th className="tableHead-cell">Service</th>

View File

@ -0,0 +1,223 @@
import {
findByTestId,
findByText,
fireEvent,
render,
} from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router';
import { mockIngestionWorkFlow } from '../../pages/IngestionPage/IngestionPage.mock';
import Ingestion from './Ingestion.component';
import { IngestionData } from './ingestion.interface';
const mockPaging = {
after: 'after',
before: 'befor',
total: 1,
};
const mockFunction = jest.fn();
const mockPaginghandler = jest.fn();
const mockDeleteIngestion = jest.fn();
const mockTriggerIngestion = jest
.fn()
.mockImplementation(() => Promise.resolve());
jest.mock('../common/non-admin-action/NonAdminAction', () => {
return jest
.fn()
.mockImplementation(({ children }: { children: React.ReactNode }) => (
<div>{children}</div>
));
});
jest.mock('../containers/PageContainer', () => {
return jest
.fn()
.mockImplementation(({ children }: { children: React.ReactNode }) => (
<div>{children}</div>
));
});
jest.mock('../common/searchbar/Searchbar', () => {
return jest.fn().mockImplementation(() => <div>Searchbar</div>);
});
jest.mock('../common/next-previous/NextPrevious', () => {
return jest.fn().mockImplementation(() => <div>NextPrevious</div>);
});
jest.mock('../IngestionModal/IngestionModal.component', () => {
return jest.fn().mockImplementation(() => <div>IngestionModal</div>);
});
jest.mock('../Modals/ConfirmationModal/ConfirmationModal', () => {
return jest.fn().mockImplementation(() => <div>ConfirmationModal</div>);
});
describe('Test Ingestion page', () => {
it('Page Should render', async () => {
const { container } = render(
<Ingestion
addIngestion={mockFunction}
deleteIngestion={mockDeleteIngestion}
ingestionList={mockIngestionWorkFlow.data.data as IngestionData[]}
paging={mockPaging}
pagingHandler={mockPaginghandler}
serviceList={[]}
triggerIngestion={mockTriggerIngestion}
updateIngestion={mockFunction}
/>,
{
wrapper: MemoryRouter,
}
);
const ingestionPageContainer = await findByTestId(
container,
'ingestion-container'
);
const searchBox = await findByText(container, /Searchbar/i);
const addIngestionButton = await findByTestId(
container,
'add-new-ingestion-button'
);
const ingestionTable = await findByTestId(container, 'ingestion-table');
expect(ingestionPageContainer).toBeInTheDocument();
expect(searchBox).toBeInTheDocument();
expect(addIngestionButton).toBeInTheDocument();
expect(ingestionTable).toBeInTheDocument();
});
it('Table should render necessary fields', async () => {
const { container } = render(
<Ingestion
addIngestion={mockFunction}
deleteIngestion={mockDeleteIngestion}
ingestionList={mockIngestionWorkFlow.data.data as IngestionData[]}
paging={mockPaging}
pagingHandler={mockPaginghandler}
serviceList={[]}
triggerIngestion={mockTriggerIngestion}
updateIngestion={mockFunction}
/>,
{
wrapper: MemoryRouter,
}
);
const ingestionTable = await findByTestId(container, 'ingestion-table');
const tableHeaderContainer = await findByTestId(container, 'table-header');
const runButton = await findByTestId(container, 'run');
const editButton = await findByTestId(container, 'edit');
const deleteButton = await findByTestId(container, 'delete');
const tableHeaders: string[] = [];
tableHeaderContainer.childNodes.forEach(
(node) => node.textContent && tableHeaders.push(node.textContent)
);
expect(ingestionTable).toBeInTheDocument();
expect(tableHeaderContainer).toBeInTheDocument();
expect(tableHeaders.length).toBe(6);
expect(tableHeaders).toStrictEqual([
'Name',
'Type',
'Service',
'Schedule',
'Recent Runs',
'Actions',
]);
expect(runButton).toBeInTheDocument();
expect(editButton).toBeInTheDocument();
expect(deleteButton).toBeInTheDocument();
});
it('Pagination should be render if paging is provided', async () => {
const mockPagingAfter = {
after: 'afterKey',
before: 'beforeKey',
};
const { container } = render(
<Ingestion
addIngestion={mockFunction}
deleteIngestion={mockDeleteIngestion}
ingestionList={mockIngestionWorkFlow.data.data as IngestionData[]}
paging={mockPagingAfter}
pagingHandler={mockPaginghandler}
serviceList={[]}
triggerIngestion={mockTriggerIngestion}
updateIngestion={mockFunction}
/>,
{
wrapper: MemoryRouter,
}
);
const nextPrevious = await findByText(container, /NextPrevious/i);
expect(nextPrevious).toBeInTheDocument();
});
it('CTA should work', async () => {
const mockPagingAfter = {
after: 'afterKey',
before: 'beforeKey',
};
const { container } = render(
<Ingestion
addIngestion={mockFunction}
deleteIngestion={mockDeleteIngestion}
ingestionList={mockIngestionWorkFlow.data.data as IngestionData[]}
paging={mockPagingAfter}
pagingHandler={mockPaginghandler}
serviceList={[]}
triggerIngestion={mockTriggerIngestion}
updateIngestion={mockFunction}
/>,
{
wrapper: MemoryRouter,
}
);
// on click of add ingestion
const addIngestionButton = await findByTestId(
container,
'add-new-ingestion-button'
);
fireEvent.click(addIngestionButton);
expect(await findByText(container, /IngestionModal/i)).toBeInTheDocument();
(await findByText(container, /IngestionModal/i)).remove();
// on click of run button
const runButton = await findByTestId(container, 'run');
fireEvent.click(runButton);
expect(mockTriggerIngestion).toBeCalled();
// on click of edit button
const editButton = await findByTestId(container, 'edit');
fireEvent.click(editButton);
expect(await findByText(container, /IngestionModal/i)).toBeInTheDocument();
(await findByText(container, /IngestionModal/i)).remove();
// on click of delete button
const deleteButton = await findByTestId(container, 'delete');
fireEvent.click(deleteButton);
expect(
await findByText(container, /ConfirmationModal/i)
).toBeInTheDocument();
(await findByText(container, /ConfirmationModal/i)).remove();
});
});

View File

@ -0,0 +1,80 @@
export const mockIngestionWorkFlow = {
data: {
data: [
{
id: '3dae41fd-0469-483b-9d48-622577f2e075',
name: 'test1',
displayName: 'Test1',
owner: {
id: '360d5fd9-ba6b-4205-a92c-8eb98286c1c5',
type: 'user',
name: 'Aaron Johnson',
href: 'http://localhost:8585/api/v1/users/360d5fd9-ba6b-4205-a92c-8eb98286c1c5',
},
fullyQualifiedName: 'bigquery.test1',
ingestionType: 'bigquery',
tags: [],
forceDeploy: true,
pauseWorkflow: false,
concurrency: 1,
startDate: '2021-11-24',
endDate: '2022-11-25',
workflowTimezone: 'UTC',
retries: 1,
retryDelay: 300,
workflowCatchup: false,
scheduleInterval: '0 12 * * *',
workflowTimeout: 60,
connectorConfig: {
username: 'test',
password: 'test',
host: 'http://localhost:3000/ingestion',
database: 'mysql',
includeViews: true,
enableDataProfiler: false,
includeFilterPattern: [],
excludeFilterPattern: [],
},
ingestionStatuses: [],
service: {
id: 'e7e34bc7-fc12-40d6-9478-a6297cdefe7a',
type: 'databaseService',
name: 'bigquery',
description: 'BigQuery service used for shopify data',
href: 'http://localhost:8585/api/v1/services/databaseServices/e7e34bc7-fc12-40d6-9478-a6297cdefe7a',
},
href: 'http://localhost:8585/api/ingestion/3dae41fd-0469-483b-9d48-622577f2e075',
version: 0.1,
updatedAt: 1637736180218,
updatedBy: 'anonymous',
},
],
paging: {
total: 1,
},
},
};
export const mockService = {
data: {
data: [
{
id: 'e7e34bc7-fc12-40d6-9478-a6297cdefe7a',
name: 'bigquery',
serviceType: 'BigQuery',
description: 'BigQuery service used for shopify data',
version: 0.1,
updatedAt: 1637734235276,
updatedBy: 'anonymous',
href: 'http://localhost:8585/api/v1/services/databaseServices/e7e34bc7-fc12-40d6-9478-a6297cdefe7a',
jdbc: {
driverClass: 'jdbc',
connectionUrl: 'jdbc://localhost',
},
},
],
paging: {
total: 1,
},
},
};

View File

@ -0,0 +1,36 @@
import { findByText, render } from '@testing-library/react';
import React from 'react';
import IngestionPage from './IngestionPage.component';
import { mockIngestionWorkFlow, mockService } from './IngestionPage.mock';
jest.mock('../../components/Ingestion/Ingestion.component', () => {
return jest.fn().mockReturnValue(<p>Ingestion Component</p>);
});
jest.mock('../../axiosAPIs/serviceAPI', () => ({
getServices: jest.fn().mockImplementation(() => Promise.resolve(mockService)),
}));
jest.mock('../../axiosAPIs/ingestionWorkflowAPI', () => ({
addIngestionWorkflow: jest.fn(),
deleteIngestionWorkflowsById: jest
.fn()
.mockImplementation(() => Promise.resolve()),
getIngestionWorkflows: jest
.fn()
.mockImplementation(() => Promise.resolve(mockIngestionWorkFlow)),
triggerIngestionWorkflowsById: jest
.fn()
.mockImplementation(() => Promise.resolve()),
updateIngestionWorkflow: jest.fn(),
}));
describe('Test Ingestion page', () => {
it('Page Should render', async () => {
const { container } = render(<IngestionPage />);
const ingestionPage = await findByText(container, /Ingestion Component/i);
expect(ingestionPage).toBeInTheDocument();
});
});