-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathcommon-setup.js
More file actions
173 lines (160 loc) · 4.58 KB
/
Copy pathcommon-setup.js
File metadata and controls
173 lines (160 loc) · 4.58 KB
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
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
// Common setup functions for search relevance tests
/**
* Enable the search relevance workbench UI toggle
*/
export const enableWorkbenchUI = () => {
// enable backend feature flag
cy.enableSearchRelevanceWorkbench();
// Visit the base URL first to ensure we're logged in
cy.visit(Cypress.config().baseUrl, { timeout: 20000 });
cy.wait(2000);
// Visit the settings page with retry logic
cy.visit('app/management/opensearch-dashboards/settings', { timeout: 20000 });
cy.wait(3000); // Wait for page to stabilize
// Check current state of the toggle with increased timeout
cy.get(
'button[role="switch"][data-test-subj="advancedSetting-editField-search-relevance:experimental_workbench_ui_enabled"]',
{ timeout: 60000 }
).then(($button) => {
const isEnabled = $button.attr('aria-checked') === 'true';
// Only click if not already enabled
if (!isEnabled) {
cy.wrap($button).click({ force: true });
cy.wait(1000); // Wait for UI to update
cy.get('[data-test-subj="advancedSetting-saveButton"]', {
timeout: 10000,
}).click({
force: true,
});
cy.wait(5000); // Wait for save to complete
}
});
// Navigate back to home to ensure settings are applied
cy.visit(Cypress.config().baseUrl, { timeout: 10000 });
cy.wait(2000);
};
/**
* Initialize UBI indices required for tests
*/
export const initializeUbiIndices = () => {
// Delete and recreate ubi_queries index
cy.deleteIndex('ubi_queries');
// Create ubi_queries index with proper mapping
cy.createIndex('ubi_queries', null, {
mappings: {
properties: {
user_query: {
type: 'keyword',
},
application: {
type: 'keyword',
},
query_id: {
type: 'keyword',
},
client_id: {
type: 'keyword',
},
query_attributes: {
type: 'object',
},
timestamp: {
type: 'date',
},
},
},
});
// Add a sample document to ubi_queries
cy.insertDocumentToIndex('ubi_queries', undefined, {
application: 'esci_ubi_sample',
query_id: '33198ee9-5912-453c-9173-3f92fd3cb1be',
client_id: '127c9afc-01c9-4084-912f-f318569f96c7',
user_query: 'futon frames full size without mattress',
query_attributes: {},
timestamp: '2024-12-10T00:01:29.378Z',
});
// Delete and recreate ubi_events index
cy.deleteIndex('ubi_events');
// Create ubi_events index with proper mapping
cy.createIndex('ubi_events', null, {
mappings: {
properties: {
application: {
type: 'keyword',
},
action_name: {
type: 'keyword',
},
query_id: {
type: 'keyword',
},
session_id: {
type: 'keyword',
},
client_id: {
type: 'keyword',
},
timestamp: {
type: 'date',
},
user_query: {
type: 'keyword',
},
message_type: {
type: 'keyword',
},
message: {
type: 'text',
},
event_attributes: {
type: 'object',
},
},
},
});
// Add a sample document to ubi_events
cy.insertDocumentToIndex('ubi_events', undefined, {
application: 'esci_ubi_sample',
action_name: 'impression',
query_id: '33198ee9-5912-453c-9173-3f92fd3cb1be',
session_id: '94cb50fb-c3af-4a69-91d9-cdd9e86d6297',
client_id: '127c9afc-01c9-4084-912f-f318569f96c7',
timestamp: '2024-12-10T00:01:29.378Z',
user_query: 'futon frames full size without mattress',
message_type: null,
message: null,
event_attributes: {
object: {
object_id: 'B07CVR21VN',
object_id_field: 'asin',
},
position: {
ordinal: 0,
},
},
});
};
/**
* Prepare sample_index for search configurations
*/
export const prepareSampleIndex = () => {
cy.insertDocumentToIndex('00sample_index', undefined, {
name: 'bafuton frames full size without mattressnana 00',
price: 1999,
description: 'this is futon frames full size without mattress 00',
});
cy.insertDocumentToIndex('00sample_index', undefined, {
name: 'bafuton frames full size without mattressnana 01',
price: 1999,
description: 'this is futon frames full size without mattress 01',
});
cy.insertDocumentToIndex('00sample_index', undefined, {
name: 'bafuton frames full size without mattressnana 02',
price: 1999,
description: 'this is futon frames full size without mattress 02',
});
};