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 Oct 2, 2024
1 parent edbb0d9 commit a5e5074
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/tests/helpers/links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

Expand Down Expand Up @@ -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')
})
})

0 comments on commit a5e5074

Please sign in to comment.