Skip to content

Commit 7d84a15

Browse files
committedSep 10, 2024
Improving and expanding functionality checks for the workflow_detail page
Signed-off-by: saimedhi <saimedhi@amazon.com>
1 parent 3e35af2 commit 7d84a15

File tree

3 files changed

+125
-36
lines changed

3 files changed

+125
-36
lines changed
 

‎package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"reactflow": "^11.8.3",
3434
"yup": "^1.3.2"
3535
},
36-
"devDependencies": {},
36+
"devDependencies": {
37+
"@testing-library/user-event": "^14.5.2"
38+
},
3739
"resolutions": {}
38-
}
40+
}

‎public/pages/workflow_detail/workflow_detail.test.tsx

+116-34
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
*/
55

66
import React from 'react';
7-
import { render } from '@testing-library/react';
7+
import { render, waitFor } from '@testing-library/react';
88
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';
1611
import { WorkflowDetail } from './workflow_detail';
1712
import { WorkflowDetailRouterProps } from '../../pages';
1813
import '@testing-library/jest-dom';
@@ -31,41 +26,48 @@ jest.mock('../../services', () => {
3126
const workflowId = '12345';
3227
const workflowName = 'test_workflow';
3328

34-
const history = createMemoryHistory({
35-
initialEntries: [`/workflow/${workflowId}`],
36-
});
37-
3829
window.ResizeObserver = resizeObserverMock;
3930

4031
const renderWithRouter = (
4132
workflowId: string,
4233
workflowName: string,
4334
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+
};
6060

6161
describe('WorkflowDetail', () => {
6262
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);
6971

7072
expect(getAllByText(workflowName).length).toBeGreaterThan(0);
7173
expect(getAllByText('Create an ingest pipeline').length).toBeGreaterThan(
@@ -88,6 +90,86 @@ describe('WorkflowDetail', () => {
8890
expect(getByRole('tab', { name: 'Run queries' })).toBeInTheDocument();
8991
expect(getByRole('tab', { name: 'Errors' })).toBeInTheDocument();
9092
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: /Create an ingest pipeline Configure and ingest data into an index./,
109+
});
110+
expect(createIngestRadio).toBeChecked();
111+
112+
// "Skip ingestion pipeline" option should be disabled by default
113+
const skipIngestRadio = getByRole('radio', {
114+
name: /Skip ingestion pipeline Use an existing index with data ingested./,
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');
91173
});
92174
});
93175
});

‎yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
classcat "^5.0.3"
6969
zustand "^4.4.1"
7070

71+
"@testing-library/user-event@^14.5.2":
72+
version "14.5.2"
73+
resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.5.2.tgz#db7257d727c891905947bd1c1a99da20e03c2ebd"
74+
integrity sha512-YAh82Wh4TIrxYLmfGcixwD18oIjyC1pFQC2Y01F2lzV2HTMiYrI0nze0FD0ocB//CKS/7jIUgae+adPqxK5yCQ==
75+
7176
"@types/d3-array@*":
7277
version "3.0.8"
7378
resolved "https://registry.yarnpkg.com/@types/d3-array/-/d3-array-3.0.8.tgz#a5d0687a12b48142c6f124d5e3796054e91bcea5"

0 commit comments

Comments
 (0)