generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MWPW-136383 - Add off-origin ability to links.js (#1455)
* Add off-origin ability to links.js If off-origin keyword is set in links.json any link that doesn't match the site origin will open in a new tab. More detailed explanatory text. Wrap at 72 characters. * Adding unit tests --------- Co-authored-by: Ryan Clayton <[email protected]>
- Loading branch information
Showing
4 changed files
with
51 additions
and
7 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
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,17 @@ | ||
import { readFile } from '@web/test-runner-commands'; | ||
import { expect } from '@esm-bundle/chai'; | ||
import linkHandlers from '../../../libs/features/links.js'; | ||
|
||
document.body.innerHTML = await readFile({ path: './mocks/body.html' }); | ||
|
||
describe('Off origin links', () => { | ||
it('Sets target correctly', async () => { | ||
await linkHandlers('/test/blocks/links/mocks/off-origin.json'); | ||
const links = document.body.querySelectorAll('a'); | ||
|
||
expect(links[0].getAttribute('target')).to.equal('_blank'); | ||
expect(links[1].getAttribute('target')).to.equal(null); | ||
expect(links[2].getAttribute('target')).to.equal('_blank'); | ||
expect(links[3].getAttribute('target')).to.equal('_blank'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<p>Lorem ipsum dolor sit amet, <a href="https://analytics.google.com">consectetuer adipiscing elit</a>.</p> | ||
<p>Lorem ipsum dolor sit amet, <a href="/this/is/a/relative/link">relative link</a>.</p> | ||
<p>Lorem ipsum dolor sit amet, <a href="https://shopify.com">shopify link</a>.</p> | ||
<p>Go to Adobe, <a href="https://adobe.com">off-origin link</a>.</p> |
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,23 @@ | ||
{ | ||
"total": 2, | ||
"offset": 0, | ||
"limit": 2, | ||
"data": [ | ||
{ | ||
"domain": "https://analytics.google.com", | ||
"window": "_blank", | ||
"rel": "nofollow noopener noreferrer" | ||
}, | ||
{ | ||
"domain": "https://www.shopify.com", | ||
"window": "", | ||
"rel": "" | ||
}, | ||
{ | ||
"domain": "off-origin", | ||
"window": "_blank", | ||
"rel": "" | ||
} | ||
], | ||
":type": "sheet" | ||
} |