forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 [amp-story-page-outlink] Force page outlinks to use target='_top' i…
…n order to prevent navigation from breaking on Safari (ampproject#36428) * Force page outlinks to use target='_top' in order to prevent them from breaking on Safari * Lint * Add test-amp-story-page-attachment.js with basic attachment and outlink tests, along with a test verifying that outlink anchor elements always have a value of '_top' * Lint
- Loading branch information
1 parent
e7602e5
commit 44a18b0
Showing
2 changed files
with
67 additions
and
4 deletions.
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
56 changes: 56 additions & 0 deletions
56
extensions/amp-story/1.0/test/test-amp-story-page-attachment.js
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {AmpDocSingle} from '#service/ampdoc-impl'; | ||
import {AmpStoryPageAttachment} from '../amp-story-page-attachment'; | ||
|
||
describes.realWin('amp-story-page-attachment', {amp: true}, (env) => { | ||
let attachmentEl; | ||
let attachment; | ||
let outlinkEl; | ||
let outlink; | ||
|
||
beforeEach(() => { | ||
const {win} = env; | ||
|
||
// Set up the story. | ||
const storyEl = win.document.createElement('amp-story'); | ||
storyEl.getAmpDoc = () => new AmpDocSingle(win); | ||
win.document.body.appendChild(storyEl); | ||
|
||
// Set up the attachment element for inline attachment testing. | ||
attachmentEl = win.document.createElement('amp-story-page-attachment'); | ||
attachmentEl.getAmpDoc = () => new AmpDocSingle(win); | ||
storyEl.appendChild(attachmentEl); | ||
attachment = new AmpStoryPageAttachment(attachmentEl); | ||
|
||
// Set up the outlink element for outlink testing. | ||
outlinkEl = win.document.createElement('amp-story-page-outlink'); | ||
outlinkEl.getAmpDoc = () => new AmpDocSingle(win); | ||
storyEl.appendChild(outlinkEl); | ||
outlinkEl.appendChild(win.document.createElement('a')); | ||
outlink = new AmpStoryPageAttachment(outlinkEl); | ||
}); | ||
|
||
afterEach(() => { | ||
attachmentEl.remove(); | ||
outlinkEl.remove(); | ||
}); | ||
|
||
it('should build an attachment', async () => { | ||
attachment.buildCallback(); | ||
return attachment.layoutCallback(); | ||
}); | ||
|
||
it('should build an outlink', async () => { | ||
outlink.buildCallback(); | ||
return outlink.layoutCallback(); | ||
}); | ||
|
||
it('should build amp-story-page-outlink with target="_top" even when the publisher has specified a different value', async () => { | ||
const anchorEl = outlinkEl.querySelector('amp-story-page-outlink a'); | ||
anchorEl.setAttribute('target', '_blank'); | ||
|
||
outlink.buildCallback(); | ||
await outlink.layoutCallback(); | ||
|
||
expect(anchorEl.getAttribute('target')).to.eql('_top'); | ||
}); | ||
}); |