-
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 amp-accordion and fontloader local tests failures #3052
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,27 @@ import {Timer} from '../../../../src/timer'; | |
import {adopt} from '../../../../src/runtime'; | ||
import {createIframePromise} from '../../../../testing/iframe'; | ||
require('../amp-accordion'); | ||
import * as sinon from 'sinon'; | ||
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. wow - wonder how it was working without this:) 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. This test didn't use sinon really, but there are a lot of files who are and not doing the import. I am going to send another PR to fix all the non-imported sinon. I think it depends on how the bundler bundles them but yeah I've seen a nasty test failure in |
||
|
||
adopt(window); | ||
|
||
describe('amp-accordion', () => { | ||
const timer = new Timer(window); | ||
let timer; | ||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
function getAmpAccordion() { | ||
return createIframePromise().then(iframe => { | ||
timer = new Timer(iframe.win); | ||
const ampAccordion = iframe.doc.createElement('amp-accordion'); | ||
ampAccordion.implementation_.mutateElement = fn => fn(); | ||
for (let i = 0; i < 3; i++) { | ||
const section = iframe.doc.createElement('section'); | ||
section.innerHTML = '<h2>Section ' + i + '</h2><div>Loreum ipsum</div>'; | ||
|
@@ -46,43 +59,32 @@ describe('amp-accordion', () => { | |
it('should expand when header of a collapsed section is clicked', () => { | ||
return getAmpAccordion().then(obj => { | ||
const iframe = obj.iframe; | ||
let clickEvent; | ||
if (iframe.doc.createEvent) { | ||
clickEvent = iframe.doc.createEvent('MouseEvent'); | ||
clickEvent.initMouseEvent('click', true, true, iframe.win, 1); | ||
} else { | ||
clickEvent = iframe.doc.createEventObject(); | ||
clickEvent.type = 'click'; | ||
} | ||
const headerElements = | ||
iframe.doc.querySelectorAll('section > *:first-child'); | ||
const headerElements = iframe.doc.querySelectorAll( | ||
'section > *:first-child'); | ||
const clickEvent = { | ||
target: headerElements[0], | ||
preventDefault: sandbox.spy(), | ||
}; | ||
expect(headerElements[0].parentNode.hasAttribute('expanded')).to.be.false; | ||
headerElements[0].dispatchEvent(clickEvent); | ||
return timer.promise(50).then(() => { | ||
expect(headerElements[0].parentNode.hasAttribute('expanded')) | ||
.to.be.true; | ||
}); | ||
obj.ampAccordion.implementation_.handleClick_(clickEvent); | ||
expect(headerElements[0].parentNode.hasAttribute('expanded')).to.be.true; | ||
expect(clickEvent.preventDefault.called).to.be.true; | ||
}); | ||
}); | ||
|
||
it('should collapse when header of an expanded section is clicked', () => { | ||
return getAmpAccordion().then(obj => { | ||
const iframe = obj.iframe; | ||
let clickEvent; | ||
if (iframe.doc.createEvent) { | ||
clickEvent = iframe.doc.createEvent('MouseEvent'); | ||
clickEvent.initMouseEvent('click', true, true, iframe.win, 1); | ||
} else { | ||
clickEvent = iframe.doc.createEventObject(); | ||
clickEvent.type = 'click'; | ||
} | ||
const headerElements = | ||
iframe.doc.querySelectorAll('section > *:first-child'); | ||
const headerElements = iframe.doc.querySelectorAll( | ||
'section > *:first-child'); | ||
const clickEvent = { | ||
target: headerElements[1], | ||
preventDefault: sandbox.spy(), | ||
}; | ||
expect(headerElements[1].parentNode.hasAttribute('expanded')).to.be.true; | ||
headerElements[1].dispatchEvent(clickEvent); | ||
return timer.promise(50).then(() => { | ||
expect(headerElements[1].parentNode.hasAttribute('expanded')) | ||
.to.be.false; | ||
}); | ||
obj.ampAccordion.implementation_.handleClick_(clickEvent); | ||
expect(headerElements[1].parentNode.hasAttribute('expanded')).to.be.false; | ||
expect(clickEvent.preventDefault.called).to.be.true; | ||
}); | ||
}); | ||
}); |
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.
rename this to onHeaderClick_
and annotate the function
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.
Done.