1
1
import UserCard from "@/components/cards/User" ;
2
- import { renderWithRedux } from "../../../ __mocks__/renderWithRedux" ;
3
- import { mockUser } from "../../../ __mocks__/fixtures/user" ;
2
+ import { renderWithRedux } from "@ __mocks__/renderWithRedux" ;
3
+ import { mockUser } from "@ __mocks__/fixtures/user" ;
4
4
import { fireEvent , screen } from "@testing-library/react" ;
5
5
import "@testing-library/jest-dom" ;
6
- import { useRouter } from "next/router" ;
7
6
8
7
jest . mock ( "next/router" , ( ) => ( {
9
- useRouter : jest . fn ( ) ,
8
+ useRouter : jest . fn ( ( ) => ( {
9
+ locale : "en" ,
10
+ push : mockPush ,
11
+ } ) ) ,
10
12
} ) ) ;
11
13
const teamMembers = [ mockUser ] ;
12
14
const handleClick = jest . fn ( ( ) => { } ) ;
13
15
const mockPush = jest . fn ( ) ;
14
- const mockUseRouter = {
15
- locale : "en" ,
16
- push : mockPush ,
17
- } ;
18
- ( useRouter as jest . Mock ) . mockReturnValue ( mockUseRouter ) ;
19
16
20
17
describe ( "User card component" , ( ) => {
21
18
const timestamp = {
@@ -33,8 +30,7 @@ describe("User card component", () => {
33
30
window . getSelection = jest . fn ( ) . mockReturnValue ( {
34
31
type : "Caret" ,
35
32
} ) ;
36
- test ( "Renders the card component" , ( ) => {
37
- const teamMembers = [ mockUser ] ;
33
+ it ( "Renders the card component" , ( ) => {
38
34
expect ( screen . getByTestId ( "userId" ) ) . toBeInTheDocument ( ) ;
39
35
expect ( screen . getAllByTestId ( "avatar" ) . length ) . toEqual ( teamMembers . length ) ;
40
36
const linkElements = screen . getAllByRole ( "link" ) ;
@@ -46,16 +42,16 @@ describe("User card component", () => {
46
42
} ) ;
47
43
} ) ;
48
44
49
- test ( "Renders the correct tag and currecy when teamMembers is not empty" , ( ) => {
45
+ it ( "Renders the correct tag and currecy when teamMembers is not empty" , ( ) => {
50
46
expect ( screen . getByTestId ( "currencyId" ) ) . toBeInTheDocument ( ) ;
51
47
expect ( screen . getByTestId ( "tag" ) ) . toBeInTheDocument ( ) ;
52
48
} ) ;
53
49
54
- test ( "Calls onClick prop when clicked" , ( ) => {
50
+ it ( "Calls onClick prop when clicked" , ( ) => {
55
51
fireEvent . click ( screen . getByTestId ( "userId" ) ) ;
56
52
expect ( handleClick ) . toHaveBeenCalled ( ) ;
57
53
} ) ;
58
- test ( "Navigates to the correct link when clicked" , ( ) => {
54
+ it ( "Navigates to the correct link when clicked" , ( ) => {
59
55
const element = screen . getByText ( "test link" ) ;
60
56
fireEvent . click ( element ) ;
61
57
expect ( mockPush ) . toHaveBeenCalledWith ( "/testlink" ) ;
0 commit comments