Skip to content

Commit 829aa03

Browse files
saimedhigithub-actions[bot]
authored andcommitted
Expanded unit test coverage for key UI components (#395)
* Expanded test coverage for key UI components Signed-off-by: saimedhi <saimedhi@amazon.com> * Expanded test coverage for key UI components Signed-off-by: saimedhi <saimedhi@amazon.com> --------- Signed-off-by: saimedhi <saimedhi@amazon.com> (cherry picked from commit 95049f7)
1 parent 3447d9a commit 829aa03

File tree

8 files changed

+170
-46
lines changed

8 files changed

+170
-46
lines changed

public/pages/workflow_detail/workflow_detail.test.tsx

+104-21
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ describe('WorkflowDetail Page with create ingestion option', () => {
7474
getAllByText,
7575
getByText,
7676
getByRole,
77-
container,
7877
getByTestId,
7978
} = renderWithRouter(workflowId, workflowName, type);
8079

@@ -109,14 +108,6 @@ describe('WorkflowDetail Page with create ingestion option', () => {
109108
const searchPipelineButton = getByTestId('searchPipelineButton');
110109
expect(searchPipelineButton).toBeInTheDocument();
111110
expect(searchPipelineButton).toBeDisabled();
112-
113-
// "Create an ingest pipeline" option should be selected by default
114-
const createIngestRadio = container.querySelector('#create');
115-
expect(createIngestRadio).toBeChecked();
116-
117-
// "Skip ingestion pipeline" option should be unselected by default
118-
const skipIngestRadio = container.querySelector('#skip');
119-
expect(skipIngestRadio).not.toBeChecked();
120111
});
121112
});
122113
});
@@ -133,37 +124,49 @@ describe('WorkflowDetail Page Functionality (Custom Workflow)', () => {
133124
);
134125

135126
// Export button opens the export component
136-
await waitFor(() => userEvent.click(getByTestId('exportButton')));
137-
expect(getByText(`Export ${workflowName}`)).toBeInTheDocument();
127+
userEvent.click(getByTestId('exportButton'));
128+
await waitFor(() => {
129+
expect(getByText(`Export ${workflowName}`)).toBeInTheDocument();
130+
});
138131

139132
// Close the export component
140-
await waitFor(() => userEvent.click(getByTestId('exportCloseButton')));
133+
userEvent.click(getByTestId('exportCloseButton'));
141134

142135
// Check workspace buttons (Visual and JSON)
143136
const visualButton = getByTestId('workspaceVisualButton');
144-
expect(visualButton).toBeVisible();
137+
await waitFor(() => {
138+
expect(visualButton).toBeVisible();
139+
});
145140
expect(visualButton).toHaveClass('euiFilterButton-hasActiveFilters');
146141
const jsonButton = getByTestId('workspaceJSONButton');
147142
expect(jsonButton).toBeVisible();
148-
await waitFor(() => userEvent.click(jsonButton));
149-
expect(jsonButton).toHaveClass('euiFilterButton-hasActiveFilters');
143+
userEvent.click(jsonButton);
144+
await waitFor(() => {
145+
expect(jsonButton).toHaveClass('euiFilterButton-hasActiveFilters');
146+
});
150147

151148
// Tools panel should collapse and expand on toggle
152149
const toolsPanel = container.querySelector('#tools_panel_id');
153150
expect(toolsPanel).toBeVisible();
154151

155152
const toggleButton = toolsPanel?.querySelector('button[type="button"]');
156153
expect(toggleButton).toBeInTheDocument();
157-
await waitFor(() => userEvent.click(toggleButton!));
154+
userEvent.click(toggleButton!);
158155

159156
// Tools panel after collapsing
160157
const collapsedToolsPanel = container.querySelector('#tools_panel_id');
161-
expect(collapsedToolsPanel).toHaveClass('euiResizablePanel-isCollapsed');
158+
await waitFor(() => {
159+
expect(collapsedToolsPanel).toHaveClass('euiResizablePanel-isCollapsed');
160+
});
162161

163162
// Tools panel after expanding
164-
await waitFor(() => userEvent.click(toggleButton!));
163+
userEvent.click(toggleButton!);
165164
const expandedToolsPanel = container.querySelector('#tools_panel_id');
166-
expect(expandedToolsPanel).not.toHaveClass('euiResizablePanel-isCollapsed');
165+
await waitFor(() => {
166+
expect(expandedToolsPanel).not.toHaveClass(
167+
'euiResizablePanel-isCollapsed'
168+
);
169+
});
167170
});
168171

