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
df619aa8
Commit
df619aa8
authored
Jun 13, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests for filtered queries
parent
3100b3e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
133 additions
and
2 deletions
+133
-2
useQueryWithPages.test.tsx
ui/shared/pagination/useQueryWithPages.test.tsx
+133
-2
No files found.
ui/shared/pagination/useQueryWithPages.test.tsx
View file @
df619aa8
...
...
@@ -37,6 +37,14 @@ const responses = {
items
:
[
{
hash
:
'
31
'
},
{
hash
:
'
32
'
}
],
next_page_params
:
null
,
},
page_filtered
:
{
items
:
[
{
hash
:
'
41
'
},
{
hash
:
'
42
'
}
],
next_page_params
:
{
block_number
:
41
,
index
:
42
,
items_count
:
43
,
},
},
};
beforeEach
(()
=>
{
...
...
@@ -363,10 +371,133 @@ describe('if there is page query param in URL', () => {
});
});
it
(
'
correctly navigates to the following pages
'
,
async
()
=>
{});
it
(
'
correctly navigates to the following pages
'
,
async
()
=>
{
const
routerPush
=
jest
.
fn
(()
=>
Promise
.
resolve
());
useRouter
.
mockReturnValue
({
...
router
,
pathname
:
'
/current-route
'
,
push
:
routerPush
,
query
:
{
page
:
'
2
'
}
});
const
params
:
Params
<
'
address_txs
'
>
=
{
resourceName
:
'
address_txs
'
,
pathParams
:
{
hash
:
addressMock
.
hash
},
};
fetch
.
once
(
JSON
.
stringify
(
responses
.
page_2
));
fetch
.
once
(
JSON
.
stringify
(
responses
.
page_3
));
const
{
result
}
=
renderHook
(()
=>
useQueryWithPages
(
params
),
{
wrapper
});
await
waitForApiResponse
();
await
act
(
async
()
=>
{
result
.
current
.
pagination
.
onNextPageClick
();
});
await
waitForApiResponse
();
expect
(
result
.
current
.
data
).
toEqual
(
responses
.
page_3
);
expect
(
result
.
current
.
pagination
).
toMatchObject
({
page
:
3
,
canGoBackwards
:
false
,
hasNextPage
:
false
,
isLoading
:
false
,
isVisible
:
true
,
});
expect
(
routerPush
).
toHaveBeenCalledTimes
(
1
);
expect
(
routerPush
).
toHaveBeenLastCalledWith
(
{
pathname
:
'
/current-route
'
,
query
:
{
next_page_params
:
encodeURIComponent
(
JSON
.
stringify
(
responses
.
page_2
.
next_page_params
)),
page
:
'
3
'
,
},
},
undefined
,
{
shallow
:
true
},
);
});
});
describe
(
'
queries with filters
'
,
()
=>
{});
describe
(
'
queries with filters
'
,
()
=>
{
it
(
'
reset page when filter is changed
'
,
async
()
=>
{
const
routerPush
=
jest
.
fn
(()
=>
Promise
.
resolve
());
useRouter
.
mockReturnValue
({
...
router
,
pathname
:
'
/current-route
'
,
push
:
routerPush
,
query
:
{
foo
:
'
bar
'
}
});
const
params
:
Params
<
'
address_txs
'
>
=
{
resourceName
:
'
address_txs
'
,
pathParams
:
{
hash
:
addressMock
.
hash
},
};
fetch
.
once
(
JSON
.
stringify
(
responses
.
page_1
));
fetch
.
once
(
JSON
.
stringify
(
responses
.
page_2
));
fetch
.
once
(
JSON
.
stringify
(
responses
.
page_filtered
));
const
{
result
}
=
renderHook
(()
=>
useQueryWithPages
(
params
),
{
wrapper
});
await
waitForApiResponse
();
await
act
(
async
()
=>
{
result
.
current
.
pagination
.
onNextPageClick
();
});
await
waitForApiResponse
();
await
act
(
async
()
=>
{
result
.
current
.
onFilterChange
({
filter
:
'
from
'
});
});
await
waitForApiResponse
();
expect
(
result
.
current
.
data
).
toEqual
(
responses
.
page_filtered
);
expect
(
result
.
current
.
pagination
).
toMatchObject
({
page
:
1
,
canGoBackwards
:
true
,
hasNextPage
:
true
,
isLoading
:
false
,
isVisible
:
true
,
});
expect
(
routerPush
).
toHaveBeenCalledTimes
(
2
);
expect
(
routerPush
).
toHaveBeenLastCalledWith
(
{
pathname
:
'
/current-route
'
,
query
:
{
filter
:
'
from
'
,
foo
:
'
bar
'
},
},
undefined
,
{
shallow
:
true
},
);
expect
(
animateScroll
.
scrollToTop
).
toHaveBeenCalledTimes
(
2
);
expect
(
animateScroll
.
scrollToTop
).
toHaveBeenLastCalledWith
({
duration
:
0
});
});
it
(
'
saves filter params in query when navigating between pages
'
,
async
()
=>
{
const
routerPush
=
jest
.
fn
(()
=>
Promise
.
resolve
());
useRouter
.
mockReturnValue
({
...
router
,
pathname
:
'
/current-route
'
,
push
:
routerPush
,
query
:
{
filter
:
'
from
'
,
foo
:
'
bar
'
}
});
const
params
:
Params
<
'
address_txs
'
>
=
{
resourceName
:
'
address_txs
'
,
pathParams
:
{
hash
:
addressMock
.
hash
},
};
fetch
.
once
(
JSON
.
stringify
(
responses
.
page_1
));
fetch
.
once
(
JSON
.
stringify
(
responses
.
page_2
));
const
{
result
}
=
renderHook
(()
=>
useQueryWithPages
(
params
),
{
wrapper
});
await
waitForApiResponse
();
await
act
(
async
()
=>
{
result
.
current
.
pagination
.
onNextPageClick
();
});
await
waitForApiResponse
();
expect
(
routerPush
).
toHaveBeenCalledTimes
(
1
);
expect
(
routerPush
).
toHaveBeenLastCalledWith
(
{
pathname
:
'
/current-route
'
,
query
:
{
filter
:
'
from
'
,
foo
:
'
bar
'
,
next_page_params
:
encodeURIComponent
(
JSON
.
stringify
(
responses
.
page_1
.
next_page_params
)),
page
:
'
2
'
,
},
},
undefined
,
{
shallow
:
true
},
);
});
});
async
function
waitForApiResponse
()
{
await
flushPromises
();
...
...
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