File tree 2 files changed +14
-22
lines changed
2 files changed +14
-22
lines changed Original file line number Diff line number Diff line change @@ -17,19 +17,14 @@ jest.mock('@nextcloud/dialogs', () => ({
17
17
18
18
describe ( 'handleUrl' , ( ) => {
19
19
describe ( 'generateAbsoluteUrl' , ( ) => {
20
- it ( 'should generate url with IS_DESKTOP=false correctly ' , ( ) => {
21
- const output = generateAbsoluteUrl ( '/path' )
22
- expect ( output ) . toBe ( 'http://localhost/nc-webroot/path' )
20
+ it ( 'should generate absolute url ' , ( ) => {
21
+ const output = generateAbsoluteUrl ( '/path/{foo}' , { foo : 'bar' } )
22
+ expect ( output ) . toBe ( 'http://localhost/nc-webroot/path/bar ' )
23
23
} )
24
24
25
- it ( 'should generate url with IS_DESKTOP=true correctly' , ( ) => {
26
- const originalIsDesktop = global . IS_DESKTOP
27
- global . IS_DESKTOP = true
28
-
29
- const output = generateAbsoluteUrl ( '/path' )
30
- expect ( output ) . toBe ( '/nc-webroot/path' )
31
-
32
- global . IS_DESKTOP = originalIsDesktop
25
+ it ( 'should generate absolute url with specified base' , ( ) => {
26
+ const output = generateAbsoluteUrl ( '/path/{foo}' , { foo : 'bar' } , { baseURL : 'https://external.ltd/root' } )
27
+ expect ( output ) . toBe ( 'https://external.ltd/root/path/bar' )
33
28
} )
34
29
} )
35
30
Original file line number Diff line number Diff line change 5
5
6
6
import { showError , showSuccess } from '@nextcloud/dialogs'
7
7
import { t } from '@nextcloud/l10n'
8
- import { generateUrl } from '@nextcloud/router'
8
+ import { generateUrl , getBaseUrl } from '@nextcloud/router'
9
9
import type { UrlOptions } from '@nextcloud/router'
10
10
11
11
/**
12
12
* Generate a full absolute link with @nextcloud/router.generateUrl
13
13
*
14
14
* @param url - path
15
- * @param [ params] parameters to be replaced into the address
16
- * @param [ options] options for the parameter replacement
15
+ * @param params - parameters to be replaced into the address
16
+ * @param options - options for the parameter replacement
17
17
*/
18
- export function generateAbsoluteUrl ( url : string , params ?: object , options ? : UrlOptions ) : string {
18
+ export function generateAbsoluteUrl ( url : string , params ?: object , options : UrlOptions = { } ) : string {
19
19
// TODO: add this function to @nextcloud /router?
20
- const fullPath = generateUrl ( url , params , options )
21
- if ( ! IS_DESKTOP ) {
22
- return `${ window . location . protocol } //${ window . location . host } ${ fullPath } `
23
- } else {
24
- // On the Desktop generateUrl creates absolute url by default
25
- return fullPath
26
- }
20
+ return generateUrl ( url , params , {
21
+ baseURL : getBaseUrl ( ) ,
22
+ ...options ,
23
+ } )
27
24
}
28
25
29
26
/**
You can’t perform that action at this time.
0 commit comments