-
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
Install global submit listener only when amp-form extension is registered #17246
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b07076d
install global submit listener only when amp-form extension is regist…
alabiaga a396169
fix tests
alabiaga 4ea8797
address comments
alabiaga ad813af
fixes
alabiaga 9ebc4cd
wait for body before checking for script in head
alabiaga 907397a
fix test
alabiaga 6323909
add comment
alabiaga eb06a6d
address comments
alabiaga 330e49a
Merge branch 'master' into 16761
2cbd928
Fix form recursive submit test.
5ed7700
Remove comment.
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 |
---|---|---|
|
@@ -14,8 +14,10 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import * as elementService from '../../src/element-service'; | ||
import * as sinon from 'sinon'; | ||
import {Services} from '../../src/services'; | ||
import {onDocumentFormSubmit_} from '../../src/document-submit'; | ||
import {installGlobalSubmitListenerForDoc, onDocumentFormSubmit_} from '../../src/document-submit'; | ||
|
||
describe('test-document-submit onDocumentFormSubmit_', () => { | ||
let sandbox; | ||
|
@@ -46,6 +48,38 @@ describe('test-document-submit onDocumentFormSubmit_', () => { | |
sandbox.restore(); | ||
}); | ||
|
||
describe('installGlobalSubmitListenerForDoc', () => { | ||
let headNode; | ||
let ampDoc; | ||
beforeEach(() => { | ||
headNode = document.createElement('body'); | ||
ampDoc = { | ||
getRootNode: () => headNode, | ||
}; | ||
}); | ||
|
||
afterEach(() => sandbox.reset()); | ||
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. Shouldn't be necessary if you don't create the sandbox in 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. removed |
||
|
||
it('should not register submit listener if amp-form is not registered.', | ||
() => { | ||
sandbox.stub(elementService, 'getElementServiceIfAvailableForDoc') | ||
.returns(Promise.resolve(null)); | ||
sandbox.spy(headNode, 'addEventListener'); | ||
installGlobalSubmitListenerForDoc(ampDoc).then(() => { | ||
expect(headNode.addEventListener).not.to.have.been.called; | ||
}); | ||
}); | ||
|
||
it('should register submit listener if amp-form extension is registered.', | ||
() => { | ||
sandbox.stub(elementService, 'getElementServiceIfAvailableForDoc') | ||
.returns(Promise.resolve({})); | ||
sandbox.spy(headNode, 'addEventListener'); | ||
installGlobalSubmitListenerForDoc(ampDoc).then(() => { | ||
expect(headNode.addEventListener).called; | ||
}); | ||
}); | ||
}); | ||
|
||
it('should check target and action attributes', () => { | ||
tgt.removeAttribute('action'); | ||
|
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.
This will delay installation of the event listener until
amp-form
extension is installed. We should instead simply check if the extension will be installed and synchronously install or skip the event listener.I think we can add a new function to element-service.js that uses
extensionScriptsInNode()
and reworkwaitForExtensionIfPresent
to use it.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. Thanks