-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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 Sidebar navigations being cancelled. #6590
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,11 +282,91 @@ describe('amp-sidebar', () => { | |
}); | ||
}); | ||
|
||
it('should reflect state of the sidebar', () => { | ||
return getAmpSidebar().then(obj => { | ||
const sidebarElement = obj.ampSidebar; | ||
const impl = sidebarElement.implementation_; | ||
impl.schedulePause = sandbox.spy(); | ||
impl.scheduleResume = sandbox.spy(); | ||
impl.vsync_ = { | ||
mutate: function(callback) { | ||
callback(); | ||
}, | ||
}; | ||
sandbox.stub(timer, 'delay', function(callback) { | ||
callback(); | ||
}); | ||
expect(impl.isOpen_()).to.be.false; | ||
expect(impl.schedulePause.callCount).to.equal(0); | ||
expect(impl.scheduleResume.callCount).to.equal(0); | ||
impl.toggle_(); | ||
expect(impl.isOpen_()).to.be.true; | ||
expect(impl.schedulePause.callCount).to.equal(0); | ||
expect(impl.scheduleResume.callCount).to.equal(1); | ||
impl.toggle_(); | ||
expect(impl.isOpen_()).to.be.false; | ||
expect(impl.schedulePause.callCount).to.equal(1); | ||
expect(impl.scheduleResume.callCount).to.equal(1); | ||
impl.toggle_(); | ||
expect(impl.isOpen_()).to.be.true; | ||
expect(impl.schedulePause.callCount).to.equal(1); | ||
expect(impl.scheduleResume.callCount).to.equal(2); | ||
impl.toggle_(); | ||
expect(impl.isOpen_()).to.be.false; | ||
expect(impl.schedulePause.callCount).to.equal(2); | ||
expect(impl.scheduleResume.callCount).to.equal(2); | ||
}); | ||
}); | ||
|
||
it.skip('should fix scroll leaks on ios safari', () => { | ||
sandbox.stub(platform, 'isIos').returns(true); | ||
sandbox.stub(platform, 'isSafari').returns(true); | ||
return getAmpSidebar().then(obj => { | ||
const sidebarElement = obj.ampSidebar; | ||
const impl = sidebarElement.implementation_; | ||
impl.vsync_ = { | ||
mutate: function(callback) { | ||
callback(); | ||
}, | ||
}; | ||
sandbox.stub(timer, 'delay', function(callback) { | ||
callback(); | ||
}); | ||
const scrollLeakSpy = sandbox.spy(impl, 'fixIosElasticScrollLeak_'); | ||
impl.buildCallback(); | ||
expect(scrollLeakSpy.callCount).to.equal(1); | ||
}); | ||
}); | ||
|
||
it.skip('should adjust for IOS safari bottom bar', () => { | ||
sandbox.stub(platform, 'isIos').returns(true); | ||
sandbox.stub(platform, 'isSafari').returns(true); | ||
return getAmpSidebar().then(obj => { | ||
const sidebarElement = obj.ampSidebar; | ||
const impl = sidebarElement.implementation_; | ||
impl.vsync_ = { | ||
mutate: function(callback) { | ||
callback(); | ||
}, | ||
}; | ||
sandbox.stub(timer, 'delay', function(callback) { | ||
callback(); | ||
}); | ||
const compensateIosBottombarSpy = | ||
sandbox.spy(impl, 'compensateIosBottombar_'); | ||
const initalChildrenCount = sidebarElement.children.length; | ||
impl.open_(); | ||
expect(compensateIosBottombarSpy.callCount).to.equal(1); | ||
// 10 lis + one top padding element inserted | ||
expect(sidebarElement.children.length).to.equal(initalChildrenCount + 1); | ||
}); | ||
}); | ||
|
||
it('should close sidebar if clicked on anchor', () => { | ||
it('should close sidebar if clicked on a non-local anchor', () => { | ||
return getAmpSidebar().then(obj => { | ||
const sidebarElement = obj.ampSidebar; | ||
const anchor = sidebarElement.getElementsByTagName('a')[0]; | ||
anchor.href = '#newloc'; | ||
const impl = sidebarElement.implementation_; | ||
impl.schedulePause = sandbox.spy(); | ||
impl.vsync_ = { | ||
|
@@ -306,6 +386,15 @@ describe('amp-sidebar', () => { | |
if (eventObj.initEvent) { | ||
eventObj.initEvent('click', true, true); | ||
} | ||
sandbox.stub(sidebarElement, 'getAmpDoc', () => { | ||
return { | ||
win: { | ||
location: { | ||
href: window.location.href, | ||
}, | ||
}, | ||
}; | ||
}); | ||
anchor.dispatchEvent ? | ||
anchor.dispatchEvent(eventObj) : | ||
anchor.fireEvent('onkeydown', eventObj); | ||
|
@@ -316,11 +405,11 @@ describe('amp-sidebar', () => { | |
}); | ||
}); | ||
|
||
|
||
it('should not close sidebar if clicked on non-anchor', () => { | ||
it('should not close sidebar if clicked on a new origin navigation', () => { | ||
return getAmpSidebar().then(obj => { | ||
const sidebarElement = obj.ampSidebar; | ||
const li = sidebarElement.getElementsByTagName('li')[0]; | ||
const anchor = sidebarElement.getElementsByTagName('a')[0]; | ||
anchor.href = '#newloc'; | ||
const impl = sidebarElement.implementation_; | ||
impl.schedulePause = sandbox.spy(); | ||
impl.vsync_ = { | ||
|
@@ -340,22 +429,33 @@ describe('amp-sidebar', () => { | |
if (eventObj.initEvent) { | ||
eventObj.initEvent('click', true, true); | ||
} | ||
li.dispatchEvent ? | ||
li.dispatchEvent(eventObj) : | ||
li.fireEvent('onkeydown', eventObj); | ||
sandbox.stub(sidebarElement, 'getAmpDoc', () => { | ||
return { | ||
win: { | ||
location: { | ||
// Mocking navigating from example.com -> localhost:9876 | ||
href: 'http://example.com', | ||
}, | ||
}, | ||
}; | ||
}); | ||
anchor.dispatchEvent ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not blocking you on this , may be we should move this to a integration test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed #6593 to refactor this in future |
||
anchor.dispatchEvent(eventObj) : | ||
anchor.fireEvent('onkeydown', eventObj); | ||
expect(sidebarElement.hasAttribute('open')).to.be.true; | ||
expect(sidebarElement.getAttribute('aria-hidden')).to.equal('false'); | ||
expect(sidebarElement.style.display).to.equal(''); | ||
expect(impl.schedulePause.callCount).to.equal(0); | ||
}); | ||
}); | ||
|
||
it('should reflect state of the sidebar', () => { | ||
it('should not close sidebar if clicked on new page navigation', () => { | ||
return getAmpSidebar().then(obj => { | ||
const sidebarElement = obj.ampSidebar; | ||
const anchor = sidebarElement.getElementsByTagName('a')[0]; | ||
anchor.href = '#newloc'; | ||
const impl = sidebarElement.implementation_; | ||
impl.schedulePause = sandbox.spy(); | ||
impl.scheduleResume = sandbox.spy(); | ||
impl.vsync_ = { | ||
mutate: function(callback) { | ||
callback(); | ||
|
@@ -364,54 +464,42 @@ describe('amp-sidebar', () => { | |
sandbox.stub(timer, 'delay', function(callback) { | ||
callback(); | ||
}); | ||
expect(impl.isOpen_()).to.be.false; | ||
expect(impl.schedulePause.callCount).to.equal(0); | ||
expect(impl.scheduleResume.callCount).to.equal(0); | ||
impl.toggle_(); | ||
expect(impl.isOpen_()).to.be.true; | ||
expect(impl.schedulePause.callCount).to.equal(0); | ||
expect(impl.scheduleResume.callCount).to.equal(1); | ||
impl.toggle_(); | ||
expect(impl.isOpen_()).to.be.false; | ||
expect(impl.schedulePause.callCount).to.equal(1); | ||
expect(impl.scheduleResume.callCount).to.equal(1); | ||
impl.toggle_(); | ||
expect(impl.isOpen_()).to.be.true; | ||
expect(impl.schedulePause.callCount).to.equal(1); | ||
expect(impl.scheduleResume.callCount).to.equal(2); | ||
impl.toggle_(); | ||
expect(impl.isOpen_()).to.be.false; | ||
expect(impl.schedulePause.callCount).to.equal(2); | ||
expect(impl.scheduleResume.callCount).to.equal(2); | ||
}); | ||
}); | ||
|
||
it.skip('should fix scroll leaks on ios safari', () => { | ||
sandbox.stub(platform, 'isIos').returns(true); | ||
sandbox.stub(platform, 'isSafari').returns(true); | ||
return getAmpSidebar().then(obj => { | ||
const sidebarElement = obj.ampSidebar; | ||
const impl = sidebarElement.implementation_; | ||
impl.vsync_ = { | ||
mutate: function(callback) { | ||
callback(); | ||
}, | ||
}; | ||
sandbox.stub(timer, 'delay', function(callback) { | ||
callback(); | ||
expect(sidebarElement.hasAttribute('open')).to.be.false; | ||
impl.open_(); | ||
expect(sidebarElement.hasAttribute('open')).to.be.true; | ||
expect(sidebarElement.getAttribute('aria-hidden')).to.equal('false'); | ||
const eventObj = document.createEventObject ? | ||
document.createEventObject() : document.createEvent('Events'); | ||
if (eventObj.initEvent) { | ||
eventObj.initEvent('click', true, true); | ||
} | ||
sandbox.stub(sidebarElement, 'getAmpDoc', () => { | ||
return { | ||
win: { | ||
location: { | ||
// Mocking navigating from | ||
// /context.html?old=context -> /context.html | ||
href: 'http://localhost:9876/context.html?old=context', | ||
}, | ||
}, | ||
}; | ||
}); | ||
const scrollLeakSpy = sandbox.spy(impl, 'fixIosElasticScrollLeak_'); | ||
impl.buildCallback(); | ||
expect(scrollLeakSpy.callCount).to.equal(1); | ||
anchor.dispatchEvent ? | ||
anchor.dispatchEvent(eventObj) : | ||
anchor.fireEvent('onkeydown', eventObj); | ||
expect(sidebarElement.hasAttribute('open')).to.be.true; | ||
expect(sidebarElement.getAttribute('aria-hidden')).to.equal('false'); | ||
expect(sidebarElement.style.display).to.equal(''); | ||
expect(impl.schedulePause.callCount).to.equal(0); | ||
}); | ||
}); | ||
|
||
it.skip('should adjust for IOS safari bottom bar', () => { | ||
sandbox.stub(platform, 'isIos').returns(true); | ||
sandbox.stub(platform, 'isSafari').returns(true); | ||
it('should not close sidebar if clicked on non-anchor', () => { | ||
return getAmpSidebar().then(obj => { | ||
const sidebarElement = obj.ampSidebar; | ||
const li = sidebarElement.getElementsByTagName('li')[0]; | ||
const impl = sidebarElement.implementation_; | ||
impl.schedulePause = sandbox.spy(); | ||
impl.vsync_ = { | ||
mutate: function(callback) { | ||
callback(); | ||
|
@@ -420,13 +508,22 @@ describe('amp-sidebar', () => { | |
sandbox.stub(timer, 'delay', function(callback) { | ||
callback(); | ||
}); | ||
const compensateIosBottombarSpy = | ||
sandbox.spy(impl, 'compensateIosBottombar_'); | ||
const initalChildrenCount = sidebarElement.children.length; | ||
expect(sidebarElement.hasAttribute('open')).to.be.false; | ||
impl.open_(); | ||
expect(compensateIosBottombarSpy.callCount).to.equal(1); | ||
// 10 lis + one top padding element inserted | ||
expect(sidebarElement.children.length).to.equal(initalChildrenCount + 1); | ||
expect(sidebarElement.hasAttribute('open')).to.be.true; | ||
expect(sidebarElement.getAttribute('aria-hidden')).to.equal('false'); | ||
const eventObj = document.createEventObject ? | ||
document.createEventObject() : document.createEvent('Events'); | ||
if (eventObj.initEvent) { | ||
eventObj.initEvent('click', true, true); | ||
} | ||
li.dispatchEvent ? | ||
li.dispatchEvent(eventObj) : | ||
li.fireEvent('onkeydown', eventObj); | ||
expect(sidebarElement.hasAttribute('open')).to.be.true; | ||
expect(sidebarElement.getAttribute('aria-hidden')).to.equal('false'); | ||
expect(sidebarElement.style.display).to.equal(''); | ||
expect(impl.schedulePause.callCount).to.equal(0); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 why github thinks I added this 😩
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 think the git diff just messed up