File tree Expand file tree Collapse file tree 2 files changed +5
-11
lines changed
exercises/01.sunsetting-jsdom/01.problem.write-a-test/src Expand file tree Collapse file tree 2 files changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,9 @@ import { FilePreview } from './file-preview.tsx'
5
5
6
6
userEvent . setup ( )
7
7
8
- it ( 'renders a preview card for the given file ' , async ( ) => {
8
+ it ( 'displays the preview card' , async ( ) => {
9
9
render ( < FilePreview file = { new File ( [ 'hello world' ] , 'message.txt' ) } /> )
10
10
11
- expect ( screen . getByText ( 'message.txt' ) ) . toBeTruthy ( ) /** @todo */
11
+ expect ( screen . getByText ( 'message.txt' ) ) . toBeTruthy ( )
12
+ expect ( screen . getByText ( 'hello world' ) ) . toBeTruthy ( )
12
13
} )
Original file line number Diff line number Diff line change 1
1
import { useEffect , useState } from 'react'
2
2
3
- const decoder = new TextDecoder ( )
4
-
5
3
export function FilePreview ( { file } : { file : File } ) {
6
4
const [ previewText , setPreviewText ] = useState < string > ( )
7
5
8
6
useEffect ( ( ) => {
9
- const getFilePreview = async ( ) => {
10
- const buffer = await file . arrayBuffer ( )
11
- const previewText = decoder . decode ( buffer )
12
- setPreviewText ( previewText )
13
- }
14
- getFilePreview ( )
7
+ file . text ( ) . then ( setPreviewText )
15
8
} , [ file ] )
16
9
17
10
return (
18
11
< div >
19
12
< div className = "w-full max-w-2xl overflow-hidden rounded-md border border-slate-200 bg-white shadow-lg shadow-slate-200" >
20
13
< p className = "border-b border-slate-200 bg-slate-50 px-4 py-2 font-bold text-slate-600" >
21
- 📄 { file . name }
14
+ { file . name }
22
15
</ p >
23
16
< pre className = "max-h-[28ch] overflow-scroll p-4" > { previewText } </ pre >
24
17
</ div >
You can’t perform that action at this time.
0 commit comments