File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { screen , render , fireEvent } from '@testing-library/react' ;
2
+ import '@testing-library/jest-dom/extend-expect' ;
3
+ import NavBar from '../src/pages/components/NavBar' ;
4
+
5
+ describe ( 'Navbar Component Test ' , ( ) => {
6
+ beforeEach ( ( ) => {
7
+ render ( < NavBar /> )
8
+ } ) ;
9
+
10
+ it ( 'navbar should have two buttons(anchor tags)' , ( ) => {
11
+ const buttons = screen . getAllByRole ( 'link' ) ;
12
+ expect ( buttons ) . toHaveLength ( 2 )
13
+ } ) ;
14
+
15
+ it ( 'clicking a post link navigates to the correct URL' , ( ) => {
16
+ expect ( screen . getAllByRole ( 'link' ) [ 0 ] ) . toHaveAttribute ( 'href' , 'http://github.com/open-source-labs/reactime' ) ;
17
+ expect ( screen . getAllByRole ( 'link' ) [ 1 ] ) . toHaveAttribute ( 'href' , 'https://chrome.google.com/webstore/detail/reactime/cgibknllccemdnfhfpmjhffpjfeidjga?hl=en-US' ) ;
18
+ } )
19
+ } )
Original file line number Diff line number Diff line change
1
+ import { screen , render } from '@testing-library/react' ;
2
+ import '@testing-library/jest-dom/extend-expect' ;
3
+ import { Profile } from '../src/pages/components/TeamSection' ;
4
+
5
+ // http://localhost/_next/image?url=https%3A%2F%2Fgithub.com%2Fwiltonlee948.png&w=256&q=75
6
+
7
+ test ( 'sets src to /profileFallback.png if src causes an error' , async ( ) => {
8
+ render ( < Profile key = '' profile = 'qcvber' name = '' /> ) ;
9
+ const src = screen . getByTestId ( 'image' ) . getAttribute ( 'src' ) ;
10
+ console . debug ( src )
11
+ } ) ;
Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ function replace(e: React.SyntheticEvent<HTMLImageElement>): void{
112
112
profile : string | undefined ,
113
113
name : string | undefined ,
114
114
}
115
- function Profile ( { profile, name} : profileType ) {
115
+ export function Profile ( { profile, name} : profileType ) {
116
116
const [ imageError , setImageError ] = useState ( false ) ;
117
117
return (
118
118
< div className = "space-y-4" >
@@ -123,6 +123,7 @@ function replace(e: React.SyntheticEvent<HTMLImageElement>): void{
123
123
className = "mx-auto h-20 w-20 rounded-full lg:h-24 lg:w-24"
124
124
onError = { ( e ) => setImageError ( true ) }
125
125
alt = "missing-profile-image"
126
+ data-testid = "image"
126
127
/>
127
128
< div className = "space-y-2" >
128
129
< div className = "text-xs font-medium lg:text-sm" >
You can’t perform that action at this time.
0 commit comments