@@ -6,7 +6,12 @@ import * as Common from '../../../core/common/common.js';
66import * as SDK from '../../../core/sdk/sdk.js' ;
77import * as Bindings from '../../../models/bindings/bindings.js' ;
88import * as Workspace from '../../../models/workspace/workspace.js' ;
9- import { renderElementIntoDOM } from '../../../testing/DOMHelpers.js' ;
9+ import {
10+ dispatchBlurEvent ,
11+ dispatchFocusEvent ,
12+ dispatchInputEvent ,
13+ renderElementIntoDOM ,
14+ } from '../../../testing/DOMHelpers.js' ;
1015import { describeWithEnvironment } from '../../../testing/EnvironmentHelpers.js' ;
1116import * as Coordinator from '../../../ui/components/render_coordinator/render_coordinator.js' ;
1217
@@ -146,7 +151,7 @@ describeWithEnvironment('Ignore List Setting', () => {
146151 const newRegexInput = getNewRegexInput ( component ) ;
147152
148153 newRegexInput . value = 'rule 1' ;
149- newRegexInput . dispatchEvent ( new FocusEvent ( 'blur' ) ) ;
154+ dispatchBlurEvent ( newRegexInput ) ;
150155
151156 assert . isTrue ( isRegexInIgnoredList ( 'rule 1' ) ) ;
152157 } ) ;
@@ -159,10 +164,90 @@ describeWithEnvironment('Ignore List Setting', () => {
159164 const newRegexInput = getNewRegexInput ( component ) ;
160165
161166 newRegexInput . value = 'rule 1' ;
162- newRegexInput . dispatchEvent ( new FocusEvent ( 'blur' ) ) ;
167+ dispatchBlurEvent ( newRegexInput ) ;
163168
164169 assert . isFalse ( isIgnoreRegexDisabled ( 'rule 1' ) ) ;
165170 } ) ;
171+
172+ describe ( 'preview the result' , ( ) => {
173+ it ( 'Add an empty regex when focusing on the input' , async ( ) => {
174+ const regexPatterns = getIgnoredRegexes ( ) ;
175+ // There is a default rule `/node_modules/|/bower_components/`, and the 'rule 1' we added.
176+ assert . strictEqual ( regexPatterns . length , 2 ) ;
177+
178+ const component = await renderIgnoreListSetting ( ) ;
179+ const newRegexInput = getNewRegexInput ( component ) ;
180+
181+ dispatchFocusEvent ( newRegexInput ) ;
182+ assert . strictEqual ( regexPatterns . length , 3 ) ;
183+
184+ // We need this to simulate the 'finish editing', so it can remove the temp regex. Otherwise the future tests will
185+ // be messed up.
186+ // The 'finish editing' part will be tested later
187+ dispatchBlurEvent ( newRegexInput ) ;
188+ } ) ;
189+
190+ it ( 'Update the regex when user typing' , async ( ) => {
191+ const regexPatterns = getIgnoredRegexes ( ) ;
192+ // There is a default rule `/node_modules/|/bower_components/`, and the 'rule 1' we added.
193+ assert . strictEqual ( regexPatterns . length , 2 ) ;
194+
195+ const component = await renderIgnoreListSetting ( ) ;
196+ const newRegexInput = getNewRegexInput ( component ) ;
197+
198+ dispatchFocusEvent ( newRegexInput ) ;
199+ assert . strictEqual ( regexPatterns . length , 3 ) ;
200+ // After the focus event, the temp regex (last one) is still empty.
201+ assert . strictEqual ( regexPatterns [ 2 ] . pattern , '' ) ;
202+ // Simulate user's typing
203+ newRegexInput . value = 'r' ;
204+ dispatchInputEvent ( newRegexInput ) ;
205+ // After the input event, the temp regex (last one) is updated.
206+ assert . strictEqual ( regexPatterns [ 2 ] . pattern , 'r' ) ;
207+
208+ // We need this to simulate the 'finish editing' with empty input, so it can remove the temp regex. Otherwise the
209+ // future tests will be messed up.
210+ // The 'finish editing' part will be tested later
211+ newRegexInput . value = '' ;
212+ dispatchBlurEvent ( newRegexInput ) ;
213+ } ) ;
214+
215+ it ( 'Add the regex when user finish typing' , async ( ) => {
216+ const regexPatterns = getIgnoredRegexes ( ) ;
217+ // There is a default rule `/node_modules/|/bower_components/`, and the 'rule 1' we added.
218+ assert . strictEqual ( regexPatterns . length , 2 ) ;
219+
220+ const component = await renderIgnoreListSetting ( ) ;
221+ const newRegexInput = getNewRegexInput ( component ) ;
222+
223+ dispatchFocusEvent ( newRegexInput ) ;
224+ newRegexInput . value = 'rule 2' ;
225+ assert . strictEqual ( regexPatterns . length , 3 ) ;
226+
227+ dispatchBlurEvent ( newRegexInput ) ;
228+ // When add a valid rule, the temp regex won't be removed.
229+ assert . strictEqual ( regexPatterns . length , 3 ) ;
230+ assert . strictEqual ( regexPatterns [ 2 ] . pattern , 'rule 2' ) ;
231+ } ) ;
232+
233+ it ( 'Remove the invalid regex when user finish typing' , async ( ) => {
234+ const regexPatterns = getIgnoredRegexes ( ) ;
235+ // There is a default rule `/node_modules/|/bower_components/`, and the 'rule 1', 'rule 2' we added.
236+ assert . strictEqual ( regexPatterns . length , 3 ) ;
237+
238+ const component = await renderIgnoreListSetting ( ) ;
239+ const newRegexInput = getNewRegexInput ( component ) ;
240+
241+ dispatchFocusEvent ( newRegexInput ) ;
242+ // This is a duplicate rule, so it is invalid.
243+ newRegexInput . value = 'rule 2' ;
244+ assert . strictEqual ( regexPatterns . length , 4 ) ;
245+
246+ dispatchBlurEvent ( newRegexInput ) ;
247+ // When add an invalid rule, the temp regex will be removed.
248+ assert . strictEqual ( regexPatterns . length , 3 ) ;
249+ } ) ;
250+ } ) ;
166251} ) ;
167252
168253describeWithEnvironment ( 'Pattern validator' , ( ) => {
@@ -204,17 +289,19 @@ describeWithEnvironment('Pattern validator', () => {
204289 } ) ;
205290} ) ;
206291
292+ function getIgnoredRegexes ( ) : Common . Settings . RegExpSettingItem [ ] {
293+ return ( Common . Settings . Settings . instance ( ) . moduleSetting ( 'skip-stack-frames-pattern' ) as
294+ Common . Settings . RegExpSetting )
295+ . getAsArray ( ) ;
296+ }
297+
207298function ignoreRegex ( regexValue : string ) : void {
208- const regexPatterns =
209- ( Common . Settings . Settings . instance ( ) . moduleSetting ( 'skip-stack-frames-pattern' ) as Common . Settings . RegExpSetting )
210- . getAsArray ( ) ;
299+ const regexPatterns = getIgnoredRegexes ( ) ;
211300 regexPatterns . push ( { pattern : regexValue , disabled : false } ) ;
212301}
213302
214303function disableIgnoreRegex ( regexValue : string ) : void {
215- const regexPatterns =
216- ( Common . Settings . Settings . instance ( ) . moduleSetting ( 'skip-stack-frames-pattern' ) as Common . Settings . RegExpSetting )
217- . getAsArray ( ) ;
304+ const regexPatterns = getIgnoredRegexes ( ) ;
218305 for ( const regexPattern of regexPatterns ) {
219306 if ( regexPattern . pattern === regexValue ) {
220307 regexPattern . disabled = true ;
@@ -224,9 +311,7 @@ function disableIgnoreRegex(regexValue: string): void {
224311}
225312
226313function isIgnoreRegexDisabled ( regexValue : string ) : boolean {
227- const regexPatterns =
228- ( Common . Settings . Settings . instance ( ) . moduleSetting ( 'skip-stack-frames-pattern' ) as Common . Settings . RegExpSetting )
229- . getAsArray ( ) ;
314+ const regexPatterns = getIgnoredRegexes ( ) ;
230315 for ( const regexPattern of regexPatterns ) {
231316 if ( regexPattern . pattern === regexValue ) {
232317 return regexPattern . disabled ?? false ;
@@ -239,9 +324,7 @@ function isIgnoreRegexDisabled(regexValue: string): boolean {
239324 * Returns if the regex is in the ignore list, no matter if it is disabled.
240325 */
241326function isRegexInIgnoredList ( regexValue : string ) : boolean {
242- const regexPatterns =
243- ( Common . Settings . Settings . instance ( ) . moduleSetting ( 'skip-stack-frames-pattern' ) as Common . Settings . RegExpSetting )
244- . getAsArray ( ) ;
327+ const regexPatterns = getIgnoredRegexes ( ) ;
245328 for ( const regexPattern of regexPatterns ) {
246329 if ( regexPattern . pattern === regexValue ) {
247330 return true ;
0 commit comments