Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
a000b3d5
Commit
a000b3d5
authored
May 28, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rework tests
parent
9aac89f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
16 deletions
+7
-16
utils.test.ts
ui/marketplace/utils.test.ts
+7
-16
No files found.
ui/marketplace/utils.test.ts
View file @
a000b3d5
import
type
{
NextRouter
}
from
'
next/router
'
;
import
type
{
NextRouter
}
from
'
next/router
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
removeQueryParam
from
'
lib/router/removeQueryParam
'
;
import
{
getAppUrl
}
from
'
./utils
'
;
import
{
getAppUrl
}
from
'
./utils
'
;
// Mocking the dependencies
jest
.
mock
(
'
lib/router/getQueryParamString
'
);
jest
.
mock
(
'
lib/router/removeQueryParam
'
);
describe
(
'
getAppUrl
'
,
()
=>
{
describe
(
'
getAppUrl
'
,
()
=>
{
let
router
:
NextRouter
;
let
router
:
NextRouter
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
router
=
{
router
=
{
pathname
:
'
/current/path
'
,
asPath
:
'
/current/path?someParam=value
'
,
asPath
:
'
/current/path?someParam=value
'
,
query
:
{
query
:
{},
url
:
'
https://example.com/custom-path?query=value
'
,
replace
:
jest
.
fn
(),
},
}
as
unknown
as
NextRouter
;
}
as
unknown
as
NextRouter
;
});
});
...
@@ -27,16 +20,16 @@ describe('getAppUrl', () => {
...
@@ -27,16 +20,16 @@ describe('getAppUrl', () => {
});
});
it
(
'
should return the custom url if origins match
'
,
()
=>
{
it
(
'
should return the custom url if origins match
'
,
()
=>
{
(
getQueryParamString
as
jest
.
Mock
).
mockReturnValue
(
'
https://example.com/custom-path?query=value
'
)
;
router
.
query
.
url
=
'
https://example.com/custom-path?query=value
'
;
const
result
=
getAppUrl
(
'
https://example.com/app
'
,
router
);
const
result
=
getAppUrl
(
'
https://example.com/app
'
,
router
);
expect
(
result
).
toBe
(
'
https://example.com/custom-path?query=value
'
);
expect
(
result
).
toBe
(
'
https://example.com/custom-path?query=value
'
);
});
});
it
(
'
should remove the query param and return original url if origins do not match
'
,
()
=>
{
it
(
'
should remove the query param and return original url if origins do not match
'
,
()
=>
{
(
getQueryParamString
as
jest
.
Mock
).
mockReturnValue
(
'
https://different.com/custom-path?query=value
'
)
;
router
.
query
.
url
=
'
https://different.com/custom-path?query=value
'
;
const
result
=
getAppUrl
(
'
https://example.com/app
'
,
router
);
const
result
=
getAppUrl
(
'
https://example.com/app
'
,
router
);
expect
(
result
).
toBe
(
'
https://example.com/app?someParam=value
'
);
expect
(
result
).
toBe
(
'
https://example.com/app?someParam=value
'
);
expect
(
r
emoveQueryParam
).
toHaveBeenCalledWith
(
router
,
'
url
'
);
expect
(
r
outer
.
replace
).
toHaveBeenCalledWith
({
pathname
:
'
/current/path
'
,
query
:
{},
hash
:
''
},
undefined
,
{
shallow
:
true
}
);
});
});
it
(
'
should construct the new url with custom params and hash
'
,
()
=>
{
it
(
'
should construct the new url with custom params and hash
'
,
()
=>
{
...
@@ -52,9 +45,7 @@ describe('getAppUrl', () => {
...
@@ -52,9 +45,7 @@ describe('getAppUrl', () => {
});
});
it
(
'
should handle error in custom url parsing
'
,
()
=>
{
it
(
'
should handle error in custom url parsing
'
,
()
=>
{
(
getQueryParamString
as
jest
.
Mock
).
mockImplementation
(()
=>
{
router
.
query
.
url
=
'
invalid-url
'
;
throw
new
Error
(
'
Invalid URL
'
);
});
const
result
=
getAppUrl
(
'
https://example.com/app
'
,
router
);
const
result
=
getAppUrl
(
'
https://example.com/app
'
,
router
);
expect
(
result
).
toBe
(
'
https://example.com/app?someParam=value
'
);
expect
(
result
).
toBe
(
'
https://example.com/app?someParam=value
'
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment