Skip to content
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

Merged
merged 13 commits into from
Oct 27, 2020

Conversation

oatkiller
Copy link
Contributor

@oatkiller oatkiller commented Oct 19, 2020

Summary

  • 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.

For maintainers

@oatkiller oatkiller added release_note:skip Skip the PR/issue when compiling release notes v7.11.0 labels Oct 19, 2020
@@ -78,8 +78,7 @@ export function noAncestorsTwoChildrenWithRelatedEventsOnOrigin(): {
*/
async eventsWithEntityIDAndCategory(
entityID: string,
category: string,
after?: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed unused param

Copy link
Contributor

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?

Copy link
Contributor

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`
Copy link
Contributor Author

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';
Copy link
Contributor Author

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> {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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()
Copy link
Contributor Author

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.

Copy link
Contributor

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> {
Copy link
Contributor Author

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';
Copy link
Contributor Author

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> {
Copy link
Contributor Author

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.

).text();
});

it.each([
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These look like this now:
image

@oatkiller oatkiller force-pushed the remove-react-testing-library branch 2 times, most recently from 29e8ee6 to d2f775d Compare October 20, 2020 21:24
@oatkiller oatkiller marked this pull request as ready for review October 21, 2020 14:02
@oatkiller oatkiller requested review from a team as code owners October 21, 2020 14:02
@oatkiller oatkiller changed the title [Resolver] SideEffectContext changes [Resolver] SideEffectContext changes, remove @testing-library uses Oct 21, 2020

return (
<div onMouseLeave={onMouseLeave}>
<EuiPopover
anchorPosition={'downCenter'}
button={<ButtonContent />}
button={hoverArea}
Copy link
Contributor

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.

Copy link
Contributor Author

@oatkiller oatkiller Oct 21, 2020

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 divs, gray backgrounds are added to divs. 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.

copy-to-clipboard-feature mov

Copy link
Contributor

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...)

Copy link
Contributor

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...

Copy link
Contributor

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?

Copy link
Contributor

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.

@bkimmel
Copy link
Contributor

bkimmel commented Oct 21, 2020

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`
@oatkiller
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

async chunks size

id before after diff
securitySolution 8.1MB 8.1MB +1.2KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@oatkiller oatkiller merged commit 161972e into elastic:master Oct 27, 2020
@oatkiller oatkiller deleted the remove-react-testing-library branch October 27, 2020 16:41
oatkiller added a commit to oatkiller/kibana that referenced this pull request Oct 27, 2020
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`.
@MindyRS MindyRS added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Oct 27, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Oct 27, 2020
* 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)
  ...
oatkiller added a commit that referenced this pull request Oct 28, 2020
#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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants