-
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
[Resolver] SideEffectContext
changes, remove @testing-library
uses
#81077
[Resolver] SideEffectContext
changes, remove @testing-library
uses
#81077
Conversation
ba41788
to
cd1ec0d
Compare
@@ -78,8 +78,7 @@ export function noAncestorsTwoChildrenWithRelatedEventsOnOrigin(): { | |||
*/ | |||
async eventsWithEntityIDAndCategory( | |||
entityID: string, | |||
category: string, | |||
after?: string |
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.
Removed unused param
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.
@bkimmel I think we added this so we could mock the pagination functionality for the /events
api. Are we still hoping to implement 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.
readonly payload: { | ||
/** | ||
* Used to identify the node that should be brought into view. | ||
* @deprecated Nodes are brought into view upon selection instead. See `appReceivedNewExternalProperties` |
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.
noticed this used alongside another side effect. I'm scheduled to work on removing this.
@@ -34,7 +34,7 @@ expect.extend({ | |||
expected: T | |||
): Promise<{ pass: boolean; message: () => string }> { | |||
// Used in printing out the pass or fail message | |||
const matcherName = 'toSometimesYieldEqualTo'; | |||
const matcherName = 'toYieldEqualTo'; |
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 was copy-pasted incorrectly (sorry.)
@@ -190,7 +190,7 @@ export class Simulator { | |||
* After 10 times, quit. | |||
* Use this to continually check a value. See `toYieldEqualTo`. | |||
*/ | |||
public async *map<R>(mapper: () => R): AsyncIterable<R> { | |||
public async *map<R>(mapper: (() => Promise<R>) | (() => R)): AsyncIterable<R> { |
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 function can now take a promise factory as well.
/** | ||
* The last value written to the clipboard via the `SideEffectors`. | ||
*/ | ||
public get clipboardText(): string { |
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.
Access the (mock) clipboard text.
@@ -218,6 +206,6 @@ const NodeDetailTimestamp = memo(({ eventDate }: { eventDate: Date | undefined } | |||
return formattedDate ? ( | |||
<CopyablePanelField textToCopy={formattedDate} content={formattedDate} /> | |||
) : ( | |||
getEmptyTagValue() |
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 was imported from the greater security solution app. Also it required a theme provider that we don't use (at least during tests and in the resolver simulator.) The function returned an emdash that had a color taken from the EUI theme. I'll try and add back the color styling using our EUI theme.
In the future we should discuss EUI theme handling.
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
@@ -19,6 +19,12 @@ const sideEffectors: SideEffectors = { | |||
return window.cancelAnimationFrame(...args); | |||
}, | |||
ResizeObserver, | |||
writeTextToClipboard(text: string): 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.
provide the production implementations of these side effectors.
@@ -4,13 +4,15 @@ | |||
* you may not use this file except in compliance with the Elastic License. | |||
*/ | |||
|
|||
import React, { FunctionComponent } from 'react'; | |||
import { render, waitFor, RenderResult, fireEvent } from '@testing-library/react'; |
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.
No longer use @testing-library
. We have moved to enzyme
now.
* After 10 times, quit. | ||
* Use this to continually check a value. See `toYieldEqualTo`. | ||
*/ | ||
async function* map<R>(mapper: () => R): AsyncIterable<R> { |
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 functionality is essentially copied from the resolver simulator. You can also find similar code in jest's github issues. It is used to continually assert a value until it is correct. See toYieldEqualTo
.
<Provider store={store}> | ||
<SideEffectContext.Provider value={simulator.mock}> | ||
<Test /> | ||
function TestWrapper({ |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
).text(); | ||
}); | ||
|
||
it.each([ |
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.
29e8ee6
to
d2f775d
Compare
SideEffectContext
changesSideEffectContext
changes, remove @testing-library
uses
|
||
return ( | ||
<div onMouseLeave={onMouseLeave}> | ||
<EuiPopover | ||
anchorPosition={'downCenter'} | ||
button={<ButtonContent />} | ||
button={hoverArea} |
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.
Not sure if this is something you want to resolve in this PR, but all this hover interaction (and whatever is happening on onMouseLeave
above) can't really be made accessibly.
I'm not super familiar with the security app so would need some help getting started to offer possible solutions but feel free to reach out with any questions.
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 gif shows the feature in use. If the user hovers over the panel that contains the interactive div
s, gray backgrounds are added to div
s. On mouseenter
, a tooltip shows up near the div. The tooltip contains a button with an image in it. You might not know it is a button. If the user hovers with the mouse over the button, a tooltip shows up on top of the original tooltip. This tooltip describes the button. Clicking this will attempt to copy text to the users clipboard.
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.
Actually, I think there's a pretty straight forward solution to all this! 🤞
If StyledCopyableField
becomes a button
instead of a div
, you can trigger the same popover on click (which works for keyboard "clicks" as well) and leave the same hover trigger you have now. This will also give you some basic focus states for free though you may want to style your own if you don't like the defaults.
You can also mimic the mouseenter
effect on the whole panel by adding a StyledPanel:focus-within
rule in addition to the :hover
rule which will trigger when any children of the panel are focused.
Lastly, we can improve the accessibility of the popover by adding the ownFocus
(or ownFocus={true}
) attribute. (Honestly, this prop can/should be applied to every EuiPopover
but isn't right now due to some historical reasons in EUI...)
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.
Stepping out of strictly accessibility for a sec, there seems to be enough room in the screenshot you posted to add the copy button inline to the right of the timestamps. That would remove a lot of the a11y concerns we're dealing with now if it's a viable option...
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.
We discussed doing that, but were looking to maintain parity with our current consuming application (security_solution) in how they have copy/paste functionality implemented. I know there's work planned to make all of this generally more accessible. Thoughts @monina-n @lindseypoli?
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 already put my thoughts in on this on a previous PR, but just to reiterate , I think the problems with putting something in that keyboard users can't use overrides the style/ux consistency concerns.
x-pack/plugins/security_solution/public/resolver/test_utilities/simulator/index.tsx
Show resolved
Hide resolved
Couple things to clear up, then I can thumb |
* `getBoundingClientRect` is now access through `SideEffectContext`. * `writeText` from the `Clipboard` API is now accessed through the `SideEffectContext` * No longer using `@testing-library/react` and `@testing-library/react-hooks` * No longer using `jest.spyOn` or `jest.clearAllMocks`
0f70bdd
to
7522b68
Compare
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]async chunks size
History
To update your PR or re-run it, just comment with: |
elastic#81077) * `getBoundingClientRect` is now accessed through `SideEffectContext`. * `writeText` from the `Clipboard` API is now accessed through the `SideEffectContext` * No longer using `@testing-library/react` and `@testing-library/react-hooks` * No longer using `jest.spyOn` (mostly) or `jest.clearAllMocks` The motivation for this PR: * We already have `SideEffectContext`, which is meant to be an alternative to using `jest.spyOn`. This PR uses the `SideEffectContext` for `getBoundingClientRect` and `navigator.clipboard.writeText`. * We have been using `enzyme` lately. This removes uses of `@testing-library/react` and `@testing-library/react-hooks` in favor of `enzyme`.
* master: (87 commits) [Actions] Adding `hasAuth` to Webhook Configuration to avoid confusing UX (elastic#81778) [i18n] add get_kibana_translation_paths tests (elastic#81624) [UX] Fix search term reset from url (elastic#81654) [Lens] Improved range formatter (elastic#80132) [Resolver] `SideEffectContext` changes, remove `@testing-library` uses (elastic#81077) [Time to Visualize] Update Library Text with Call to Action (elastic#81667) [docs] Resolving failed Kibana upgrade migrations (elastic#80999) [ftr/menuToggle] provide helper for enhanced menu toggle handling (elastic#81709) [Task Manager] adds basic observability into Task Manager's runtime operations (elastic#77868) Doc changes for stack management and grouped feature privileges (elastic#80486) Added functional test for alerts list filters by status, alert type and action type. Did a code refactoring and splitting for alerts tests. (elastic#81422) [Security Solution][Endpoint][Admin] Malware Protections Notify User Version (elastic#81415) Revert "[Actions] Adding `hasAuth` to Webhook Configuration to avoid confusing UX (elastic#81390)" [Maps] Use default format when proxying EMS-files (elastic#79760) [Discover] Deangularize context.html (elastic#81442) Use the displayName property in default editor (elastic#73311) adds bug label to Bug report for Security Solution template (elastic#81643) [ML] Transforms: Remove index field limitation for custom query. (elastic#81467) [Actions] Adding `hasAuth` to Webhook Configuration to avoid confusing UX (elastic#81390) [Task Manager] Mark task as failed if maxAttempts has been met. (elastic#80681) ...
#81077) (#81811) * `getBoundingClientRect` is now accessed through `SideEffectContext`. * `writeText` from the `Clipboard` API is now accessed through the `SideEffectContext` * No longer using `@testing-library/react` and `@testing-library/react-hooks` * No longer using `jest.spyOn` (mostly) or `jest.clearAllMocks` The motivation for this PR: * We already have `SideEffectContext`, which is meant to be an alternative to using `jest.spyOn`. This PR uses the `SideEffectContext` for `getBoundingClientRect` and `navigator.clipboard.writeText`. * We have been using `enzyme` lately. This removes uses of `@testing-library/react` and `@testing-library/react-hooks` in favor of `enzyme`.
Summary
getBoundingClientRect
is now accessed throughSideEffectContext
.writeText
from theClipboard
API is now accessed through theSideEffectContext
@testing-library/react
and@testing-library/react-hooks
jest.spyOn
(mostly) orjest.clearAllMocks
The motivation for this PR:
SideEffectContext
, which is meant to be an alternative to usingjest.spyOn
. This PR uses theSideEffectContext
forgetBoundingClientRect
andnavigator.clipboard.writeText
.enzyme
lately. This removes uses of@testing-library/react
and@testing-library/react-hooks
in favor ofenzyme
.For maintainers