-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_workflow_spec.js
218 lines (206 loc) · 7.21 KB
/
create_workflow_spec.js
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
218
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import {
FF_URL,
FF_FIXTURE_BASE_PATH,
WORKFLOW_DETAIL_URL_SEGMENT,
FF_TIMEOUT,
} from '../../../utils/constants';
import createConnectorBody from '../../../fixtures/plugins/dashboards-flow-framework/create_connector.json';
import registerModelBody from '../../../fixtures/plugins/dashboards-flow-framework/register_model.json';
import { CURRENT_TENANT } from '../../../utils/commands';
describe('Creating Workflows Using Various Methods', () => {
var modelId = '';
before(() => {
CURRENT_TENANT.newTenant = 'global';
cy.createConnector(createConnectorBody)
.then((connectorResponse) => {
return cy.registerModel({
body: {
...registerModelBody,
connector_id: connectorResponse.connector_id,
function_name: 'remote',
},
});
})
.then((modelResponse) => {
modelId = modelResponse.model_id;
return cy.deployModel(modelId);
});
});
beforeEach(() => {
CURRENT_TENANT.newTenant = 'global';
cy.wait(20000);
cy.visit(FF_URL.WORKFLOWS, { timeout: FF_TIMEOUT });
});
it('Import workflow with valid configuration', () => {
CURRENT_TENANT.newTenant = 'global';
cy.wait(20000);
cy.getElementByDataTestId('importWorkflowButton', { timeout: FF_TIMEOUT })
.should('be.visible')
.click({ force: true });
cy.contains('Import a workflow (JSON/YAML)').should('be.visible');
const filePath =
'cypress/fixtures/' +
FF_FIXTURE_BASE_PATH +
'semantic_search/import_workflow.json';
cy.get('input[type=file]').selectFile(filePath);
cy.getElementByDataTestId('importJSONButton').should('be.visible').click();
cy.get('.euiFieldSearch').should('be.visible').focus();
cy.wait(1000);
cy.get('.euiFieldSearch')
.should('be.visible')
.type('semantic_search_1{enter}');
cy.contains('semantic_search_1');
cy.get('.euiTableRow').should('have.length.greaterThan', 0);
cy.get('.euiTableRow').first().find('button.euiButtonIcon--danger').click();
cy.contains('The workflow will be permanently deleted.').should('exist');
cy.getElementByDataTestId('deleteWorkflowButton')
.should('be.visible')
.click();
});
it('Attempt to import workflow with invalid configuration', () => {
cy.getElementByDataTestId('importWorkflowButton', { timeout: FF_TIMEOUT })
.should('be.visible')
.click();
cy.contains('Import a workflow (JSON/YAML)').should('be.visible');
const filePath =
'cypress/fixtures/' +
FF_FIXTURE_BASE_PATH +
'semantic_search/search_query.json';
cy.get('input[type=file]').selectFile(filePath);
cy.contains('The uploaded file is not a valid workflow').should(
'be.visible'
);
});
it('Create workflow using semantic search template', () => {
cy.getElementByDataTestId('createWorkflowButton', { timeout: FF_TIMEOUT })
.should('be.visible')
.click();
cy.contains('h3', 'Semantic Search', { timeout: FF_TIMEOUT })
.should('be.visible')
.parents('.euiCard')
.within(() => {
cy.contains('button', 'Create').click();
});
cy.contains('label', 'Name')
.invoke('attr', 'for')
.then((id) => {
cy.get(`#${id}`).clear().type('semantic_search');
});
cy.getElementByDataTestId('optionalConfigurationButton', {
timeout: FF_TIMEOUT,
})
.should('be.visible')
.click();
cy.getElementByDataTestId('selectDeployedModel')
.should('be.visible')
.click();
cy.get('.euiSuperSelect__item').contains('BedRock').click();
cy.contains('label', 'Text field')
.invoke('attr', 'for')
.then((id) => {
cy.get(`#${id}`).clear().type('item_text');
});
cy.getElementByDataTestId('quickConfigureCreateButton')
.should('be.visible')
.click();
cy.url().should('include', '/workflows/');
cy.getElementByDataTestId('selectDataToImportButton')
.should('be.visible')
.click();
cy.get(`[data-text="Upload a file"]`).should('be.visible').click();
const filePath = `cypress/fixtures/${FF_FIXTURE_BASE_PATH}semantic_search/source_data.jsonl`;
cy.get('input[type=file]').selectFile(filePath);
cy.getElementByDataTestId('updateSourceDataButton')
.should('be.visible')
.click();
cy.mockAllIngestActions(() => {
cy.getElementByTestId('updateAndRunIngestButton')
.should('be.visible')
.click();
});
// Checking Run ingestion response
cy.sa_getElementByText('button.euiTab', 'Ingest response')
.should('be.visible')
.click();
cy.fixture(FF_FIXTURE_BASE_PATH + 'semantic_search/ingest_response').then(
() => {
cy.get('#tools_panel_id').should('be.visible');
}
);
cy.getElementByDataTestId('searchPipelineButton')
.should('be.visible')
.click();
cy.getElementByDataTestId('queryEditButton').should('be.visible').click();
cy.get('[data-testid="editQueryModalBody"]').within(() => {
cy.fixture(
FF_FIXTURE_BASE_PATH + 'semantic_search/search_query.json'
).then((jsonData) => {
const jsonString = JSON.stringify(jsonData);
cy.get('.ace_text-input')
.focus()
.clear({ force: true })
.focus()
.wait(2000)
.type(jsonString, {
force: true,
parseSpecialCharSequences: false,
delay: 5,
})
.trigger('blur', { force: true });
});
});
cy.getElementByDataTestId('updateSearchQueryButton')
.should('be.visible')
.click();
cy.getElementByTestId('updateSearchButton').should('be.visible').click();
// TODO: further search response validation can be completed when the UI is finalized in how it is displayed.
});
it('Create workflow from hybrid search template', () => {
createPreset('Hybrid Search', true);
});
it('Create workflow from multimodal template', () => {
createPreset('Multimodal Search', true);
});
it('Create workflow from custom template', () => {
createPreset('Custom Search', false);
});
after(() => {
if (modelId != '') {
cy.undeployMLCommonsModel(modelId);
cy.deleteMLCommonsModel(modelId);
}
});
});
// Reusable fn to check the preset exists, and able to create it, and navigate to its details page.
function createPreset(presetName, containsModels = false) {
cy.getElementByDataTestId('createWorkflowButton', { timeout: FF_TIMEOUT })
.should('be.visible')
.click();
cy.contains('h3', presetName, { timeout: FF_TIMEOUT })
.should('be.visible')
.parents('.euiCard')
.within(() => {
cy.contains('button', 'Create').click();
});
cy.contains('label', 'Name')
.invoke('attr', 'for')
.then((id) => {
cy.get(`#${id}`)
.clear()
.type(presetName.toLowerCase().replace(/\s/g, ''));
});
if (containsModels) {
cy.getElementByDataTestId('selectDeployedModel')
.should('be.visible')
.click();
cy.get('.euiSuperSelect__item').contains('BedRock').click();
}
cy.getElementByDataTestId('quickConfigureCreateButton')
.should('be.visible')
.click();
cy.url().should('include', WORKFLOW_DETAIL_URL_SEGMENT);
}