Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(links): add linkTo helper function
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Oct 2, 2024
commit f78015d5fc485b3e1db06609860bbeee0453bb4f
22 changes: 11 additions & 11 deletions src/tests/helpers/links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,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 @@ -139,7 +139,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')
})
})