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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/javascript/components/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Accordion', function() {

afterEach(function() {
plugin.destroy();
document.activeElement.blur();
if(document.activeElement) document.activeElement.blur();
$html.remove();
});

Expand Down
2 changes: 1 addition & 1 deletion test/javascript/components/drilldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Drilldown Menu', function() {

afterEach(function() {
plugin.destroy();
document.activeElement.blur();
if(document.activeElement) document.activeElement.blur();
$html.remove();
});

Expand Down
2 changes: 1 addition & 1 deletion test/javascript/components/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Dropdown', function() {

afterEach(function() {
plugin.destroy();
document.activeElement.blur();
if(document.activeElement) document.activeElement.blur();
$dropdownController.remove();
$dropdownContainer.remove();
});
Expand Down
18 changes: 5 additions & 13 deletions test/javascript/components/interchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,27 +170,19 @@ describe('Interchange', function() {
it('calls reflow on viewport size change once', function(done) {
$html = $(generateTemplate('image')).appendTo('body');
plugin = new Foundation.Interchange($html, {});
setTimeout(function() {
setTimeout(function () {
Foundation.IHearYou();
}, 1);
let spy = sinon.spy(plugin, '_reflow');

setTimeout(function() {
setTimeout(function () {
$(window).trigger('resize');
}, 5);

setTimeout(function() {
$(window).trigger('resize');
}, 10);

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.

}, 50);

setTimeout(function() { // Wait for third trigger...
setTimeout(function () {
sinon.assert.calledOnce(spy);
done();
}, 50);
}, 150);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/javascript/components/offcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Off Canvas', function() {

afterEach(function() {
plugin.destroy();
document.activeElement.blur();
if(document.activeElement) document.activeElement.blur();
$html.remove();
});

Expand Down
2 changes: 1 addition & 1 deletion test/javascript/components/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Reveal', function() {

afterEach(function() {
plugin.destroy();
document.activeElement.blur();
if(document.activeElement) document.activeElement.blur();
$html.remove();
});

Expand Down
2 changes: 1 addition & 1 deletion test/javascript/util/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Keyboard util', function() {
};

afterEach(function() {
document.activeElement.blur();
if(document.activeElement) document.activeElement.blur();
});

it('exists on the Foundation API', function() {
Expand Down