Skip to content

Commit

Permalink
Adding unit tests (opensearch-project#317)
Browse files Browse the repository at this point in the history
Signed-off-by: saimedhi <[email protected]>
  • Loading branch information
saimedhi authored Aug 29, 2024
1 parent 831f71e commit 7cf2ac2
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { store } from '../../../store';
import { ImportWorkflowModal } from './import_workflow_modal';

jest.mock('../../../services', () => {
const { mockCoreServices } = require('../../../../test');
return {
...jest.requireActual('../../../services'),
...mockCoreServices,
};
});

const renderWithRouter = () =>
render(
<Provider store={store}>
<Router>
<Switch>
<Route
render={() => (
<ImportWorkflowModal
isImportModalOpen={true}
setIsImportModalOpen={jest.fn()}
setSelectedTabId={jest.fn()}
/>
)}
/>
</Switch>
</Router>
</Provider>
);

describe('ImportWorkflowModal', () => {
test('renders the page', () => {
const { getAllByText } = renderWithRouter();
expect(
getAllByText('Import a workflow (JSON/YAML)').length
).toBeGreaterThan(0);
});
});
38 changes: 38 additions & 0 deletions public/pages/workflows/new_workflow/new_workflow.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Provider } from 'react-redux';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { store } from '../../../store';
import { NewWorkflow } from './new_workflow';

jest.mock('../../../services', () => {
const { mockCoreServices } = require('../../../../test');
return {
...jest.requireActual('../../../services'),
...mockCoreServices,
};
});

const renderWithRouter = () =>
render(
<Provider store={store}>
<Router>
<Switch>
<Route render={() => <NewWorkflow />} />
</Switch>
</Router>
</Provider>
);

describe('NewWorkflow', () => {
test('renders the search bar', () => {
const { getByPlaceholderText } = renderWithRouter();
expect(getByPlaceholderText('Search')).toBeInTheDocument();
});
});
37 changes: 37 additions & 0 deletions public/pages/workflows/workflow_list/workflow_list.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { store } from '../../../store';
import { WorkflowList } from './workflow_list';

jest.mock('../../../services', () => {
const { mockCoreServices } = require('../../../../test');
return {
...jest.requireActual('../../../services'),
...mockCoreServices,
};
});

const renderWithRouter = () =>
render(
<Provider store={store}>
<Router>
<Switch>
<Route render={() => <WorkflowList setSelectedTabId={jest.fn()} />} />
</Switch>
</Router>
</Provider>
);

describe('WorkflowList', () => {
test('renders the page', () => {
const { getAllByText } = renderWithRouter();
expect(getAllByText('Manage existing workflows').length).toBeGreaterThan(0);
});
});

0 comments on commit 7cf2ac2

Please sign in to comment.