| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- import * as pathUtils from './path-utils';
- describe('page-utils', () => {
- describe('.normalizePath', () => {
- test.concurrent.each`
- path | expected
- ${'/'} | ${'/'}
- ${''} | ${'/'}
- ${'path'} | ${'/path'}
- ${'/path'} | ${'/path'}
- ${'path/'} | ${'/path'}
- ${'/path/'} | ${'/path'}
- ${'path1/path2'} | ${'/path1/path2'}
- ${'/path1/path2'} | ${'/path1/path2'}
- ${'path1/path2/'} | ${'/path1/path2'}
- ${'/path1/path2/'} | ${'/path1/path2'}
- ${'//path1/path2//'} | ${'/path1/path2'}
- ${'https://example.com'} | ${'/https://example.com'}
- ${'https://example.com/'} | ${'/https://example.com'}
- `("should normalize '$path' to '$expected'", ({ path, expected }) => {
- expect(pathUtils.normalizePath(path)).toBe(expected);
- });
- });
- describe('.hasHeadingSlash', () => {
- test.concurrent.each`
- path | expected
- ${'/'} | ${true}
- ${''} | ${false}
- ${'path'} | ${false}
- ${'/path'} | ${true}
- ${'path/'} | ${false}
- ${'/path/'} | ${true}
- ${'path1/path2'} | ${false}
- ${'/path1/path2'} | ${true}
- ${'path1/path2/'} | ${false}
- ${'/path1/path2/'} | ${true}
- ${'//path1/path2//'} | ${true}
- ${'https://example.com'} | ${false}
- ${'https://example.com/'} | ${false}
- `(
- "should return $expected when checking heading slash for '$path'",
- ({ path, expected }) => {
- expect(pathUtils.hasHeadingSlash(path)).toBe(expected);
- },
- );
- });
- describe('.hasTrailingSlash', () => {
- test.concurrent.each`
- path | expected
- ${'/'} | ${true}
- ${''} | ${false}
- ${'path'} | ${false}
- ${'/path'} | ${false}
- ${'path/'} | ${true}
- ${'/path/'} | ${true}
- ${'path1/path2'} | ${false}
- ${'/path1/path2'} | ${false}
- ${'path1/path2/'} | ${true}
- ${'/path1/path2/'} | ${true}
- ${'//path1/path2//'} | ${true}
- ${'https://example.com'} | ${false}
- ${'https://example.com/'} | ${true}
- `(
- "should return $expected when checking trailing slash for '$path'",
- ({ path, expected }) => {
- expect(pathUtils.hasTrailingSlash(path)).toBe(expected);
- },
- );
- });
- describe('.addHeadingSlash', () => {
- test.concurrent.each`
- path | expected
- ${'/'} | ${'/'}
- ${''} | ${'/'}
- ${'path'} | ${'/path'}
- ${'/path'} | ${'/path'}
- ${'path/'} | ${'/path/'}
- ${'/path/'} | ${'/path/'}
- ${'path1/path2'} | ${'/path1/path2'}
- ${'/path1/path2'} | ${'/path1/path2'}
- ${'path1/path2/'} | ${'/path1/path2/'}
- ${'/path1/path2/'} | ${'/path1/path2/'}
- ${'//path1/path2//'} | ${'//path1/path2//'}
- ${'https://example.com'} | ${'/https://example.com'}
- ${'https://example.com/'} | ${'/https://example.com/'}
- `(
- "should add heading slash to '$path' resulting in '$expected'",
- ({ path, expected }) => {
- expect(pathUtils.addHeadingSlash(path)).toBe(expected);
- },
- );
- });
- describe('.addTrailingSlash', () => {
- test.concurrent.each`
- path | expected
- ${'/'} | ${'/'}
- ${''} | ${'/'}
- ${'path'} | ${'path/'}
- ${'/path'} | ${'/path/'}
- ${'path/'} | ${'path/'}
- ${'/path/'} | ${'/path/'}
- ${'path1/path2'} | ${'path1/path2/'}
- ${'/path1/path2'} | ${'/path1/path2/'}
- ${'path1/path2/'} | ${'path1/path2/'}
- ${'/path1/path2/'} | ${'/path1/path2/'}
- ${'//path1/path2//'} | ${'//path1/path2//'}
- ${'https://example.com'} | ${'https://example.com/'}
- ${'https://example.com/'} | ${'https://example.com/'}
- `(
- "should add trailing slash to '$path' resulting in '$expected'",
- ({ path, expected }) => {
- expect(pathUtils.addTrailingSlash(path)).toBe(expected);
- },
- );
- });
- describe('.removeHeadingSlash', () => {
- test.concurrent.each`
- path | expected
- ${'/'} | ${'/'}
- ${''} | ${''}
- ${'path'} | ${'path'}
- ${'/path'} | ${'path'}
- ${'path/'} | ${'path/'}
- ${'/path/'} | ${'path/'}
- ${'path1/path2'} | ${'path1/path2'}
- ${'/path1/path2'} | ${'path1/path2'}
- ${'path1/path2/'} | ${'path1/path2/'}
- ${'/path1/path2/'} | ${'path1/path2/'}
- ${'//path1/path2//'} | ${'path1/path2//'}
- ${'https://example.com'} | ${'https://example.com'}
- ${'https://example.com/'} | ${'https://example.com/'}
- ${'//'} | ${'/'}
- `(
- "should remove heading slash from '$path' resulting in '$expected'",
- ({ path, expected }) => {
- expect(pathUtils.removeHeadingSlash(path)).toBe(expected);
- },
- );
- });
- describe('.removeTrailingSlash', () => {
- test.concurrent.each`
- path | expected
- ${'/'} | ${'/'}
- ${''} | ${''}
- ${'path'} | ${'path'}
- ${'/path'} | ${'/path'}
- ${'path/'} | ${'path'}
- ${'/path/'} | ${'/path'}
- ${'path1/path2'} | ${'path1/path2'}
- ${'/path1/path2'} | ${'/path1/path2'}
- ${'path1/path2/'} | ${'path1/path2'}
- ${'/path1/path2/'} | ${'/path1/path2'}
- ${'//path1/path2//'} | ${'//path1/path2'}
- ${'https://example.com'} | ${'https://example.com'}
- ${'https://example.com/'} | ${'https://example.com'}
- `(
- "should remove trailing slash from '$path' resulting in '$expected'",
- ({ path, expected }) => {
- expect(pathUtils.removeTrailingSlash(path)).toBe(expected);
- },
- );
- });
- describe('.getParentPath', () => {
- test.concurrent.each`
- path | expected
- ${'/'} | ${'/'}
- ${''} | ${'/'}
- ${'path'} | ${'/'}
- ${'/path'} | ${'/'}
- ${'path/'} | ${'/path'}
- ${'/path/'} | ${'/path'}
- ${'path1/path2'} | ${'/path1'}
- ${'/path1/path2'} | ${'/path1'}
- ${'path1/path2/'} | ${'/path1/path2'}
- ${'/path1/path2/'} | ${'/path1/path2'}
- ${'//path1/path2//'} | ${'/path1/path2'}
- ${'https://example.com'} | ${'/https:'}
- ${'https://example.com/'} | ${'/https://example.com'}
- ${'/page'} | ${'/'}
- `(
- "should get parent path of '$path' as '$expected'",
- ({ path, expected }) => {
- expect(pathUtils.getParentPath(path)).toBe(expected);
- },
- );
- });
- });
|