@@ -38,9 +38,9 @@ describe('Tab completion', function() {
38
38
const tabby = ( app , partial , full , expectOK = true ) => app . client . waitForExist ( ui . selectors . CURRENT_PROMPT_BLOCK )
39
39
. then ( ( ) => app . client . getAttribute ( ui . selectors . CURRENT_PROMPT_BLOCK , 'data-input-count' ) )
40
40
. then ( count => parseInt ( count ) )
41
- . then ( count => app . client . keys ( partial )
41
+ . then ( count => app . client . setValue ( ui . selectors . CURRENT_PROMPT , partial )
42
42
. then ( ( ) => app . client . waitForValue ( ui . selectors . PROMPT_N ( count ) , partial ) )
43
- . then ( ( ) => app . client . keys ( 'Tab' ) )
43
+ . then ( ( ) => app . client . setValue ( ui . selectors . CURRENT_PROMPT , ` ${ partial } ${ keys . TAB } ` ) )
44
44
. then ( ( ) => app . client . waitForValue ( ui . selectors . PROMPT_N ( count ) , full ) ) )
45
45
. then ( ( ) => cli . do ( '' , app ) )
46
46
. then ( data => {
@@ -52,65 +52,74 @@ describe('Tab completion', function() {
52
52
} )
53
53
. catch ( common . oops ( this ) ) ;
54
54
55
- const tabbyWithOptions = ( app , partial , expected , full , { click, nTabs, expectOK= true } = { } ) => app . client . waitForExist ( ui . selectors . CURRENT_PROMPT_BLOCK )
56
- . then ( ( ) => app . client . getAttribute ( ui . selectors . CURRENT_PROMPT_BLOCK , 'data-input-count' ) )
57
- . then ( count => parseInt ( count ) )
58
- . then ( count => app . client . keys ( partial )
59
- . then ( ( ) => app . client . waitForValue ( ui . selectors . PROMPT_N ( count ) , partial ) )
60
- . then ( ( ) => app . client . keys ( 'Tab' ) )
61
- . then ( ( ) => {
62
- if ( ! expected ) {
63
- // then we expect non-visibility of the tab-completion popup
64
- // console.error('Expecting non-existence of popup')
65
- return app . client . waitForVisible ( `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .clickable` , 20000 , true )
66
- . then ( ( ) => {
67
- // great, the tab completion popup does not exist; early exit
68
- const err = new Error ( )
69
- err . failedAsExpected = true
70
- throw err
71
- } )
72
- } else {
73
- const selector = `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .clickable`
74
- // console.error('Expecting existence of popup', selector)
75
- return app . client . waitForVisible ( selector , 20000 )
76
- }
77
- } )
78
- . then ( ( ) => app . client . getText ( `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .clickable` ) )
79
- . then ( ui . expectArray ( expected ) )
80
- // .then(() => { console.error('Got expected options') })
81
- . then ( ( ) => {
82
- if ( click !== undefined ) {
83
- // click on a row
84
- const selector = `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .tab-completion-option[data-value="${ expected [ click ] } "] .clickable`
85
- console . error ( 'clicking' , click , selector )
86
- return app . client . waitForVisible ( selector , 20000 )
87
- . then ( ( ) => app . client . click ( selector ) )
88
- } else {
89
- // otherwise hit tab a number of times, to cycle to the desired entry
90
- console . error ( 'tabbing' , nTabs )
91
- return doTimes ( nTabs , ( ) => app . client . keys ( 'Tab' ) )
92
- . then ( ( ) => app . client . keys ( 'Enter' ) )
93
- }
94
- } )
95
- . then ( ( ) => app . client . waitForVisible ( `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary` , 20000 , true ) ) // wait for non-existence of the temporary
96
- . then ( ( ) => app . client . waitForValue ( ui . selectors . PROMPT_N ( count ) , full ) ) )
97
- . then ( ( ) => cli . do ( '' , app ) )
98
- . then ( data => {
99
- if ( expectOK ) {
100
- return cli . expectJustOK ( data )
101
- } else {
102
- return app
103
- }
104
- } )
105
- . catch ( err => this . app . client . execute ( 'repl.doCancel()' ) // clear the line
106
- . then ( ( ) => common . oops ( this ) ( err ) ) )
55
+ const tabbyWithOptions = ( app , partial , expected , full , { click, nTabs, expectOK= true , iter= 0 } = { } ) => {
56
+ return app . client . waitForExist ( ui . selectors . CURRENT_PROMPT_BLOCK )
57
+ . then ( ( ) => app . client . getAttribute ( ui . selectors . CURRENT_PROMPT_BLOCK , 'data-input-count' ) )
58
+ . then ( count => parseInt ( count ) )
59
+ . then ( count => app . client . setValue ( ui . selectors . CURRENT_PROMPT , partial )
60
+ . then ( ( ) => app . client . waitForValue ( ui . selectors . PROMPT_N ( count ) , partial ) )
61
+ . then ( ( ) => app . client . setValue ( ui . selectors . CURRENT_PROMPT , `${ partial } ${ keys . TAB } ` ) )
62
+ . then ( ( ) => {
63
+ if ( ! expected ) {
64
+ // then we expect non-visibility of the tab-completion popup
65
+ // console.error('Expecting non-existence of popup')
66
+ return app . client . waitForVisible ( `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .clickable` , 10000 , true )
67
+ . then ( ( ) => {
68
+ // great, the tab completion popup does not exist; early exit
69
+ const err = new Error ( )
70
+ err . failedAsExpected = true
71
+ throw err
72
+ } )
73
+ } else {
74
+ const selector = `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .clickable`
75
+ // console.error('Expecting existence of popup', selector)
76
+ return app . client . waitForVisible ( selector , 10000 )
77
+ }
78
+ } )
79
+ . then ( ( ) => app . client . getText ( `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .clickable` ) )
80
+ . then ( ui . expectArray ( expected ) )
81
+ // .then(() => { console.error('Got expected options') })
82
+ . then ( ( ) => {
83
+ if ( click !== undefined ) {
84
+ // click on a row
85
+ const selector = `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .tab-completion-option[data-value="${ expected [ click ] } "] .clickable`
86
+ // console.error('clicking', click, selector)
87
+ return app . client . waitForVisible ( selector , 10000 )
88
+ . then ( ( ) => app . client . click ( selector ) )
89
+ } else {
90
+ // otherwise hit tab a number of times, to cycle to the desired entry
91
+ // console.error('tabbing', nTabs)
92
+ return doTimes ( nTabs , ( ) => app . client . keys ( 'Tab' ) )
93
+ . then ( ( ) => app . client . keys ( 'Enter' ) )
94
+ }
95
+ } )
96
+ . then ( ( ) => app . client . waitForVisible ( `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary` , 8000 , true ) ) // wait for non-existence of the temporary
97
+ . then ( ( ) => app . client . waitForValue ( ui . selectors . PROMPT_N ( count ) , full ) ) )
98
+ . then ( ( ) => cli . do ( '' , app ) )
99
+ . then ( data => {
100
+ if ( expectOK ) {
101
+ return cli . expectJustOK ( data )
102
+ } else {
103
+ return app
104
+ }
105
+ } )
106
+ . catch ( err => this . app . client . execute ( 'repl.doCancel()' ) // clear the line
107
+ . then ( ( ) => {
108
+ if ( iter < 5 ) {
109
+ console . error ( 'retry' , iter )
110
+ return tabbyWithOptions ( app , partial , expected , full , { click, nTabs, expectOK, iter : iter + 1 } )
111
+ } else {
112
+ return common . oops ( this ) ( err )
113
+ }
114
+ } ) )
115
+ }
107
116
108
117
const tabbyWithOptionsThenCancel = ( app , partial , expected ) => app . client . waitForExist ( ui . selectors . CURRENT_PROMPT_BLOCK )
109
118
. then ( ( ) => app . client . getAttribute ( ui . selectors . CURRENT_PROMPT_BLOCK , 'data-input-count' ) )
110
119
. then ( count => parseInt ( count ) )
111
- . then ( count => app . client . keys ( partial )
120
+ . then ( count => app . client . setValue ( ui . selectors . CURRENT_PROMPT , partial )
112
121
. then ( ( ) => app . client . waitForValue ( ui . selectors . PROMPT_N ( count ) , partial ) )
113
- . then ( ( ) => app . client . keys ( 'Tab' ) )
122
+ . then ( ( ) => app . client . setValue ( ui . selectors . CURRENT_PROMPT , ` ${ partial } ${ keys . TAB } ` ) )
114
123
. then ( ( ) => app . client . waitForVisible ( `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .clickable` ) )
115
124
. then ( ( ) => app . client . getText ( `${ ui . selectors . PROMPT_BLOCK_N ( count ) } .tab-completion-temporary .clickable` ) )
116
125
. then ( ui . expectArray ( expected ) )
@@ -121,6 +130,13 @@ describe('Tab completion', function() {
121
130
122
131
it ( 'should have an active repl' , ( ) => cli . waitForRepl ( this . app ) )
123
132
133
+ // tab completion with options, then click on the second (idx=1) entry of the expected cmpletion list
134
+ it ( 'should tab complete local file path' , ( ) => tabbyWithOptions ( this . app ,
135
+ 'lls data/com' ,
136
+ options ,
137
+ 'lls data/composer-source/' ,
138
+ { click : 1 } ) )
139
+
124
140
it ( 'should tab complete the data directory' , ( ) => tabby ( this . app , 'lls da' , 'lls data/' ) )
125
141
it ( 'should tab complete the data/fsm.js file' , ( ) => tabby ( this . app , 'lls data/fsm.js' , 'lls data/fsm.json' ) )
126
142
it ( 'should tab complete the ../app directory' , ( ) => tabby ( this . app , 'lls ../ap' , 'lls ../app/' ) )
@@ -130,13 +146,6 @@ describe('Tab completion', function() {
130
146
'composer-source-expect-errors/' ,
131
147
'composer-wookiechat/' ]
132
148
133
- // tab completion with options, then click on the second (idx=1) entry of the expected cmpletion list
134
- it ( 'should tab complete local file path' , ( ) => tabbyWithOptions ( this . app ,
135
- 'lls data/com' ,
136
- options ,
137
- 'lls data/composer-source/' ,
138
- { click : 1 } ) )
139
-
140
149
// same, but this time tab to cycle through the options
141
150
it ( 'should tab complete local file path' , ( ) => tabbyWithOptions ( this . app ,
142
151
'lls data/com' ,
0 commit comments