|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import React from 'react'; |
| 7 | +import { render } from '@testing-library/react'; |
| 8 | +import { Provider } from 'react-redux'; |
| 9 | +import { |
| 10 | + RouteComponentProps, |
| 11 | + Route, |
| 12 | + Switch, |
| 13 | + Router, |
| 14 | + Redirect, |
| 15 | +} from 'react-router-dom'; |
| 16 | +import { WorkflowDetail } from './workflow_detail'; |
| 17 | +import { WorkflowDetailRouterProps } from '../../pages'; |
| 18 | +import '@testing-library/jest-dom'; |
| 19 | +import { mockStore, resizeObserverMock } from '../../../test/utils'; |
| 20 | +import { createMemoryHistory } from 'history'; |
| 21 | +import { WORKFLOW_TYPE } from '../../../common'; |
| 22 | + |
| 23 | +jest.mock('../../services', () => { |
| 24 | + const { mockCoreServices } = require('../../../test'); |
| 25 | + return { |
| 26 | + ...jest.requireActual('../../services'), |
| 27 | + ...mockCoreServices, |
| 28 | + }; |
| 29 | +}); |
| 30 | + |
| 31 | +const workflowId = '12345'; |
| 32 | +const workflowName = 'test_workflow'; |
| 33 | + |
| 34 | +const history = createMemoryHistory({ |
| 35 | + initialEntries: [`/workflow/${workflowId}`], |
| 36 | +}); |
| 37 | + |
| 38 | +window.ResizeObserver = resizeObserverMock; |
| 39 | + |
| 40 | +const renderWithRouter = ( |
| 41 | + workflowId: string, |
| 42 | + workflowName: string, |
| 43 | + workflowType: WORKFLOW_TYPE |
| 44 | +) => ({ |
| 45 | + ...render( |
| 46 | + <Provider store={mockStore(workflowId, workflowName, workflowType)}> |
| 47 | + <Router history={history}> |
| 48 | + <Switch> |
| 49 | + <Route |
| 50 | + path="/workflow/:workflowId" |
| 51 | + render={(props: RouteComponentProps<WorkflowDetailRouterProps>) => { |
| 52 | + return <WorkflowDetail setActionMenu={jest.fn()} {...props} />; |
| 53 | + }} |
| 54 | + /> |
| 55 | + </Switch> |
| 56 | + </Router> |
| 57 | + </Provider> |
| 58 | + ), |
| 59 | +}); |
| 60 | + |
| 61 | +describe('WorkflowDetail', () => { |
| 62 | + Object.values(WORKFLOW_TYPE).forEach((type) => { |
| 63 | + test(`renders the page with ${type} type`, () => { |
| 64 | + const { getAllByText, getByText, getByRole } = renderWithRouter( |
| 65 | + workflowId, |
| 66 | + workflowName, |
| 67 | + type |
| 68 | + ); |
| 69 | + |
| 70 | + expect(getAllByText(workflowName).length).toBeGreaterThan(0); |
| 71 | + expect(getAllByText('Create an ingest pipeline').length).toBeGreaterThan( |
| 72 | + 0 |
| 73 | + ); |
| 74 | + expect(getAllByText('Skip ingestion pipeline').length).toBeGreaterThan(0); |
| 75 | + expect(getAllByText('Define ingest pipeline').length).toBeGreaterThan(0); |
| 76 | + expect(getAllByText('Tools').length).toBeGreaterThan(0); |
| 77 | + expect(getAllByText('Preview').length).toBeGreaterThan(0); |
| 78 | + expect(getAllByText('Not started').length).toBeGreaterThan(0); |
| 79 | + expect( |
| 80 | + getAllByText((content) => content.startsWith('Last updated:')).length |
| 81 | + ).toBeGreaterThan(0); |
| 82 | + expect(getAllByText('Search pipeline').length).toBeGreaterThan(0); |
| 83 | + expect(getByText('Close')).toBeInTheDocument(); |
| 84 | + expect(getByText('Export')).toBeInTheDocument(); |
| 85 | + expect(getByText('Visual')).toBeInTheDocument(); |
| 86 | + expect(getByText('JSON')).toBeInTheDocument(); |
| 87 | + expect(getByRole('tab', { name: 'Run ingestion' })).toBeInTheDocument(); |
| 88 | + expect(getByRole('tab', { name: 'Run queries' })).toBeInTheDocument(); |
| 89 | + expect(getByRole('tab', { name: 'Errors' })).toBeInTheDocument(); |
| 90 | + expect(getByRole('tab', { name: 'Resources' })).toBeInTheDocument(); |
| 91 | + }); |
| 92 | + }); |
| 93 | +}); |
0 commit comments