169172
test('tests navigation to workflows list on Close button click', async () => {
@@ -174,7 +177,87 @@ describe('WorkflowDetail Page Functionality (Custom Workflow)', () => {
174177
);
175178

176179
// The WorkflowDetail Page Close button should navigate back to the workflows list
177-
await waitFor(() => userEvent.click(getByTestId('closeButton')));
178-
expect(history.location.pathname).toBe('/workflows');
180+
userEvent.click(getByTestId('closeButton'));
181+
await waitFor(() => {
182+
expect(history.location.pathname).toBe('/workflows');
183+
});
184+
});
185+
});
186+
187+
describe('WorkflowDetail Page with skip ingestion option (Hybrid Search Workflow)', () => {
188+
beforeEach(() => {
189+
jest.clearAllMocks();
190+
});
191+
test(`renders the WorkflowDetail page with skip ingestion option`, async () => {
192+
const {
193+
container,
194+
getByTestId,
195+
getAllByText,
196+
getAllByTestId,
197+
} = renderWithRouter(workflowId, workflowName, WORKFLOW_TYPE.HYBRID_SEARCH);
198+
199+
// "Create an ingest pipeline" option should be selected by default
200+
const createIngestRadio = container.querySelector('#create');
201+
expect(createIngestRadio).toBeChecked();
202+
203+
// "Skip ingestion pipeline" option should be unselected by default
204+
const skipIngestRadio = container.querySelector('#skip');
205+
expect(skipIngestRadio).not.toBeChecked();
206+
207+
// Selected "Skip ingestion pipeline"
208+
userEvent.click(skipIngestRadio!);
209+
await waitFor(() => {
210+
expect(createIngestRadio).not.toBeChecked();
211+
});
212+
expect(skipIngestRadio).toBeChecked();
213+
const searchPipelineButton = getByTestId('searchPipelineButton');
214+
userEvent.click(searchPipelineButton);
215+
216+
// Search pipeline
217+
await waitFor(() => {
218+
expect(getAllByText('Define search pipeline').length).toBeGreaterThan(0);
219+
});
220+
expect(getAllByText('Configure query').length).toBeGreaterThan(0);
221+
const searchTestButton = getByTestId('searchTestButton');
222+
expect(searchTestButton).toBeInTheDocument();
223+
224+
// Edit Search Query
225+
const queryEditButton = getByTestId('queryEditButton');
226+
expect(queryEditButton).toBeInTheDocument();
227+
userEvent.click(queryEditButton);
228+
await waitFor(() => {
229+
expect(getAllByText('Edit query').length).toBeGreaterThan(0);
230+
});
231+
const searchQueryPresetButton = getByTestId('searchQueryPresetButton');
232+
expect(searchQueryPresetButton).toBeInTheDocument();
233+
const searchQueryCloseButton = getByTestId('searchQueryCloseButton');
234+
expect(searchQueryCloseButton).toBeInTheDocument();
235+
userEvent.click(searchQueryCloseButton);
236+
237+
// Add request processor
238+
const addRequestProcessorButton = await waitFor(
239+
() => getAllByTestId('addProcessorButton')[0]
240+
);
241+
userEvent.click(addRequestProcessorButton);
242+
await waitFor(() => {
243+
expect(getAllByText('Processors').length).toBeGreaterThan(0);
244+
});
245+
246+
// Add response processor
247+
const addResponseProcessorButton = getAllByTestId('addProcessorButton')[1];
248+
userEvent.click(addResponseProcessorButton);
249+
await waitFor(() => {
250+
expect(getAllByText('Processors').length).toBeGreaterThan(0);
251+
});
252+
253+
// Save, Build and Run query, Back buttons
254+
expect(getByTestId('saveSearchPipelineButton')).toBeInTheDocument();
255+
expect(getByTestId('runQueryButton')).toBeInTheDocument();
256+
const searchPipelineBackButton = getByTestId('searchPipelineBackButton');
257+
userEvent.click(searchPipelineBackButton);
258+
259+
await waitFor(() => {
260+
expect(skipIngestRadio).toBeChecked();
261+
});
179262
});
180263
});

public/pages/workflow_detail/workflow_inputs/processors_list.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export function ProcessorsList(props: ProcessorsListProps) {
191191
onClick={() => {
192192
setPopover(!isPopoverOpen);
193193
}}
194+
data-testid="addProcessorButton"
194195
>
195196
{processors.length > 0
196197
? 'Add another processor'

public/pages/workflow_detail/workflow_inputs/search_inputs/configure_search_request.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
120120
fill={false}
121121
style={{ width: '100px' }}
122122
onClick={() => setIsEditModalOpen(true)}
123+
data-testid="queryEditButton"
123124
>
124125
Edit
125126
</EuiSmallButton>
@@ -163,6 +164,7 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
163164
console.error('Error running query: ', error);
164165
});
165166
}}
167+
data-testid="searchTestButton"
166168
>
167169
Test
168170
</EuiSmallButton>

