Skip to content

Comments

Pass scoped context to tutorial providers when building tutorials#22260

Merged
nreese merged 4 commits intoelastic:masterfrom
nreese:spaceIdInTutorials
Sep 5, 2018
Merged

Pass scoped context to tutorial providers when building tutorials#22260
nreese merged 4 commits intoelastic:masterfrom
nreese:spaceIdInTutorials

Conversation

@nreese
Copy link
Contributor

@nreese nreese commented Aug 22, 2018

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. The contextFactory is a function that is called with the request and returns an object of properties.
tutorialSpecProvider will now be called with an additional parameter, context, which contains the output of all registered contextFactories merged into a single object. tutorialSpecProvider can use the context object and its properties to conditionally modify the generated tutorial spec.

In the cases of spaces, the spaces plugin will decorate tutorials with a contextFactory that 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

@elasticmachine
Copy link
Contributor

💔 Build Failed

@nreese
Copy link
Contributor Author

nreese commented Aug 22, 2018

flaky visualize test

fail: "visualize app data table with index without time filter "after all" hook"
19:08:35              │      [GET http://localhost:9515/session/2f5693819948083ed1f3978b0ad5dd23/url] connect ECONNREFUSED 127.0.0.1:9515

@nreese
Copy link
Contributor Author

nreese commented Aug 22, 2018

jenkins, test this

@elasticmachine
Copy link
Contributor

💔 Build Failed

@ruflin
Copy link
Contributor

ruflin commented Aug 23, 2018

For my understanding: After this PR is merged the space plugin still needs to be modified to register the contextFactory?

@kobelb
Copy link
Contributor

kobelb commented Aug 23, 2018

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.

return _.cloneDeep(tutorials);
server.decorate('server', 'getTutorials', (request) => {
const initialContext = {};
const scopedContext = scopedTutorialContextFactoryies.reduce((accumulatedContext, contextFactory) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the plural of factory is factories.

server.decorate('server', 'getTutorials', (request) => {
const initialContext = {};
const scopedContext = scopedTutorialContextFactoryies.reduce((accumulatedContext, contextFactory) => {
return { ...accumulatedContext, ...contextFactory(request) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw an error if we have two context factories try to set the same values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no preference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference either way, so LGTM!

Copy link
Contributor

@kobelb kobelb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@elasticmachine
Copy link
Contributor

💔 Build Failed

@ycombinator
Copy link
Contributor

jenkins, test this pretty please with sugar on top

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nreese nreese merged commit b26e2b4 into elastic:master Sep 5, 2018
nreese added a commit to nreese/kibana that referenced this pull request Sep 5, 2018
…astic#22260)

* Pass scoped context to tutorial providers when building tutorials

* only generated scoped context one time

* spelling
nreese added a commit that referenced this pull request Sep 5, 2018
…2260) (#22743)

* Pass scoped context to tutorial providers when building tutorials

* only generated scoped context one time

* spelling
kapral18 added a commit that referenced this pull request Oct 21, 2025
…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>
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Oct 27, 2025
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Add Data Add Data and sample data feature on Home v6.5.0 v7.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants