How can I simulate window.focus() with react testing-library? - react-testing-library

I've been doing a lot of research, and I can't find a way to successfully simulate a window focus event.
I looked through "testing-library/user-event" and still can't find a way to do this.
In my component, we have window.addEventListener('focus', doSomething); but this is never getting invoked via the test runner.

I have verified that fireEvent.focus(window); does actually trigger the handler, and that the callback just isn't behaving as expected.

Related

Drag and Drop Behavior on Chrome DevTools Protocol

I am trying to write a tool that open's a website and interacts with and triggers the drag/drop behavior. I am seeing Input.dragIntercepted, Input.dispatchDragEvent functions in the documentation. But when I use these functions, I am getting a ... is not a function error. Probably, I am not using them in a proper way.
How can I use these functions to trigger drag and drop behavior of the web application? I did not find any example that shows usage of these functions.
First of all, Input.dragIntercepted really isn't a function. It's an event that will be fired, but only if you enable it, using Input.setInterceptDrags with enable set as true.
This is documented both here and here.

Can't get the DOM in a react app using testcafe

I'm new into testcafe. I have a react app which was made by create-react-app, and I'm trying to do very simple function:
await t.expect(ReactSelector('ReactHighcharts').exists.ok()
I figured out that no matter what component I put inside the selector I get flase.
When I explored more, I saw that react-scripts probably minifies/uglifies by his webpack, my code, and that's
why I can't get the DOM.
Am I right? if yes - how can I disable it? if not, I'd like to understand why the DOM is unreachable.
You can explicitly set the displayName property for a component or consider testing the dev build.
https://reactjs.org/docs/react-component.html#displayname

appAPI.notifier.show sometimes not work

i have a problem with Crossrider code.
I want to display notifier with this code:
appAPI.notifier.show({
'name':'my-notification-name',
'title':'Title',
'body':body_popUp,
'theme':'facebook',
'position':'bottom-left',
'close':false,
'sticky':true,
'fadeAfter':1,
'width':'700px',
'closeWhenClicked':false
});
but sometimes work, sometimes not work.
Do you have an idea? I have to write any instructions before call .show()?
Thanks in advance, Mattia
You don't show what body_popUp is set to but, assuming it's valid HTML and it's placed in the extension,js file, the code look fine.
In general, note that the notification is smart and only appears when it detects user movement in the browser. This algorithm is used as a way to ensure that the notification is seen, as it assumes the user is looking when activity is detected.
[Disclosure: I am a Crossrider employee]

Mono Form.Show from another form doesn't work

I am trying to port a WinForms app for use with Mono, and I've recently noted that calling Form.Show() from another form will either do nothing or cause the new form to flash and disappear. I read something about the new form needing a message pump, which is accomplished with Application.Run(), but that's already been called. Any idea why this doesn't work? I can't use ShowDialog because my program relies on events fired by completed async tasks, and I don't want to block a ton of extra threads that will be done right after the Show call.
Have you tried to hide your current form before showing/displaying your new one?
Seems to me like your form is indeed being displayed but for some strange reason it's being delegated to the background. Worth a shot.

Periodically calling TinyMCE's triggerSave function

If anyone knows TinyMCE well, do you know if it has built-in support for periodically calling its triggerSave function?
(This function copies it's content to its "parent" textarea. I want to observe said textarea for changes so I can implement autosave.)
Thanks
Don't try autosave, trust me on this one. triggerSave is buggy and when it fails it fails silently so you think that your content got posted, but in reality it didn't. After it fails once it will no longer work for the rest of the session, as in until the page is manually reloaded and tinymce does another full init().
Just got bit by this one badly, again. Never again trust triggerSave.
You could easily do this yourself by using JavaScript's setTimeout() function.
See http://www.w3schools.com/js/js_timing.asp.