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

fix: check for activeElement before calling blur() on it #11214

Closed
wants to merge 5 commits into from
Closed

fix: check for activeElement before calling blur() on it #11214

wants to merge 5 commits into from

Conversation

DanielRuf
Copy link
Contributor

Description

Currently the tests throw errors in IE11 on Windows 10 because there might be some race conditions or differences in the browser behaviors as document.activeElement is not always defined.

Motivation and Context

Fixes the unit tests in IE11 on Windows 10.

Types of changes

  • Documentation
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to change)

Checklist (all required):

  • I have read and follow the CONTRIBUTING document.
  • There are no other pull request similar to this one.
  • The pull request title is descriptive.
  • The template is fully and correctly filled.
  • The pull request targets the right branch (develop or support/*).
  • My commits are correctly titled and contain all relevant information.
  • My code follows the code style of this project.
  • I have updated the documentation accordingly to my changes (if relevant).
  • I have added tests to cover my changes (if relevant).
  • All new and existing tests passed.

Copy link
Contributor

@ncoden ncoden left a comment

Choose a reason for hiding this comment

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

Stupid mistake on my side, sorry about that.

But I don't understand why doesn't this appear in https://travis-ci.org/zurb/foundation-sites/jobs/372717914 ? I can reproduce it locally with index.html.

@@ -27,7 +27,7 @@ describe('Accordion', function() {

afterEach(function() {
plugin.destroy();
document.activeElement.blur();
if(document.activeElement)document.activeElement.blur();
Copy link
Contributor

@ncoden ncoden Apr 29, 2018

Choose a reason for hiding this comment

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

if(document.activeElement)document.activeElement.blur();
//                        ^
//                     no space ?

@DanielRuf
Copy link
Contributor Author

I still guess that the tests on Browserstack run slower than on real devices.

@ncoden
Copy link
Contributor

ncoden commented Apr 29, 2018

chore: add missing space between condition and statement

Prefix depends on the type of change, not where it is. Here, it should be style

@@ -20,7 +20,7 @@ describe('Keyboard util', function() {
};

afterEach(function() {
document.activeElement.blur();
if(document.activeElement)document.activeElement.blur();
Copy link
Contributor

Choose a reason for hiding this comment

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

if(document.activeElement)document.activeElement.blur();
//                        ^
//                     no space ?

You can rebase this change with the previous commit I guess. The PR is clear enough. And use style: ...

@ncoden ncoden added the WIP label Apr 29, 2018
Copy link
Contributor

@ncoden ncoden left a comment

Choose a reason for hiding this comment

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

29d21c8 tests: always call blur() for asynchronous calls

Why "asynchronous calls". I see nothing asynchronous in test/javascript/components/dropdownMenu.js.

Also even if .focus() is called asynchronously, we wait for the test to finish before calling .blur() in afterEach.

So this line is not the issue.


setTimeout(function() {
$(window).trigger('resize');
}, 20);
Copy link
Contributor

Choose a reason for hiding this comment

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

This break the purpose of the test itself. calls reflow on viewport size change once means that with multiple resize, _reflow is called only once within a given delay (10ms by default for MutationObserver debounce). We cannot test this behavior without triggering resize once.

So we actually broke these test before with switching to delays over 10ms. We should triggers several resize in 10ms and expect reflow to be called once.

Also, this should not be in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. But not fixing this in this PR will produce a failing Travis build.

What do you recommend because of this issue with reflow and the timing issues on the Travis containers?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. But not fixing this in this PR will produce a failing Travis build.

Are you sure ? Tests runs after tests: always call blur() for asynchronous calls. Do we need both commits for tests to runs ?

I would recommend to actually test what we want to test and expect it to fail if the component does not work properly: trigger resize several times in 10ms and check after that if _reflow was called once.

This shoud work. If it doesn't, Interchange has a bug. I'll take a look at this later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take a look at this later.

This would be really helpful, thanks.

@DanielRuf
Copy link
Contributor Author

So this line is not the issue.

The testsuite tells differently but ok. How would you solve this here? Not sure if we can solve these issues related to timing functions when the browser / VM is too slow.

@ncoden ncoden self-assigned this May 1, 2018
@ncoden
Copy link
Contributor

ncoden commented May 11, 2018

I'll take a look at this later.

Will do this tomorrow

@ncoden
Copy link
Contributor

ncoden commented May 13, 2018

So the bug with the previous Interchange tests came from the browser not able to respect the setTimeout delays, which lead to big differences between several timeout running in parrallel. If the difference is bigger than the utils.trigger debounce time (10ms), several reflow may be triggered.

@DanielRuf
Copy link
Contributor Author

Well, in general setTimeout is never exact when it comes to timing as it is often longer than what is set as timeout.

So what is the correct solution in your opinion? Keep in mind that the VM might be slower and timeouts may trigger later.

@ncoden
Copy link
Contributor

ncoden commented May 13, 2018

I have a working solution. I'll open a PR specific to it because it require a bug fix in utils.trigger

@ncoden
Copy link
Contributor

ncoden commented May 13, 2018

See #11259

If you're okay with these PRs, I guess you can create a new clean PR to replace this one without these commits:

  • 9dbb994 tests: trigger resize event in interchange test only once
  • 29d21c8 tests: always call blur() for asynchronous calls
  • 2caa5dd tests: decrease timeout delay

@DanielRuf
Copy link
Contributor Author

If you're okay with these PRs

Which PRs? You linked just one? I thought these replace mine?

@ncoden
Copy link
Contributor

ncoden commented May 13, 2018

Sorry, see #11259 and its required fix #11258.

They only partially replace this PR as they only fix the Interchange test issue. The if(document.activeElement) fix is still required but I think we should propose it in a new PR (that would fully replace this one) and let this PR git history untouched.

Like "As soon as a Git branch is public, active and used, its commit history must be kept intact".

@DanielRuf DanielRuf closed this May 13, 2018
@DanielRuf DanielRuf deleted the tests/blur-check-active-element branch May 13, 2018 20:40
@ncoden
Copy link
Contributor

ncoden commented May 13, 2018

Closed in favor of #11260

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests: failing unit tests in IE11 due to blur() being called on null / undefined
2 participants