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
654382d0
Commit
654382d0
authored
Jul 17, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for useRatings hook
parent
7f636783
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
3 deletions
+76
-3
useRatings.test.tsx
ui/marketplace/Rating/useRatings.test.tsx
+74
-0
useRatings.tsx
ui/marketplace/Rating/useRatings.tsx
+2
-3
No files found.
ui/marketplace/Rating/useRatings.test.tsx
0 → 100644
View file @
654382d0
import
{
renderHook
,
wrapper
}
from
'
jest/lib
'
;
import
useRatings
from
'
./useRatings
'
;
const
useAccount
=
jest
.
fn
();
const
useApiQuery
=
jest
.
fn
();
jest
.
mock
(
'
lib/hooks/useToast
'
,
()
=>
jest
.
fn
());
jest
.
mock
(
'
wagmi
'
,
()
=>
({
useAccount
:
()
=>
useAccount
()
}));
jest
.
mock
(
'
lib/api/useApiQuery
'
,
()
=>
()
=>
useApiQuery
());
beforeEach
(()
=>
{
jest
.
clearAllMocks
();
});
it
(
'
should set canRate to true if address is defined and transactions_count is 10 or more
'
,
async
()
=>
{
useAccount
.
mockReturnValue
({
address
:
'
0x123
'
});
useApiQuery
.
mockReturnValue
({
isPlaceholderData
:
false
,
data
:
{
transactions_count
:
10
},
});
const
{
result
}
=
renderHook
(()
=>
useRatings
(),
{
wrapper
});
expect
(
result
.
current
.
canRate
).
toBe
(
true
);
});
it
(
'
should set canRate to undefined if address is undefined
'
,
async
()
=>
{
useAccount
.
mockReturnValue
({
address
:
undefined
});
useApiQuery
.
mockReturnValue
({
isPlaceholderData
:
false
,
data
:
{
transactions_count
:
10
},
});
const
{
result
}
=
renderHook
(()
=>
useRatings
(),
{
wrapper
});
expect
(
result
.
current
.
canRate
).
toBe
(
undefined
);
});
it
(
'
should set canRate to false if transactions_count is less than 10
'
,
async
()
=>
{
useAccount
.
mockReturnValue
({
address
:
'
0x123
'
});
useApiQuery
.
mockReturnValue
({
isPlaceholderData
:
false
,
data
:
{
transactions_count
:
5
},
});
const
{
result
}
=
renderHook
(()
=>
useRatings
(),
{
wrapper
});
expect
(
result
.
current
.
canRate
).
toBe
(
false
);
});
it
(
'
should set canRate to false if isPlaceholderData is true
'
,
async
()
=>
{
useAccount
.
mockReturnValue
({
address
:
'
0x123
'
});
useApiQuery
.
mockReturnValue
({
isPlaceholderData
:
true
,
data
:
{
transactions_count
:
10
},
});
const
{
result
}
=
renderHook
(()
=>
useRatings
(),
{
wrapper
});
expect
(
result
.
current
.
canRate
).
toBe
(
false
);
});
it
(
'
should set canRate to false if data is undefined
'
,
async
()
=>
{
useAccount
.
mockReturnValue
({
address
:
'
0x123
'
});
useApiQuery
.
mockReturnValue
({
isPlaceholderData
:
false
,
data
:
undefined
,
});
const
{
result
}
=
renderHook
(()
=>
useRatings
());
expect
(
result
.
current
.
canRate
).
toBe
(
false
);
});
it
(
'
should set canRate to false if transactions_count is undefined
'
,
async
()
=>
{
useAccount
.
mockReturnValue
({
address
:
'
0x123
'
});
useApiQuery
.
mockReturnValue
({
isPlaceholderData
:
false
,
data
:
{},
});
const
{
result
}
=
renderHook
(()
=>
useRatings
());
expect
(
result
.
current
.
canRate
).
toBe
(
false
);
});
ui/marketplace/Rating/useRatings.tsx
View file @
654382d0
...
@@ -108,9 +108,8 @@ export default function useRatings() {
...
@@ -108,9 +108,8 @@ export default function useRatings() {
},
[
address
,
toast
]);
},
[
address
,
toast
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
// TODO: uncomment validation after testing
const
{
isPlaceholderData
,
data
}
=
addressCountersQuery
;
const
{
isPlaceholderData
/*, data*/
}
=
addressCountersQuery
;
const
canRate
=
address
&&
!
isPlaceholderData
&&
Number
(
data
?.
transactions_count
)
>=
10
;
const
canRate
=
address
&&
!
isPlaceholderData
/* && Number(data?.transactions_count) >= 10*/
;
setCanRate
(
canRate
);
setCanRate
(
canRate
);
},
[
address
,
addressCountersQuery
]);
},
[
address
,
addressCountersQuery
]);
...
...
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