-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Endpoint] Policy list support for URL pagination state #63291
[Endpoint] Policy list support for URL pagination state #63291
Conversation
Pinging @elastic/endpoint-management (Team:Endpoint Management) |
Pinging @elastic/endpoint-app-team (Feature:Endpoint) |
* // do assertion | ||
* }); | ||
*/ | ||
export const createSpyMiddleware = <S = GlobalState>(): MiddlewareActionSpyHelper<S> => { |
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.
@parkiino , @kevinlog , @oatkiller , @peluja1012 , @dplumlee , @bkimmel , @kqualters-elastic - FYI. If you find that you have the same need for this type of utility while creating test cases for middleware or views that trigger middleware, we can elevate this utility to be in a higher level folder and re-use it. Its currently built in a generic way, so it should adopt to other middleware testing cases.
@oatkiller - I'm going to try to jest.fn()
on the middleware idea next. Did not include it here because I did not have a need currently for it. 😃
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.
FYI - I made the middleware dispatch
function a jest mocked function and exposed its mock
object via the dispatchSpy
property in the returned object.
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.
this is greatttt
const timeout = setTimeout(() => { | ||
watchers.delete(watch); | ||
reject(err); | ||
}, 4500); |
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.
would it ever make sense to make this timeout configurable? Not necessary now, but wondering if we would ever adjust jest's default.
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.
Yeah, for sure the createSpyMiddleware
factory can be improved in the future to take in the timeout. I actually looked to see if there was a way to access Jest's timeout value at runtime so that I could use it, but was not able to find it (there is one to set it, but not retrieve it).
…st-url-pagination-redo
…st-url-pagination-redo # Conflicts: # x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/middleware.ts # x-pack/plugins/endpoint/public/applications/endpoint/store/routing/action.ts # x-pack/plugins/endpoint/public/applications/endpoint/view/use_page_id.ts
jenkins test this |
return state.location?.pathname === '/policy'; | ||
}; | ||
|
||
export const routeLocation = (state: PolicyListState) => state.location; |
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.
you could drop export
if you'd like
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.
True. I will remove it in next commit
* | ||
* @param actionType | ||
*/ | ||
waitForAction: (actionType: Pick<AppAction, 'type'>['type']) => Promise<void>; |
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.
you should be able to write AppAction['type']
here and get the same behavior
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.
thanks. Will simplify it. (not sure why I decided to go the long/hard way on this one).
* Also - do not hold on to references to this property value if `jest.clearAllMocks()` or | ||
* `jest.resetAllMocks()` is called between usages of the value. | ||
*/ | ||
dispatchSpy: jest.Mock<Dispatch<AppAction>>['mock']; |
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.
if this isn't always set, maybe make the property dispatchSpy?
instead? that way we'll check for validity before using it (and hopefully avoid an error.)
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.
yeah, thats another alternative. But would that be a worst developer experience? It would imply that we would need to either check the property every time we try to use it (utils!.dispatchSpy
) or in destructing it, like dispatchSpy = utils!.dispatchUtils
which could lead to an error if done prior to store creation.
|
||
actionSpyMiddleware: api => { | ||
return next => { | ||
spyDispatch = jest.fn(action => { |
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.
could you create jest.fn
where it is defined and here do
spyDispatch.mockImplementation(action => {
// ...
})
would that allow you to remove the comment about an error occurring if you access the mock calls out of sequence?
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.
That was my initial thought (in order to avoid the check in the dispatchSpy
property getter), but dispatch needs access to next()
thus it needs to be defined within this context.
spyDispatch = jest.fn(action => { | ||
next(action); | ||
// If we have action watchers, then loop through them and call them with this action | ||
if (watchers.size > 0) { |
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.
would this work the same if you didn't have if (watchers.size > 0)
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.
ahh - good point. I'll remove the condition and have only the for loop
watch(action); | ||
} | ||
} | ||
return action; |
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.
are you using this?
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'm not using it, but needed to satisfy the type defined by jest.Mock<>
. Without it, I got type errors
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
) * store changes to support pagination via url * Fix storing location when pagination happens * Initial set of tests * Redux spy middleware and async utility * Add better types to `waitForAction` * Add more docs * fix urlSearchParams selector to account for array of values * full set of tests for policy list store concerns * More efficient redux spy middleware (no more sleep()) * Set spy middleware `dispatch` to a `jest.fn` and expose `mock` info. * Fix url param selector to return first param value when it is defined multiple times * Removed PageId and associated hook * clean up TODO items * Fixes post-merge frm `master` * Address code review comments
* master: (132 commits) document code splitting for client code (elastic#62593) Escape single quotes surrounded by double quotes (elastic#63229) [Endpoint] Update cli mapping to match endpoint package (elastic#63372) update in-app links to metricbeat configuration docs (elastic#63295) investigation notes field (documentation / metadata) (elastic#63386) [Maps] fix bug where toggling Scaling type does not re-fetch data (elastic#63326) [Alerting] set correct parameter for unauthented email action (elastic#63086) [Telemetry] force staging urls in tests (elastic#63356) Migrate legacy maps service to NP & update refs (elastic#60942) Fix task manager query to return tasks to retry (elastic#63360) [Endpoint] Policy list support for URL pagination state (elastic#63291) [Canvas] Migrate saved object mappings and migrations to Kibana Platform (elastic#58891) [DOCS] Add ILM tutorial (elastic#59502) [Maps] Add SOURCE_TYPES enumeration (elastic#62975) [Maps] update geospatial filters to use geo_shape query for geo_point fields (elastic#62966) Move away from npStart for embeddables in canvas (elastic#62680) Use MapInput type from Maps plugin (elastic#61539) Update to pagination for workpad and templates (elastic#62050) [SIEM] Fix AlertsTable id (elastic#63368) Consistent terminology around cypress test data (elastic#63279) ...
* master: document code splitting for client code (elastic#62593) Escape single quotes surrounded by double quotes (elastic#63229) [Endpoint] Update cli mapping to match endpoint package (elastic#63372) update in-app links to metricbeat configuration docs (elastic#63295) investigation notes field (documentation / metadata) (elastic#63386) [Maps] fix bug where toggling Scaling type does not re-fetch data (elastic#63326) [Alerting] set correct parameter for unauthented email action (elastic#63086) [Telemetry] force staging urls in tests (elastic#63356) Migrate legacy maps service to NP & update refs (elastic#60942) Fix task manager query to return tasks to retry (elastic#63360) [Endpoint] Policy list support for URL pagination state (elastic#63291) [Canvas] Migrate saved object mappings and migrations to Kibana Platform (elastic#58891) [DOCS] Add ILM tutorial (elastic#59502) [Maps] Add SOURCE_TYPES enumeration (elastic#62975) [Maps] update geospatial filters to use geo_shape query for geo_point fields (elastic#62966) Move away from npStart for embeddables in canvas (elastic#62680)
* store changes to support pagination via url * Fix storing location when pagination happens * Initial set of tests * Redux spy middleware and async utility * Add better types to `waitForAction` * Add more docs * fix urlSearchParams selector to account for array of values * full set of tests for policy list store concerns * More efficient redux spy middleware (no more sleep()) * Set spy middleware `dispatch` to a `jest.fn` and expose `mock` info. * Fix url param selector to return first param value when it is defined multiple times * Removed PageId and associated hook * clean up TODO items * Fixes post-merge frm `master` * Address code review comments
Regressed test cases for url pagination state for Policy List:
|
Summary
Drive pagination for the Policy List (page index + page size) via URL search params (
page_index=1&page_size=10
). This enables a user to click the browser back/forward buttons and be shown the correct set of data on the Policy list view.This PR also includes a Redux "spy" middleware test utility to avoid having to use
setTimeout
based sleeps in Unit Test cases. With this in place:isLoading
whenuserPaginatedPolicyListTable
#58896isLoading
whenuserNavigatedToPage
#58972🤞
Checklist
Delete any items that are not applicable to this PR.