Skip to content

Commit

Permalink
test(links): add linkTo helper function
Browse files Browse the repository at this point in the history
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Nov 18, 2024
1 parent 45c743e commit bd85cc1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/tests/helpers/links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,34 @@ global.OC = {

global._oc_webroot = ''

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]'}}))
expect(linkTo('mailTo:[email protected]'))
.toBe('mailTo:[email protected]')
})

test('relative link with fileid', () => {
expect(domHref({attrs: {href: 'otherfile?fileId=123'}}))
expect(linkTo('otherfile?fileId=123'))
.toBe('/apps/files/?dir=/Wiki&openfile=123#relPath=otherfile')
})

test('relative path with ../', () => {
expect(domHref({attrs: {href: '../other/otherfile?fileId=123'}}))
expect(linkTo('../other/otherfile?fileId=123'))
.toBe('/apps/files/?dir=/other&openfile=123#relPath=../other/otherfile')
})

Expand All @@ -48,7 +49,7 @@ describe('Preparing href attributes for the DOM', () => {
})

test('absolute path', () => {
expect(domHref({attrs: {href: '/otherfile?fileId=123'}}))
expect(linkTo('/otherfile?fileId=123'))
.toBe('/apps/files/?dir=/&openfile=123#relPath=/otherfile')
})

Expand Down

0 comments on commit bd85cc1

Please sign in to comment.