4
4
*/
5
5
6
6
import React from 'react' ;
7
- import { render } from '@testing-library/react' ;
7
+ import { render , waitFor } from '@testing-library/react' ;
8
8
import { Provider } from 'react-redux' ;
9
- import {
10
- RouteComponentProps ,
11
- Route ,
12
- Switch ,
13
- Router ,
14
- Redirect ,
15
- } from 'react-router-dom' ;
9
+ import { RouteComponentProps , Route , Switch , Router } from 'react-router-dom' ;
10
+ import userEvent from '@testing-library/user-event' ;
16
11
import { WorkflowDetail } from './workflow_detail' ;
17
12
import { WorkflowDetailRouterProps } from '../../pages' ;
18
13
import '@testing-library/jest-dom' ;
@@ -31,41 +26,48 @@ jest.mock('../../services', () => {
31
26
const workflowId = '12345' ;
32
27
const workflowName = 'test_workflow' ;
33
28
34
- const history = createMemoryHistory ( {
35
- initialEntries : [ `/workflow/${ workflowId } ` ] ,
36
- } ) ;
37
-
38
29
window . ResizeObserver = resizeObserverMock ;
39
30
40
31
const renderWithRouter = (
41
32
workflowId : string ,
42
33
workflowName : string ,
43
34
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
- } ) ;
35
+ ) => {
36
+ const history = createMemoryHistory ( {
37
+ initialEntries : [ `/workflow/${ workflowId } ` ] ,
38
+ } ) ;
39
+
40
+ return {
41
+ ...render (
42
+ < Provider store = { mockStore ( workflowId , workflowName , workflowType ) } >
43
+ < Router history = { history } >
44
+ < Switch >
45
+ < Route
46
+ path = "/workflow/:workflowId"
47
+ render = { (
48
+ props : RouteComponentProps < WorkflowDetailRouterProps >
49
+ ) => {
50
+ return < WorkflowDetail setActionMenu = { jest . fn ( ) } { ...props } /> ;
51
+ } }
52
+ />
53
+ </ Switch >
54
+ </ Router >
55
+ </ Provider >
56
+ ) ,
57
+ history,
58
+ } ;
59
+ } ;
60
60
61
61
describe ( 'WorkflowDetail' , ( ) => {
62
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
- ) ;
63
+ test ( `renders the page with ${ type } type` , async ( ) => {
64
+ const {
65
+ getAllByText,
66
+ getByText,
67
+ getByRole,
68
+ container,
69
+ history,
70
+ } = renderWithRouter ( workflowId , workflowName , type ) ;
69
71
70
72
expect ( getAllByText ( workflowName ) . length ) . toBeGreaterThan ( 0 ) ;
71
73
expect ( getAllByText ( 'Create an ingest pipeline' ) . length ) . toBeGreaterThan (
@@ -88,6 +90,86 @@ describe('WorkflowDetail', () => {
88
90
expect ( getByRole ( 'tab' , { name : 'Run queries' } ) ) . toBeInTheDocument ( ) ;
89
91
expect ( getByRole ( 'tab' , { name : 'Errors' } ) ) . toBeInTheDocument ( ) ;
90
92
expect ( getByRole ( 'tab' , { name : 'Resources' } ) ) . toBeInTheDocument ( ) ;
93
+
94
+ // "Run ingestion" button should be enabled by default
95
+ const runIngestionButton = getByRole ( 'button' , { name : 'Run ingestion' } ) ;
96
+ expect ( runIngestionButton ) . toBeInTheDocument ( ) ;
97
+ expect ( runIngestionButton ) . toBeEnabled ( ) ;
98
+
99
+ // "Search pipeline >" button should be disabled by default
100
+ const searchPipelineButton = getByRole ( 'button' , {
101
+ name : 'Search pipeline >' ,
102
+ } ) ;
103
+ expect ( searchPipelineButton ) . toBeInTheDocument ( ) ;
104
+ expect ( searchPipelineButton ) . toBeDisabled ( ) ;
105
+
106
+ // "Create an ingest pipeline" option should be selected by default
107
+ const createIngestRadio = getByRole ( 'radio' , {
108
+ name : / C r e a t e a n i n g e s t p i p e l i n e C o n f i g u r e a n d i n g e s t d a t a i n t o a n i n d e x ./ ,
109
+ } ) ;
110
+ expect ( createIngestRadio ) . toBeChecked ( ) ;
111
+
112
+ // "Skip ingestion pipeline" option should be disabled by default
113
+ const skipIngestRadio = getByRole ( 'radio' , {
114
+ name : / S k i p i n g e s t i o n p i p e l i n e U s e a n e x i s t i n g i n d e x w i t h d a t a i n g e s t e d ./ ,
115
+ } ) ;
116
+ expect ( skipIngestRadio ) . not . toBeChecked ( ) ;
117
+
118
+ // Clicking the "Export" button should open the export component
119
+ await waitFor ( ( ) =>
120
+ userEvent . click ( getByRole ( 'button' , { name : 'Export' } ) )
121
+ ) ;
122
+ expect ( getByText ( 'Export ' + workflowName ) ) . toBeInTheDocument ( ) ;
123
+ // Closing the "Export" opened above
124
+ await waitFor ( ( ) =>
125
+ userEvent . click ( getByRole ( 'button' , { name : 'Close' } ) )
126
+ ) ;
127
+
128
+ // Testing components in the ReactFlow workspace
129
+ const visualButton = getByRole ( 'button' , { name : 'Visual' } ) ;
130
+ expect ( visualButton ) . toBeVisible ( ) ;
131
+ expect ( visualButton ) . toHaveClass ( 'euiFilterButton-hasActiveFilters' ) ;
132
+ const jsonButton = getByRole ( 'button' , { name : 'JSON' } ) ;
133
+ expect ( jsonButton ) . toBeVisible ( ) ;
134
+ await waitFor ( ( ) => userEvent . click ( jsonButton ) ) ;
135
+ expect ( jsonButton ) . toHaveClass ( 'euiFilterButton-hasActiveFilters' ) ;
136
+
137
+ // Testing collapsible Tools panel
138
+ // Get the initial state of the Tools panel
139
+ const toolsPanelInitially = container . querySelector ( '#tools_panel_id' ) ;
140
+ expect ( toolsPanelInitially ) . toBeVisible ( ) ;
141
+ // Find and click the button to adjust panel sizes
142
+ const adjustPanelSizeButton = container . querySelector (
143
+ 'button[aria-label="Press up or down to adjust panels size"].euiResizableButton--vertical'
144
+ ) ;
145
+ expect ( adjustPanelSizeButton ) . toBeInTheDocument ( ) ;
146
+ await waitFor ( ( ) => userEvent . click ( adjustPanelSizeButton ! ) ) ;
147
+ // Find the toggle button for the Tools panel
148
+ const toggleButton = container . querySelector (
149
+ 'button[aria-label="Press to toggle this panel"].euiResizableToggleButton--vertical'
150
+ ) ;
151
+ expect ( toggleButton ) . toBeInTheDocument ( ) ;
152
+ expect ( toggleButton ) . toHaveClass ( 'euiResizableToggleButton-isVisible' ) ;
153
+ // Collapse the Tools panel
154
+ await waitFor ( ( ) => userEvent . click ( toggleButton ! ) ) ;
155
+ const toolsPanelAfterCollapse = container . querySelector (
156
+ '#tools_panel_id'
157
+ ) ! ;
158
+ expect ( toolsPanelAfterCollapse ) . toHaveClass (
159
+ 'euiResizablePanel-isCollapsed'
160
+ ) ;
161
+ // Expand the Tools panel
162
+ await waitFor ( ( ) => userEvent . click ( toggleButton ! ) ) ;
163
+ const toolsPanelAfterExpand = container . querySelector ( '#tools_panel_id' ) ! ;
164
+ expect ( toolsPanelAfterExpand ) . not . toHaveClass (
165
+ 'euiResizablePanel-isCollapsed'
166
+ ) ;
167
+
168
+ // Clicking the "close" button should go back to the list page
169
+ await waitFor ( ( ) =>
170
+ userEvent . click ( getByRole ( 'button' , { name : 'Close' } ) )
171
+ ) ;
172
+ expect ( history . location . pathname ) . toBe ( '/workflows' ) ;
91
173
} ) ;
92
174
} ) ;
93
175
} ) ;
0 commit comments