-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathworkflow_detail.test.tsx
217 lines (196 loc) · 7.43 KB
/
workflow_detail.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { Provider } from 'react-redux';
import { RouteComponentProps, Route, Switch, Router } from 'react-router-dom';
import userEvent from '@testing-library/user-event';
import { WorkflowDetail } from './workflow_detail';
import { WorkflowDetailRouterProps } from '../../pages';
import '@testing-library/jest-dom';
import { mockStore, resizeObserverMock } from '../../../test/utils';
import { createMemoryHistory } from 'history';
import { MINIMUM_FULL_SUPPORTED_VERSION, WORKFLOW_TYPE } from '../../../common';
jest.mock('../../services', () => {
const { mockCoreServices } = require('../../../test');
return {
...jest.requireActual('../../services'),
...mockCoreServices,
};
});
jest.setTimeout(10000);
const workflowId = '12345';
const workflowName = 'test_workflow';
window.ResizeObserver = resizeObserverMock;
const renderWithRouter = (
workflowId: string,
workflowName: string,
workflowType: WORKFLOW_TYPE
) => {
const history = createMemoryHistory({
initialEntries: [`/workflow/${workflowId}`],
});
const mockInput = {
id: workflowId,
name: workflowName,
type: workflowType,
version: [
WORKFLOW_TYPE.SEMANTIC_SEARCH,
WORKFLOW_TYPE.MULTIMODAL_SEARCH,
WORKFLOW_TYPE.HYBRID_SEARCH,
].includes(workflowType)
? MINIMUM_FULL_SUPPORTED_VERSION
: undefined,
};
return {
...render(
<Provider store={mockStore(mockInput)}>
<Router history={history}>
<Switch>
<Route
path="/workflow/:workflowId"
render={(
props: RouteComponentProps<WorkflowDetailRouterProps>
) => <WorkflowDetail setActionMenu={jest.fn()} {...props} />}
/>
</Switch>
</Router>
</Provider>
),
history,
};
};
describe('WorkflowDetail Page with create ingestion option', () => {
beforeEach(() => {
jest.clearAllMocks();
});
Object.values(WORKFLOW_TYPE).forEach((type) => {
test(`renders the WorkflowDetail page with ${type} type`, async () => {
const {
getAllByText,
getByText,
getByRole,
getByTestId,
} = renderWithRouter(workflowId, workflowName, type);
expect(getAllByText(workflowName).length).toBeGreaterThan(0);
expect(getAllByText('Inspect flows').length).toBeGreaterThan(0);
expect(getAllByText('Preview flows').length).toBeGreaterThan(0);
expect(
getAllByText((content) => content.startsWith('Last saved:')).length
).toBeGreaterThan(0);
expect(getByText('Close')).toBeInTheDocument();
expect(getByText('Export')).toBeInTheDocument();
expect(getByText('Visual')).toBeInTheDocument();
expect(getByText('JSON')).toBeInTheDocument();
expect(getByRole('tab', { name: 'Test flow' })).toBeInTheDocument();
expect(getByRole('tab', { name: 'Ingest response' })).toBeInTheDocument();
expect(getByRole('tab', { name: 'Errors' })).toBeInTheDocument();
expect(getByRole('tab', { name: 'Resources' })).toBeInTheDocument();
// "Search pipeline" button should be disabled by default
const searchPipelineButton = getByTestId('searchPipelineButton');
expect(searchPipelineButton).toBeInTheDocument();
expect(searchPipelineButton).toBeDisabled();
});
});
});
describe('WorkflowDetail Page Functionality (Custom Workflow)', () => {
beforeEach(() => {
jest.clearAllMocks();
});
test('tests Export button, Tools panel toggling, and Workspace preview', async () => {
global.URL.createObjectURL = jest.fn();
const { getByText, container, getByTestId } = renderWithRouter(
workflowId,
workflowName,
WORKFLOW_TYPE.CUSTOM
);
// Export button opens the export component
userEvent.click(getByTestId('exportButton'));
await waitFor(() => {
expect(getByText(`Export '${workflowName}'`)).toBeInTheDocument();
});
// Close the export component
userEvent.click(getByTestId('exportCloseButton'));
// Check workspace button group exists (Visual and JSON)
getByTestId('visualJSONToggleButtonGroup');
// Tools panel should collapse and expand the toggle
const toolsPanel = container.querySelector('#tools_panel_id');
expect(toolsPanel).toBeVisible();
const toggleButton = toolsPanel?.querySelector('button[type="button"]');
expect(toggleButton).toBeInTheDocument();
userEvent.click(toggleButton!);
// Tools panel after collapsing
const collapsedToolsPanel = container.querySelector('#tools_panel_id');
await waitFor(() => {
expect(collapsedToolsPanel).toHaveClass('euiResizablePanel-isCollapsed');
});
// Tools panel after expanding
userEvent.click(toggleButton!);
const expandedToolsPanel = container.querySelector('#tools_panel_id');
await waitFor(() => {
expect(expandedToolsPanel).not.toHaveClass(
'euiResizablePanel-isCollapsed'
);
});
});
});
describe('WorkflowDetail Page with skip ingestion option (Hybrid Search Workflow)', () => {
beforeEach(() => {
jest.clearAllMocks();
});
test(`renders the WorkflowDetail page with skip ingestion option`, async () => {
const { getByTestId, getAllByText, getAllByTestId } = renderWithRouter(
workflowId,
workflowName,
WORKFLOW_TYPE.HYBRID_SEARCH
);
// Defining a new ingest pipeline & index is enabled by default
const enabledCheckbox = getByTestId('switch-ingest.enabled');
// Skipping ingest pipeline and navigating to search
userEvent.click(enabledCheckbox);
await waitFor(() => {});
const searchPipelineButton = getByTestId('searchPipelineButton');
userEvent.click(searchPipelineButton);
// Search pipeline
await waitFor(() => {
expect(getAllByText('Search flow').length).toBeGreaterThan(0);
});
expect(getAllByText('Configure query interface').length).toBeGreaterThan(0);
// Edit Search Query
const queryEditButton = getByTestId('queryEditButton');
expect(queryEditButton).toBeInTheDocument();
userEvent.click(queryEditButton);
await waitFor(() => {
expect(getAllByText('Define query').length).toBeGreaterThan(0);
});
const searchQueryPresetButton = getByTestId('searchQueryPresetButton');
expect(searchQueryPresetButton).toBeInTheDocument();
const updateSearchQueryButton = getByTestId('updateSearchQueryButton');
expect(updateSearchQueryButton).toBeInTheDocument();
userEvent.click(updateSearchQueryButton);
// Add request processor
const addRequestProcessorButton = await waitFor(
() => getAllByTestId('addProcessorButton')[0]
);
userEvent.click(addRequestProcessorButton);
await waitFor(() => {
const popoverPanel = document.querySelector('.euiPopover__panel');
expect(popoverPanel).toBeTruthy();
});
// Add response processor
const addResponseProcessorButton = getAllByTestId('addProcessorButton')[1];
userEvent.click(addResponseProcessorButton);
await waitFor(() => {
const popoverPanel = document.querySelector('.euiPopover__panel');
expect(popoverPanel).toBeTruthy();
});
// Build and Run query, Back buttons are present
const searchPipelineBackButton = getByTestId('searchPipelineBackButton');
userEvent.click(searchPipelineBackButton);
await waitFor(() => {
expect(enabledCheckbox).not.toBeChecked();
});
});
});