-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(links): add linkTo helper function
Signed-off-by: Max <[email protected]>
- Loading branch information
1 parent
edbb0d9
commit a5e5074
Showing
1 changed file
with
11 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,43 +16,43 @@ global._oc_webroot = '' | |
jest.mock('@nextcloud/initial-state') | ||
loadState.mockImplementation((app, key) => 'files') | ||
|
||
const linkTo = href => domHref({ attrs: { href } }) | ||
|
||
describe('Preparing href attributes for the DOM', () => { | ||
|
||
test('leave empty hrefs alone', () => { | ||
expect(domHref({attrs: {href: ''}})).toBe('') | ||
expect(linkTo('')).toBe('') | ||
}) | ||
|
||
test('leave undefined hrefs alone', () => { | ||
expect(domHref({attrs: {}})).toBe(undefined) | ||
}) | ||
|
||
test('full url', () => { | ||
expect(domHref({attrs: {href: 'https://otherdomain.tld'}})) | ||
.toBe('https://otherdomain.tld') | ||
expect(linkTo('https://otherdomain.tld')).toBe('https://otherdomain.tld') | ||
}) | ||
|
||
test('other protocol', () => { | ||
expect(domHref({attrs: {href: 'mailTo:[email protected]'}})) | ||
.toBe('mailTo:[email protected]') | ||
test('other protocols', () => { | ||
expect(linkTo('mailto:[email protected]')).toBe('mailto:[email protected]') | ||
}) | ||
|
||
test('relative link with fileid (old format from file picker)', () => { | ||
expect(domHref({attrs: {href: 'otherfile?fileId=123'}})) | ||
expect(linkTo('otherfile?fileId=123')) | ||
.toBe('http://localhost/f/123') | ||
}) | ||
|
||
test('relative path with ../ (old format from file picker)', () => { | ||
expect(domHref({attrs: {href: '../other/otherfile?fileId=123'}})) | ||
expect(linkTo('../other/otherfile?fileId=123')) | ||
.toBe('http://localhost/f/123') | ||
}) | ||
|
||
test('absolute path (old format from file picker)', () => { | ||
expect(domHref({attrs: {href: '/other/otherfile?fileId=123'}})) | ||
expect(linkTo('/other/otherfile?fileId=123')) | ||
.toBe('http://localhost/f/123') | ||
}) | ||
|
||
test('absolute path (old format from file picker)', () => { | ||
expect(domHref({attrs: {href: '/otherfile?fileId=123'}})) | ||
expect(linkTo('/otherfile?fileId=123')) | ||
.toBe('http://localhost/f/123') | ||
}) | ||
|
||
|
@@ -134,7 +134,7 @@ describe('Preparing href attributes for the DOM in Collectives app', () => { | |
}) | ||
|
||
test('relative link with fileid in Collectives', () => { | ||
expect(domHref({attrs: {href: 'otherfile?fileId=123'}})) | ||
expect(linkTo('otherfile?fileId=123')) | ||
.toBe('otherfile?fileId=123') | ||
}) | ||
}) |