|
1 | | -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ |
2 | | -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ |
3 | | -/* eslint-disable @typescript-eslint/no-unsafe-return */ |
4 | | - |
5 | 1 | import React from 'react'; |
6 | 2 | import { create, ReactTestRendererJSON } from 'react-test-renderer'; |
7 | 3 | import AuthOrProfile from './components/auth-or-profile'; |
8 | 4 |
|
| 5 | +const defaultUserProps = { |
| 6 | + user: { |
| 7 | + username: 'test-user', |
| 8 | + picture: 'https://freecodecamp.org/image.png', |
| 9 | + isDonating: false, |
| 10 | + yearsTopContributor: [] |
| 11 | + }, |
| 12 | + pending: false, |
| 13 | + pathName: '/learn' |
| 14 | +}; |
| 15 | + |
| 16 | +const donatingUserProps = { |
| 17 | + ...defaultUserProps, |
| 18 | + user: { |
| 19 | + ...defaultUserProps.user, |
| 20 | + isDonating: true |
| 21 | + } |
| 22 | +}; |
| 23 | + |
| 24 | +const topContributorUserProps = { |
| 25 | + ...defaultUserProps, |
| 26 | + user: { |
| 27 | + ...defaultUserProps.user, |
| 28 | + yearsTopContributor: ['2020'] |
| 29 | + } |
| 30 | +}; |
| 31 | + |
| 32 | +const topDonatingContributorUserProps = { |
| 33 | + ...topContributorUserProps, |
| 34 | + user: { |
| 35 | + ...topContributorUserProps.user, |
| 36 | + isDonating: true |
| 37 | + } |
| 38 | +}; |
| 39 | + |
9 | 40 | jest.mock('../../analytics'); |
10 | 41 |
|
11 | 42 | describe('<AuthOrProfile />', () => { |
12 | 43 | it('has avatar with default border for default users', () => { |
13 | | - const defaultUserProps = { |
14 | | - user: { |
15 | | - username: 'test-user', |
16 | | - picture: 'https://freecodecamp.org/image.png' |
17 | | - }, |
18 | | - pending: false, |
19 | | - pathName: '/learn' |
20 | | - }; |
21 | | - |
22 | 44 | const componentTree = create( |
23 | 45 | <AuthOrProfile {...defaultUserProps} /> |
24 | 46 | ).toJSON(); |
25 | 47 | expect(avatarHasClass(componentTree, 'default-border')).toBeTruthy(); |
26 | 48 | }); |
27 | 49 |
|
28 | 50 | it('has avatar with gold border for donating users', () => { |
29 | | - const donatingUserProps = { |
30 | | - user: { |
31 | | - username: 'test-user', |
32 | | - picture: 'https://freecodecamp.org/image.png', |
33 | | - isDonating: true |
34 | | - }, |
35 | | - pending: false, |
36 | | - pathName: '/learn' |
37 | | - }; |
38 | | - |
39 | 51 | const componentTree = create( |
40 | 52 | <AuthOrProfile {...donatingUserProps} /> |
41 | 53 | ).toJSON(); |
42 | 54 | expect(avatarHasClass(componentTree, 'gold-border')).toBeTruthy(); |
43 | 55 | }); |
44 | 56 |
|
45 | 57 | it('has avatar with blue border for top contributors', () => { |
46 | | - const topContributorUserProps = { |
47 | | - user: { |
48 | | - username: 'test-user', |
49 | | - picture: 'https://freecodecamp.org/image.png', |
50 | | - yearsTopContributor: [2020] |
51 | | - }, |
52 | | - pending: false, |
53 | | - pathName: '/learn' |
54 | | - }; |
55 | | - |
56 | 58 | const componentTree = create( |
57 | 59 | <AuthOrProfile {...topContributorUserProps} /> |
58 | 60 | ).toJSON(); |
59 | 61 | expect(avatarHasClass(componentTree, 'blue-border')).toBeTruthy(); |
60 | 62 | }); |
61 | 63 |
|
62 | 64 | it('has avatar with purple border for donating top contributors', () => { |
63 | | - const topDonatingContributorUserProps = { |
64 | | - user: { |
65 | | - username: 'test-user', |
66 | | - picture: 'https://freecodecamp.org/image.png', |
67 | | - isDonating: true, |
68 | | - yearsTopContributor: [2020] |
69 | | - }, |
70 | | - pending: false, |
71 | | - pathName: '/learn' |
72 | | - }; |
73 | | - |
74 | 65 | const componentTree = create( |
75 | 66 | <AuthOrProfile {...topDonatingContributorUserProps} /> |
76 | 67 | ).toJSON(); |
77 | 68 | expect(avatarHasClass(componentTree, 'purple-border')).toBeTruthy(); |
78 | 69 | }); |
79 | 70 | }); |
80 | 71 |
|
81 | | -// eslint-disable-next-line @typescript-eslint/no-explicit-any |
82 | | -const profileNavItem = (component: any) => component.children[0]; |
| 72 | +type Component = { |
| 73 | + children: { props: { className: string } }[]; |
| 74 | +}; |
| 75 | +const profileNavItem = (component: Component) => component.children[0]; |
83 | 76 |
|
84 | 77 | const avatarHasClass = ( |
85 | 78 | componentTree: ReactTestRendererJSON | ReactTestRendererJSON[] | null, |
86 | 79 | classes: string |
87 | 80 | ) => { |
88 | 81 | return ( |
89 | | - profileNavItem(componentTree).props.className === |
| 82 | + profileNavItem(componentTree as unknown as Component).props.className === |
90 | 83 | 'avatar-container ' + classes |
91 | 84 | ); |
92 | 85 | }; |
0 commit comments