Skip to content

Commit

Permalink
Add test for getModifiedHref
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed May 2, 2020
1 parent 8cbd2aa commit 135cd24
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/getModifiedHref.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ const {
buildRelativeUrl,
} = require('urltools');

/**
*
* @param {string} href
* @param {string} from
* @param {string} to
* @param {string} root
*
* @returns {string}
*/
function getModifiedHref(href, from, to, root) {
switch (getHrefType(href)) {
case hrefTypes.ABSOLUTE:
Expand Down
43 changes: 43 additions & 0 deletions test/getModifiedHref.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const expect = require('unexpected');
const getModifiedHref = require('../lib/getModifiedHref');

const root = 'file:///local/filesystem/path/';

describe('getModifiedHref', () => {
it('should handle absolute urls', () => {
expect(
getModifiedHref(
'https://hyperlink/to',
`${root}/from`,
'https://hyperlink/to',
root
),
'to be',
'https://hyperlink/to'
);
});

it('should handle protocol relative urls', () => {
expect(
getModifiedHref('//hyperlink/to', `${root}/from`, '//hyperlink/to', root),
'to be',
'//hyperlink/to'
);
});

it('should handle root relative urls', () => {
expect(
getModifiedHref('/to', `${root}/from`, `${root}/to`, root),
'to be',
'/to'
);
});

it('should handle relative urls', () => {
expect(
getModifiedHref('to', `${root}/from`, `${root}/to`, root),
'to be',
'to'
);
});
});

0 comments on commit 135cd24

Please sign in to comment.