Pass scoped context to tutorial providers when building tutorials#22260
Pass scoped context to tutorial providers when building tutorials#22260nreese merged 4 commits intoelastic:masterfrom
Conversation
💔 Build Failed |
|
flaky visualize test |
|
jenkins, test this |
💔 Build Failed |
|
For my understanding: After this PR is merged the space plugin still needs to be modified to register the contextFactory? |
That's correct, this is focused on the architecture to allow the plugins to register additional information that can be used within the tutorials. |
src/ui/tutorials_mixin.js
Outdated
| return _.cloneDeep(tutorials); | ||
| server.decorate('server', 'getTutorials', (request) => { | ||
| const initialContext = {}; | ||
| const scopedContext = scopedTutorialContextFactoryies.reduce((accumulatedContext, contextFactory) => { |
There was a problem hiding this comment.
nit: the plural of factory is factories.
| server.decorate('server', 'getTutorials', (request) => { | ||
| const initialContext = {}; | ||
| const scopedContext = scopedTutorialContextFactoryies.reduce((accumulatedContext, contextFactory) => { | ||
| return { ...accumulatedContext, ...contextFactory(request) }; |
There was a problem hiding this comment.
Should we throw an error if we have two context factories try to set the same values?
There was a problem hiding this comment.
I have no preference.
There was a problem hiding this comment.
I don't have a strong preference either way, so LGTM!
💔 Build Failed |
|
jenkins, test this pretty please with sugar on top |
💔 Build Failed |
💚 Build Succeeded |
…astic#22260) * Pass scoped context to tutorial providers when building tutorials * only generated scoped context one time * spelling
…8764) ## Summary This PR migrates the first batch of test files from Enzyme to React Testing Library (RTL) as part of the effort to remove Enzyme dependencies from the Kibana codebase. Addresses #22260 ### Migration Details **Enzyme → RTL API Changes:** - Replaced `shallow()` / `mount()` with RTL's `render()` - Replaced `shallowWithIntl` / `mountWithIntl` with `renderWithI18n` - Replaced `.find()` with `screen.getByTestId()` / `screen.getByLabelText()` - Replaced `.simulate()` with `userEvent` interactions - Removed `wrapper.update()` calls (unnecessary in RTL) - Removed Enzyme type imports (`ShallowWrapper`, `ReactWrapper`) **Modern Testing Patterns:** - Added Jest modern fake timers setup (`jest.useFakeTimers()`) - Configured `userEvent.setup({ advanceTimers: jest.advanceTimersByTime })` - Replaced `waitFor()` polling with direct assertions using timer control - Implemented "Start → Flush → Await" pattern for async operations with internal timers - Added proper `act()` wrapping for state-changing operations - All tests now use async/await for user interactions **TypeScript Fixes:** - Fixed context provider type issues in `landing.test.tsx` - Ensured all required `AppDependencies` props are provided - Removed unused imports and fixed linting issues **Snapshot Updates:** - Updated all snapshots to reflect RTL's rendering output format ## Testing - ✅ All migrated tests pass locally - ✅ Zero console warnings (verified with `NODE_ENV=development`) - ✅ TypeScript compilation successful - ✅ ESLint passes with no errors - ✅ Snapshots updated and validated ## Performance Improvements Tests are now faster and more deterministic: - No polling with `waitFor()` - direct assertions with timer control - Fake timers eliminate real-time waiting - More reliable in CI environments ## Checklist - [x] Removed all Enzyme dependencies from test files - [x] Added modern fake timer setup - [x] Configured userEvent with timer advancement - [x] Replaced waitFor() with timer control - [x] All tests pass with zero warnings - [x] TypeScript compiles without errors - [x] ESLint passes - [x] Snapshots updated - [x] Helper files migrated where needed ## Next Steps This is the first batch. Subsequent batches will continue migrating the remaining test files listed in issue #222608. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
…stic#238764) ## Summary This PR migrates the first batch of test files from Enzyme to React Testing Library (RTL) as part of the effort to remove Enzyme dependencies from the Kibana codebase. Addresses elastic#22260 ### Migration Details **Enzyme → RTL API Changes:** - Replaced `shallow()` / `mount()` with RTL's `render()` - Replaced `shallowWithIntl` / `mountWithIntl` with `renderWithI18n` - Replaced `.find()` with `screen.getByTestId()` / `screen.getByLabelText()` - Replaced `.simulate()` with `userEvent` interactions - Removed `wrapper.update()` calls (unnecessary in RTL) - Removed Enzyme type imports (`ShallowWrapper`, `ReactWrapper`) **Modern Testing Patterns:** - Added Jest modern fake timers setup (`jest.useFakeTimers()`) - Configured `userEvent.setup({ advanceTimers: jest.advanceTimersByTime })` - Replaced `waitFor()` polling with direct assertions using timer control - Implemented "Start → Flush → Await" pattern for async operations with internal timers - Added proper `act()` wrapping for state-changing operations - All tests now use async/await for user interactions **TypeScript Fixes:** - Fixed context provider type issues in `landing.test.tsx` - Ensured all required `AppDependencies` props are provided - Removed unused imports and fixed linting issues **Snapshot Updates:** - Updated all snapshots to reflect RTL's rendering output format ## Testing - ✅ All migrated tests pass locally - ✅ Zero console warnings (verified with `NODE_ENV=development`) - ✅ TypeScript compilation successful - ✅ ESLint passes with no errors - ✅ Snapshots updated and validated ## Performance Improvements Tests are now faster and more deterministic: - No polling with `waitFor()` - direct assertions with timer control - Fake timers eliminate real-time waiting - More reliable in CI environments ## Checklist - [x] Removed all Enzyme dependencies from test files - [x] Added modern fake timer setup - [x] Configured userEvent with timer advancement - [x] Replaced waitFor() with timer control - [x] All tests pass with zero warnings - [x] TypeScript compiles without errors - [x] ESLint passes - [x] Snapshots updated - [x] Helper files migrated where needed ## Next Steps This is the first batch. Subsequent batches will continue migrating the remaining test files listed in issue elastic#222608. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Part of the solution to Support for Kibana Spaces in Beats modules.
Talked through a solution with @elastic/kibana-security. The conversation revolved around providing a way for plugins to decorate tutorials by registering a
contextFactory. ThecontextFactoryis a function that is called with therequestand returns an object of properties.tutorialSpecProviderwill now be called with an additional parameter,context, which contains the output of all registered contextFactories merged into a single object.tutorialSpecProvidercan use thecontextobject and its properties to conditionally modify the generated tutorial spec.In the cases of spaces, the spaces plugin will decorate tutorials with a
contextFactorythat returns the spaceId. So when the tutorialSpecProvider is called, if spaces plugin is running and the request is within a space, then the context will include{ spaceId: "value"}@ycombinator @ruflin @elastic/kibana-sharing @alexfrancoeur