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'
55
66userEvent . setup ( )
77
8- it ( 'renders a preview card for the given file ' , async ( ) => {
8+ it ( 'displays the preview card' , async ( ) => {
99 render ( < FilePreview file = { new File ( [ 'hello world' ] , 'message.txt' ) } /> )
1010
11- expect ( screen . getByText ( 'message.txt' ) ) . toBeTruthy ( ) /** @todo */
11+ expect ( screen . getByText ( 'message.txt' ) ) . toBeTruthy ( )
12+ expect ( screen . getByText ( 'hello world' ) ) . toBeTruthy ( )
1213} )
Original file line number Diff line number Diff line change 11import { useEffect , useState } from 'react'
22
3- const decoder = new TextDecoder ( )
4-
53export function FilePreview ( { file } : { file : File } ) {
64 const [ previewText , setPreviewText ] = useState < string > ( )
75
86 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 )
158 } , [ file ] )
169
1710 return (
1811 < div >
1912 < div className = "w-full max-w-2xl overflow-hidden rounded-md border border-slate-200 bg-white shadow-lg shadow-slate-200" >
2013 < 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 }
2215 </ p >
2316 < pre className = "max-h-[28ch] overflow-scroll p-4" > { previewText } </ pre >
2417 </ div >
You can’t perform that action at this time.
0 commit comments