33const test = require ( 'tape' ) ;
44const diff = require ( 'sinon-called-with-diff' ) ;
55const sinon = diff ( require ( 'sinon' ) ) ;
6- const dir = '../../../client/key/' ;
6+ const dir = '../../../../ client/key/' ;
77const KEY = require ( dir + 'key' ) ;
88
9- initGlobals ( ) ;
9+ const {
10+ getDOM,
11+ getCloudCmd,
12+ } = require ( './globals' ) ;
13+
14+ global . DOM = global . DOM || getDOM ( ) ;
15+ global . CloudCmd = global . CloudCmd || getCloudCmd ( ) ;
1016
1117const DOM = global . DOM ;
1218const Buffer = DOM . Buffer ;
@@ -349,8 +355,8 @@ test('cloudcmd: client: key: Enter', (t) => {
349355
350356 const setCurrentFile = sinon . stub ( ) ;
351357
352- global . DOM . CurrentInfo . element = element ;
353- global . DOM . setCurrentFile = setCurrentFile ;
358+ DOM . CurrentInfo . element = element ;
359+ DOM . setCurrentFile = setCurrentFile ;
354360
355361 vim ( '' , {
356362 keyCode : KEY . ENTER
@@ -363,32 +369,60 @@ test('cloudcmd: client: key: Enter', (t) => {
363369 t . end ( ) ;
364370} ) ;
365371
366- function initGlobals ( ) {
367- const CurrentInfo = {
368- element : { } ,
369- } ;
372+ test ( 'cloudcmd: client: key: /' , ( t ) => {
373+ const preventDefault = sinon . stub ( ) ;
374+ const element = { } ;
370375
371- const noop = ( ) => { } ;
372- const Buffer = {
373- copy : noop ,
374- } ;
376+ DOM . CurrentInfo . element = element ;
377+ DOM . getCurrentName = ( ) => '' ;
375378
376- global . DOM = {
377- Buffer,
378- CurrentInfo,
379- selectFile : noop ,
380- unselectFile : noop ,
381- unselectFiles : noop ,
382- setCurrentFile : noop ,
383- toggleSelectedFile : noop ,
384- } ;
379+ vim ( '/' , {
380+ preventDefault
381+ } ) ;
385382
386- const show = ( ) => { } ;
383+ t . ok ( preventDefault . calledWith ( ) , 'should call preventDefault' ) ;
384+ t . end ( ) ;
385+ } ) ;
386+
387+ test ( 'cloudcmd: client: key: n' , ( t ) => {
388+ const findNext = sinon . stub ( ) ;
387389
388- global . CloudCmd = {
389- Operation : {
390- show
391- }
392- } ;
390+ clean ( dir + 'vim' ) ;
391+ stub ( dir + 'vim/find' , {
392+ findNext
393+ } ) ;
394+
395+ const vim = require ( dir + 'vim' ) ;
396+ const event = { } ;
397+
398+ vim ( 'n' , event ) ;
399+
400+ t . ok ( findNext . calledWith ( ) , 'should call findNext' ) ;
401+ t . end ( ) ;
402+ } ) ;
403+
404+ test ( 'cloudcmd: client: key: N' , ( t ) => {
405+ const findPrevious = sinon . stub ( ) ;
406+
407+ clean ( dir + 'vim' ) ;
408+ stub ( dir + 'vim/find' , {
409+ findPrevious,
410+ } ) ;
411+
412+ const vim = require ( dir + 'vim' ) ;
413+ const event = { } ;
414+
415+ vim ( 'N' , event ) ;
416+
417+ t . ok ( findPrevious . calledWith ( ) , 'should call findPrevious' ) ;
418+ t . end ( ) ;
419+ } ) ;
420+
421+ function clean ( path ) {
422+ delete require . cache [ require . resolve ( path ) ] ;
423+ }
424+
425+ function stub ( name , fn ) {
426+ require . cache [ require . resolve ( name ) ] . exports = fn ;
393427}
394428
0 commit comments