-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathadminHelpers.ts
More file actions
226 lines (198 loc) · 7.19 KB
/
adminHelpers.ts
File metadata and controls
226 lines (198 loc) · 7.19 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
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
219
220
221
222
223
224
225
226
/**
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* adminHelpers.ts
* Contains reusable checks for the Administration button & menu.
*/
import {
verifyCardsHaveData,
verifyCloudscapeTableHasData,
verifyListHasData,
waitForContentToLoad,
} from './dataHelpers';
// Cloudscape TopNavigation selectors
// Use aria-label to target the specific Administration menu, not just any [role="menu"]
const ADMIN_MENU_SELECTOR = '[role="menu"][aria-label="Administration"]';
const MENU_ITEM_SELECTOR = '[role="menuitem"]';
// Core menu items that are always present for admin users
const EXPECTED_MENU_ITEMS = [
'API Token Management',
'Bedrock Agent Catalog',
'Configuration',
'MCP Management',
'MCP Workbench',
'Model Management',
'RAG Management',
];
/**
* Get the visible admin button with built-in retry.
* Cloudscape TopNavigation buttons have aria-label for accessibility.
*/
export function getAdminButton (): Cypress.Chainable {
// Use aria-label which is reliable in Cloudscape TopNavigation
return cy.get('header button[aria-label="Administration"]');
}
export function getLibraryButton (): Cypress.Chainable {
// Use aria-label which is reliable in Cloudscape TopNavigation
return cy.get('header button[aria-label="Libraries"]');
}
const LIBRARIES_MENU_SELECTOR = '[role="menu"][aria-label="Libraries"]';
/**
* Open the Libraries dropdown and click a menu item (e.g. Agentic Connections).
*/
export function navigateViaLibraries (menuItemName: string) {
getLibraryButton().should('be.visible').click().should('have.attr', 'aria-expanded', 'true');
cy.get(LIBRARIES_MENU_SELECTOR)
.should('be.visible')
.contains(MENU_ITEM_SELECTOR, menuItemName)
.filter(':visible')
.click();
}
/**
* Expand the admin menu and verify all items are present
*/
export function expandAdminMenu () {
// Wait for both Administration and Libraries buttons to be visible
// This prevents clicking Administration before the header is fully rendered
getLibraryButton().should('be.visible');
getAdminButton().should('be.visible');
getAdminButton()
.click()
.should('have.attr', 'aria-expanded', 'true');
// Wait for the Administration menu specifically (not Libraries or other menus)
cy.get(ADMIN_MENU_SELECTOR)
.should('be.visible')
.find(MENU_ITEM_SELECTOR)
.filter(':visible')
.should('have.length.at.least', EXPECTED_MENU_ITEMS.length)
.then(($items) => {
const labels = $items.map((_, el) => Cypress.$(el).text().trim()).get();
// Verify core items are present
EXPECTED_MENU_ITEMS.forEach((item) => {
expect(labels).to.include(item);
});
});
}
/**
* Collapse the admin menu
*/
export function collapseAdminMenu () {
getAdminButton()
.click()
.should('have.attr', 'aria-expanded', 'false');
cy.get(ADMIN_MENU_SELECTOR).should('not.be.visible');
}
/**
* Expand the admin menu for a RAG Admin user and verify only RAG Management is present.
* Admin-only items (Configuration, Model Management, etc.) should not appear.
*/
export function expandRagAdminMenu () {
getLibraryButton().should('be.visible');
getAdminButton().should('be.visible');
getAdminButton()
.click()
.should('have.attr', 'aria-expanded', 'true');
// Cloudscape may render multiple menu elements (collapsed/expanded views).
// Filter to visible only to avoid asserting on hidden duplicates.
const ADMIN_ONLY_ITEMS = [
'Bedrock Agent Catalog',
'Configuration',
'Model Management',
'API Token Management',
'MCP Management',
'MCP Workbench',
];
cy.get(ADMIN_MENU_SELECTOR, { timeout: 10000 })
.filter(':visible')
.should('have.length', 1)
.within(() => {
cy.get(MENU_ITEM_SELECTOR).filter(':visible').should('have.length', 1);
cy.contains(MENU_ITEM_SELECTOR, 'RAG Management').should('be.visible');
ADMIN_ONLY_ITEMS.forEach((item) => {
cy.contains(MENU_ITEM_SELECTOR, item).should('not.exist');
});
});
}
export function checkNoAdminButton () {
// Use the specific selector for the Administration button
cy.get('header button[aria-label="Administration"]').should('not.exist');
}
/**
* Navigate to a specific admin page by menu item name
* @param menuItemName - The exact text of the menu item to click
*/
export function navigateToAdminPage (menuItemName: string) {
// First expand the menu using the same pattern as expandAdminMenu
expandAdminMenu();
// Then click the specific menu item
cy.contains(MENU_ITEM_SELECTOR, menuItemName)
.filter(':visible')
.click();
}
/**
* Verify that an admin page has loaded correctly
* @param urlFragment - The expected URL fragment (e.g., '/admin/configuration')
* @param pageTitle - Optional expected page title text
*/
export function verifyAdminPageLoaded (urlFragment: string, pageTitle?: string) {
cy.url().should('include', urlFragment);
waitForContentToLoad();
if (pageTitle) {
cy.get('h1, h2, [data-testid="page-title"]')
.should('be.visible')
.and('contain.text', pageTitle);
} else {
cy.get('h1, h2, [data-testid="page-title"], main, [role="main"]')
.should('be.visible');
}
}
/**
* Combined helper to navigate to admin page and verify it has rendered with data
* @param menuItemName - The menu item to click
* @param urlFragment - Expected URL fragment
* @param pageTitle - Expected page title
* @param contentType - Type of content to verify ('table', 'cards', 'list', or 'custom')
* @param minItems - Minimum number of items expected
*/
export function navigateAndVerifyAdminPage (
menuItemName: string,
urlFragment: string,
pageTitle?: string,
contentType: 'table' | 'cards' | 'list' | 'custom' = 'table',
minItems: number = 1
) {
navigateToAdminPage(menuItemName);
verifyAdminPageLoaded(urlFragment, pageTitle);
switch (contentType) {
case 'table':
verifyCloudscapeTableHasData(minItems);
break;
case 'cards':
verifyCardsHaveData(minItems);
break;
case 'list':
verifyListHasData(minItems);
break;
case 'custom':
// For custom verification, just ensure page loaded
break;
}
}
// Re-export data helpers for backward compatibility
export {
verifyTableHasData,
verifyCloudscapeTableHasData,
verifyCardsHaveData,
verifyListHasData,
waitForContentToLoad,
} from './dataHelpers';