-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enterprise Search] Upgrade Kea to 2.3, update LogicMounter helper w/ props support #94232
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,14 +80,15 @@ export const setMockActions = (actions: object) => { | |
* const { mount, unmount } = new LogicMounter(SomeLogic); | ||
* | ||
* it('some test', () => { | ||
* mount({ someValue: 'hello' }); | ||
* mount({ someValue: 'hello' }, { someProp: 'world' }); | ||
* unmount(); | ||
* }); | ||
*/ | ||
import { resetContext, Logic, LogicInput } from 'kea'; | ||
|
||
interface LogicFile { | ||
inputs: Array<LogicInput<Logic>>; | ||
build(props?: object): void; | ||
mount(): Function; | ||
} | ||
export class LogicMounter { | ||
|
@@ -110,8 +111,10 @@ export class LogicMounter { | |
}; | ||
|
||
// Automatically reset context & mount the logic file | ||
public mount = (values?: object) => { | ||
public mount = (values?: object, props?: object) => { | ||
this.resetContext(values); | ||
if (props) this.logicFile.build(props); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got that from Kea's docs here for context: https://kea.js.org/docs/guide/advanced#mounting-and-unmounting
|
||
|
||
const unmount = this.logicFile.mount(); | ||
this.unmountFn = unmount; | ||
return unmount; // Keep Kea behavior of returning an unmount fn from mount | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to quickly note - I'm not a super huge fan of how logic files that don't want defaults and only want props (e.g., AppLogic) now have to either pass
undefined
or{}
as a first param. If I could go back in time I'd probably change this toand have test files pass in their API like
mount({ defaults: { foo: 'bar' } })
ormount({ props: { bar: 'baz' } })
. IDK if we feel strongly to make that change in a ton of files at this point so I'm fine leaving it as-is, mostly just thinking out loudThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also for more context, here's the first conversation where I mentioned LogicMounter needing to support props: #92560 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I supposed you could do a
mountWithProps
, which would not require the empty object, but I am not a huge fan of that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya for sure, to clarify I don't hate this either and I'm fine with shipping it for now - we can definitely come back to this API later if we start using a ton more logic files w/ props!