public/pages/workflow_detail/workflow_inputs/search_inputs/edit_query_modal.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export function EditQueryModal(props: EditQueryModalProps) {
5454
<EuiModalBody>
5555
<EuiPopover
5656
button={
57-
<EuiSmallButton onClick={() => setPopoverOpen(!popoverOpen)}>
57+
<EuiSmallButton
58+
onClick={() => setPopoverOpen(!popoverOpen)}
59+
data-testid="searchQueryPresetButton"
60+
>
5861
Choose from a preset
5962
</EuiSmallButton>
6063
}
@@ -90,6 +93,7 @@ export function EditQueryModal(props: EditQueryModalProps) {
9093
<EuiModalFooter>
9194
<EuiSmallButton
9295
onClick={() => props.setModalOpen(false)}
96+
data-testid="searchQueryCloseButton"
9397
fill={false}
9498
color="primary"
9599
>

public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
876876
<EuiSmallButtonEmpty
877877
disabled={searchBackButtonDisabled}
878878
onClick={() => setSelectedStep(STEP.INGEST)}
879+
data-testid="searchPipelineBackButton"
879880
>
880881
Back
881882
</EuiSmallButtonEmpty>
@@ -897,6 +898,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
897898
onClick={() => {
898899
updateWorkflowUiConfig();
899900
}}
901+
data-testid="saveSearchPipelineButton"
900902
>
901903
{`Save`}
902904
</EuiSmallButtonEmpty>
@@ -909,6 +911,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
909911
onClick={() => {
910912
validateAndRunQuery();
911913
}}
914+
data-testid="runQueryButton"
912915
>
913916
Build and run query
914917
</EuiSmallButton>

public/pages/workflows/new_workflow/new_workflow.test.tsx

+17-6
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ describe('NewWorkflow', () => {
7373
// Click the first "Go" button on the templates and test Quick Configure.
7474
const goButtons = getAllByTestId('goButton');
7575
userEvent.click(goButtons[0]);
76-
await waitFor(() =>
77-
expect(getAllByText('Quick configure')).toHaveLength(1)
78-
);
76+
await waitFor(() => {
77+
expect(getAllByText('Quick configure')).toHaveLength(1);
78+
});
7979

8080
// Verify that the create button is present in the Quick Configure pop-up.
8181
expect(getByTestId('quickConfigureCreateButton')).toBeInTheDocument();
@@ -87,8 +87,19 @@ describe('NewWorkflow', () => {
8787
userEvent.click(quickConfigureCancelButton);
8888

8989
// Ensure the quick configure pop-up is closed after canceling.
90-
await waitFor(() =>
91-
expect(queryByText('quickConfigureCreateButton')).toBeNull()
92-
);
90+
await waitFor(() => {
91+
expect(queryByText('quickConfigureCreateButton')).toBeNull();
92+
});
93+
});
94+
95+
test('search functionality ', async () => {
96+
const { getByText, getByPlaceholderText, queryByText } = renderWithRouter();
97+
98+
// Search by Template Name
99+
userEvent.type(getByPlaceholderText('Search'), 'hybrid');
100+
await waitFor(() => {
101+
expect(getByText('Hybrid Search')).toBeInTheDocument();
102+
expect(queryByText('Multimodal Search')).toBeNull();
103+
});
93104
});
94105
});

public/pages/workflows/workflow_list/workflow_list.test.tsx

+22-8
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,30 @@ describe('WorkflowList', () => {
8080
userEvent.click(sortButtons[0]!);
8181
await waitFor(() => {
8282
expect(queryByText('workflow_name_19')).toBeInTheDocument();
83-
expect(queryByText('workflow_name_0')).toBeNull();
8483
});
84+
expect(queryByText('workflow_name_0')).toBeNull();
85+
8586
userEvent.click(sortButtons[0]!);
8687
await waitFor(() => {
8788
expect(queryByText('workflow_name_0')).toBeInTheDocument();
88-
expect(queryByText('workflow_name_9')).toBeInTheDocument();
89-
expect(queryByText('workflow_name_10')).toBeNull();
90-
expect(queryByText('workflow_name_19')).toBeNull();
9189
});
90+
expect(queryByText('workflow_name_9')).toBeInTheDocument();
91+
expect(queryByText('workflow_name_10')).toBeNull();
92+
expect(queryByText('workflow_name_19')).toBeNull();
9293

9394
// Sort workflows list by Type
9495
expect(sortButtons[1]).toBeInTheDocument();
9596
userEvent.click(sortButtons[1]!);
9697
await waitFor(() => {
9798
expect(getAllByText('Custom').length).toBeGreaterThan(0);
98-
expect(queryByText('Unknown')).toBeNull();
9999
});
100+
expect(queryByText('Unknown')).toBeNull();
101+
100102
userEvent.click(sortButtons[1]!);
101103
await waitFor(() => {
102104
expect(queryByText('Unknown')).toBeNull();
103-
expect(getAllByText('Custom').length).toBeGreaterThan(0);
104105
});
106+
expect(getAllByText('Custom').length).toBeGreaterThan(0);
105107
});
106108

107109
test('pagination functionality', async () => {
@@ -124,8 +126,8 @@ describe('WorkflowList', () => {
124126
userEvent.click(nextButton);
125127
await waitFor(() => {
126128
expect(getByText('workflow_name_19')).toBeInTheDocument();
127-
expect(queryByText('workflow_name_0')).toBeNull();
128129
});
130+
expect(queryByText('workflow_name_0')).toBeNull();
129131

130132
// Navigate to previous page
131133
const previousButton = container.querySelector(
@@ -134,8 +136,8 @@ describe('WorkflowList', () => {
134136
userEvent.click(previousButton);
135137
await waitFor(() => {
136138
expect(getByText('workflow_name_0')).toBeInTheDocument();
137-
expect(queryByText('workflow_name_19')).toBeNull();
138139
});
140+
expect(queryByText('workflow_name_19')).toBeNull();
139141
});
140142

141143
test('delete action functionality', async () => {
@@ -161,4 +163,16 @@ describe('WorkflowList', () => {
161163
expect(getByText('No existing resources found')).toBeInTheDocument();
162164
});
163165
});
166+
167+
test('search functionality ', async () => {
168+
const { getByText, getByPlaceholderText, queryByText } = renderWithRouter();
169+
170+
// Search by Name
171+
userEvent.type(getByPlaceholderText('Search'), 'name_18');
172+
await waitFor(() => {
173+
expect(getByText('workflow_name_18')).toBeInTheDocument();
174+
});
175+
expect(queryByText('workflow_name_19')).toBeNull();
176+
expect(queryByText('workflow_name_0')).toBeNull();
177+
});
164178
});

public/pages/workflows/workflows.test.tsx

+16-10
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,30 @@ describe('Workflows', () => {
5454
// Import Workflow Testing
5555
expect(getAllByText('Workflows').length).toBeGreaterThan(0);
5656
const importWorkflowButton = getByTestId('importWorkflowButton');
57-
await waitFor(() => userEvent.click(importWorkflowButton));
58-
expect(
59-
getAllByText('Select or drag and drop a file').length
60-
).toBeGreaterThan(0);
57+
userEvent.click(importWorkflowButton);
58+
await waitFor(() => {
59+
expect(
60+
getAllByText('Select or drag and drop a file').length
61+
).toBeGreaterThan(0);
62+
});
6163

6264
// Closing or canceling the import
6365
const cancelImportButton = getByTestId('cancelImportButton');
64-
await waitFor(() => userEvent.click(cancelImportButton));
65-
expect(
66-
queryByText('Select or drag and drop a file')
67-
).not.toBeInTheDocument();
66+
userEvent.click(cancelImportButton);
67+
await waitFor(() => {
68+
expect(
69+
queryByText('Select or drag and drop a file')
70+
).not.toBeInTheDocument();
71+
});
6872
expect(getAllByText('Manage existing workflows').length).toBeGreaterThan(0);
6973

7074
// When the "Create Workflow" button is clicked, the "New workflow" tab opens
7175
// Create Workflow Testing
7276
const createWorkflowButton = getByTestId('createWorkflowButton');
7377
expect(createWorkflowButton).toBeInTheDocument();
74-
await waitFor(() => userEvent.click(createWorkflowButton));
75-
expect(getAllByText('Create from a template').length).toBeGreaterThan(0);
78+
userEvent.click(createWorkflowButton);
79+
await waitFor(() => {
80+
expect(getAllByText('Create from a template').length).toBeGreaterThan(0);
81+
});
7682
});
7783
});

0 commit comments

Comments
 (0)