-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add unit tests for Utils.js * Use relative url for CMCD nor attribute * URI encode the CMCD nor url
- Loading branch information
Showing
5 changed files
with
135 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,90 @@ | ||
import Utils from '../../src/core/Utils' | ||
import {expect} from 'chai'; | ||
|
||
describe('Utils', () => { | ||
describe('getRelativeUrl', () => { | ||
|
||
it('Should return complete url if no original url is given', () => { | ||
const b = 'https://localhost:3000/d/e/f.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(undefined,b)).to.be.equal('https://localhost:3000/d/e/f.mp4'); | ||
}) | ||
|
||
it('Should return relative url if strings are different after server name', () => { | ||
const a = 'https://localhost:3000/a/b/c.mp4'; | ||
const b = 'https://localhost:3000/d/e/f.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('/d/e/f.mp4'); | ||
}) | ||
|
||
it('Should return relative url if strings are similar up to one element before filename', () => { | ||
const a = 'https://localhost:3000/a/b/c.mp4'; | ||
const b = 'https://localhost:3000/a/c/f.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('../c/f.mp4'); | ||
}) | ||
|
||
it('Should return relative url if strings are similar up to filename', () => { | ||
const a = 'https://localhost:3000/a/b/c.mp4'; | ||
const b = 'https://localhost:3000/a/b/f.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('f.mp4'); | ||
}) | ||
|
||
it('Should return complete url if origin is different', () => { | ||
const a = 'https://localhost:3000/a/b/c.mp4'; | ||
const b = 'https://loca:3000/a/b/f.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('https://loca:3000/a/b/f.mp4'); | ||
}) | ||
|
||
it('Should return filename if origin differs in terms of SSL', () => { | ||
const a = 'https://localhost:3000/a/b/c.mp4'; | ||
const b = 'http://localhost:3000/a/b/e.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('e.mp4'); | ||
}) | ||
|
||
it('Should return relative url if part of the pathnames are not equal', () => { | ||
const a = 'https://localhost:3000/a/b/c.mp4'; | ||
const b = 'https://localhost:3000/ab/b/f.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('/ab/b/f.mp4'); | ||
}) | ||
|
||
it('Should return relative url if target pathname is longer than source pathname ', () => { | ||
const a = 'https://localhost:3000/a/b/f.mp4'; | ||
const b = 'https://localhost:3000/a/b/f/e/c.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('f/e/c.mp4'); | ||
}) | ||
|
||
it('Should return relative url if source pathname is longer than target pathname ', () => { | ||
const a = 'https://localhost:3000/a/b/f/e/c.mp4'; | ||
const b = 'https://localhost:3000/a/b/f.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('/a/b/f.mp4'); | ||
}) | ||
|
||
it('Should return relative url if source contains slash in the end ', () => { | ||
const a = 'https://localhost:3000/a/'; | ||
const b = 'https://localhost:3000/a/b.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('b.mp4'); | ||
}) | ||
|
||
it('Should return relative url if source pathnames are exceptionally long ', () => { | ||
const a = 'https://localhost:3000/a/b/c/d/e/f/g/h/1.mp4'; | ||
const b = 'https://localhost:3000/a/b/c/d/e/change/i/j/k/l/m/n/2.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('../../../change/i/j/k/l/m/n/2.mp4'); | ||
}) | ||
|
||
it('Should return relative url if source contains slash in the end and multiple elements in the path', () => { | ||
const a = 'https://localhost:3000/a/b/c/'; | ||
const b = 'https://localhost:3000/a/b/x/c.mp4'; | ||
|
||
expect(Utils.getRelativeUrl(a,b)).to.be.equal('../x/c.mp4'); | ||
}) | ||
}) | ||
}) |
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