Commit 38b4d17
authored
Cursor Mock Rule Creation & GenAI Mock Test Creation (using rules) (opendatahub-io#5541)
* feat(testing): Add comprehensive Cypress mock test rules - RHOAIENG-34223
Created detailed Cursor rules for mock test creation:
- cypress-mock.mdc (995 lines): Comprehensive guidelines for creating
and maintaining Cypress mock tests with fully mocked backends
- MOCK_TEST_RULES_SUMMARY.md: Quick reference guide for developers
- Minor update to cypress-e2e.mdc globs config
Key features of mock test rules:
- Test structure and organization patterns (describe/beforeEach/it)
- Backend mocking with interceptors (cy.interceptOdh, cy.interceptK8sList)
- Mandatory use of page objects (no direct cy.findByTestId in tests)
- Mock data management (always use __mocks__ folder)
- Common test patterns (tables, modals, forms, drag-drop, routing)
- Access control and feature flag testing
- Code quality and linting requirements
- Test execution and debugging guidelines
- Complete implementation checklists
Addresses acceptance criteria for RHOAIENG-34223:
- ✅ Draft markdown-formatted Cursor rule for Mock Test Generation
- ✅ Include intelligent patterns for API endpoint mocking
- ⏳ Review with team and incorporate feedback (next step)
- ⏳ Test rules with real codebase examples (next step)
* chore: simplify workflow name to 'Cypress e2e Test'
* Add Cypress mock test rules and groupSettings mock tests
- Add comprehensive Cypress mock test rules document (.cursor/rules/cypress-mock.mdc)
- Create groupSettings page object with test selectors
- Implement 15 mock tests for groupSettings page covering:
- Page display and navigation
- Admin and user group selection
- Save functionality and validation
- Error handling (save errors, loading errors)
- New group creation
- Loading states
Related to RHOAIENG-34223
* Update Cypress mock test rules with learnings from existing tests
- Add Contextual pattern for reusable page object sections
- Add appChrome usage for navigation items
- Add proper wait validation with specific text checks
- Add success/error validation with semantic HTML roles
- Add scope management with .document() for portaled content
- Add test structure best practices (focus on flows, not micro-tests)
- Add minimal mocking principle
- Add proper payload validation patterns
- Emphasize reviewing existing tests before creating new ones
These learnings come from comparing duplicate groupSettings tests with
existing userManagement tests and identifying best practices.
* Remove duplicate groupSettings tests
The groupSettings page is already tested by userManagement.cy.ts since
both test the same GroupSettings component at /settings/user-management.
The duplicate tests were created without checking for existing coverage.
Removed:
- frontend/src/__tests__/cypress/cypress/tests/mocked/groupSettings/groupSettings.cy.ts
- frontend/src/__tests__/cypress/cypress/pages/groupSettings.ts
* feat(gen-ai): Add comprehensive mock tests for AI Playground chatbot
- Add Cypress mock test rules with strict testID requirements
- Create chatbot mock tests covering UI interactions, configuration, and messaging
- Add data-testid attributes to chatbot components for robust test selectors
- Update page objects to use testIDs instead of brittle selectors
- Add rule: never add timeouts to page objects, only in tests
- Enhance mcpServersTestHelpers to support custom namespaces
Components updated with testIDs:
- ChatbotHeaderActions: view-code-button, kebab-menu-toggle, menu items
- ChatbotSettingsPanel: rag-section, mcp-servers-section, system-instructions
- ModelParameterFormGroup: temperature-input
- SystemInstructionFormGroup: system-instructions-input
- NoData: empty-state-action-button
Tests cover:
- Page load and message input verification
- Model configuration (temperature, streaming, system instructions)
- MCP servers panel visibility
- Header actions (view code, kebab menu, delete)
- Message sending and bot response verification
All 8 tests passing ✅
* fix(gen-ai): Fix chatbot mock tests CI failures
- Fix ReDoS vulnerability in chatbotPage.ts by removing dynamic RegExp
- Create cypress:server:bff-mock script to run BFF with all mock clients
- Update test:cypress-ci to run BFF + frontend + Cypress tests concurrently
This fixes the CI failures where chatbot.cy.ts tests were failing because
they expected a running BFF with mock data, but CI was only running the
frontend dev server. Now both BFF (with mocks) and frontend run during tests.
All 17 mock tests now pass (ci-smoke, mcpServers, chatbot).
* ci(gen-ai): Add Go setup and BFF support to frontend CI workflow
- Add Go setup step to install Go for running the BFF
- Configure Go version from bff/go.mod with caching
This enables the BFF to run in mock mode during frontend tests.
* fix: Add data-testid to disabled View Code button
The View Code button's data-testid was only on the enabled state,
causing the test to fail when the button is disabled (default state
when no message has been sent). Added data-testid to both states.1 parent 2b7f69f commit 38b4d17
12 files changed
Lines changed: 2459 additions & 11 deletions
File tree
- .cursor/rules
- .github/workflows
- packages/gen-ai/frontend
- src
- __tests__/cypress/cypress
- pages
- support/helpers/mcpServers
- tests/mocked/chatbot
- app
- Chatbot
- components
- EmptyStates
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
Lines changed: 282 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
1 | 25 | | |
2 | 26 | | |
3 | 27 | | |
4 | 28 | | |
5 | 29 | | |
6 | 30 | | |
7 | 31 | | |
8 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
9 | 35 | | |
10 | 36 | | |
11 | 37 | | |
12 | 38 | | |
13 | | - | |
| 39 | + | |
14 | 40 | | |
15 | 41 | | |
16 | 42 | | |
| |||
19 | 45 | | |
20 | 46 | | |
21 | 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 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
22 | 302 | | |
23 | 303 | | |
24 | 304 | | |
Lines changed: 15 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
67 | 79 | | |
68 | 80 | | |
69 | 81 | | |
| |||
0 commit comments