22 * @jest -environment jsdom
33 */
44import React from 'react'
5- import { screen , setup , render , t , waitFor } from 'rtl'
5+ import { screen , setup , render , t } from 'rtl'
66import { Statusbar } from '../Statusbar'
77import { filterFiles , filterDirs } from '$src/utils/fileUtils'
8- import { File } from '$src/services/Fs'
98import { ViewState } from '$src/state/viewState'
10- import { FileState } from '$src/state/fileState'
11- import { action , makeObservable , observable , runInAction } from 'mobx'
9+ import { vol } from 'memfs'
1210
1311describe ( 'Statusbar' , ( ) => {
14- const cache = makeObservable (
12+ vol . fromJSON (
1513 {
16- status : 'ok' ,
17- files : observable < File > ( [ ] ) ,
18- setShowHiddenFiles : jest . fn ( ( show : boolean ) => {
19- cache . showHiddenFiles = show
20- } ) ,
21- showHiddenFiles : false ,
22- path : '/tmp' ,
23- } as unknown as FileState ,
24- {
25- path : observable ,
26- showHiddenFiles : observable ,
27- setShowHiddenFiles : action ,
14+ dir1 : null ,
15+ foo1 : '' ,
16+ foo2 : '' ,
17+ '.hidden' : '' ,
2818 } ,
19+ '/virtual' ,
2920 )
3021
3122 const options = {
3223 providerProps : {
33- viewState : {
34- getVisibleCache : ( ) => cache ,
35- } as unknown as ViewState ,
24+ viewState : new ViewState ( 0 ) ,
3625 } ,
3726 }
3827
3928 const buildStatusBarText = ( ) => {
29+ const cache = options . providerProps . viewState . getVisibleCache ( )
4030 const files = filterFiles ( cache . files , cache . showHiddenFiles ) . length
4131 const folders = filterDirs ( cache . files , cache . showHiddenFiles ) . length
32+
4233 return `${ t ( 'STATUS.FILES' , { count : files } ) } , ${ t ( 'STATUS.FOLDERS' , {
4334 count : folders ,
4435 } ) } `
4536 }
4637
47- beforeEach ( ( ) => {
48- cache . status = 'ok'
49- cache . showHiddenFiles = false
50- cache . files . replace ( [
51- {
52- fullname : 'dir1' ,
53- isDir : true ,
54- } as unknown as File ,
55- {
56- fullname : 'foo1' ,
57- isDir : false ,
58- } as unknown as File ,
59- {
60- fullname : '.foo2' ,
61- isDir : false ,
62- } as unknown as File ,
63- ] )
38+ beforeEach ( async ( ) => {
39+ options . providerProps . viewState = new ViewState ( 0 )
40+ const cache = options . providerProps . viewState . addCache ( '/virtual' , - 1 , true )
41+ await cache . openDirectory ( { dir : '/virtual' , fullname : '' } )
6442
6543 jest . clearAllMocks ( )
6644 } )
@@ -81,7 +59,7 @@ describe('Statusbar', () => {
8159 } )
8260
8361 it ( 'toggle hidden files button should be hidden if file cache is not valid' , ( ) => {
84- cache . status = 'busy'
62+ options . providerProps . viewState . getVisibleCache ( ) . setStatus ( 'busy' )
8563 render ( < Statusbar /> , options )
8664
8765 expect ( screen . queryByRole ( 'button' ) ) . not . toBeInTheDocument ( )
0 commit comments