import { LOG , NGX , clear , findInput } from './functions' ; function escapeRegex ( string ) { return string . replace ( /[-\/\\^$*+?.()|[\]{}]/g , '\\$&' ) ; } function Cypress_Commands_overwrite_Subject < T extends keyof Cypress . Chainable > ( name , fn ) { Cypress . Commands . overwrite ( name , fn as any ) ; } /**
 * Overwrites `cy.select` to work with ngx-ui elements.
 */ Cypress_Commands_overwrite_Subject ( 'select' , ( originalFn , subject , text , options = { } , ... args ) => { const tagName = subject . prop ( 'tagName' ) . toLowerCase ( ) ; switch ( tagName ) { case NGX . DROPDOWN : case NGX . SELECT : if ( options . log !== false ) { Cypress . log ( { name : 'select' , $el : subject , consoleProps : ( ) => { return { Selected : text , 'Applied to' : subject , Elements : subject . length } ; } } ) ; } if ( ! Array . isArray ( text ) ) text = [ text ] ; text = text . map ( t => { if ( t instanceof RegExp ) return t ; return new RegExp ( `^\\s*${ escapeRegex ( t ) }\\s*$` , 'g' ) ; } ) ; } switch ( tagName ) { case NGX . DROPDOWN : return cy . wrap ( subject , LOG ) . ngxOpen ( LOG ) . withinEach ( ( ) => { text . forEach ( ( re ) => cy . get ( 'li' ) . contains ( re , LOG ) . click ( LOG ) ) ; } , LOG ) . ngxClose ( LOG ) ; case NGX . SELECT : return cy . wrap ( subject , LOG ) . clear ( LOG ) . ngxOpen ( LOG ) . withinEach ( ( ) => { text . forEach ( ( re ) => cy . get ( 'li' ) . contains ( re , LOG ) . click ( LOG ) ) ; } , LOG ) . ngxClose ( LOG ) ; } return originalFn ( subject , text as any , options , ... args ) ; } ) ; /**
 * Overwrites `cy.clear` to work with ngx-ui elements.
 */ Cypress_Commands_overwrite_Subject ( 'clear' , ( originalFn , subject , options = { } , ... args ) => { switch ( subject . prop ( 'tagName' ) . toLowerCase ( ) ) { case NGX . CODEMIRROR : case NGX . INPUT : case NGX . DATETIME : case NGX . SELECT : case NGX . TOGGLE : case NGX . CHECKBOX : case NGX . SLIDER : { if ( options . log !== false ) { Cypress . log ( { name : 'clear' , $el : subject , consoleProps : ( ) => { return { 'Applied to' : subject , Elements : subject . length } ; } } ) ; } return cy . wrap ( subject , LOG ) . each ( clear ) ; } } return originalFn ( subject , options , ... args ) ; } ) ; /**
 * Overwrites `cy.click` to work with ngx-ui elements.
 */ Cypress_Commands_overwrite_Subject ( 'click' , ( originalFn , subject , options ? , ... args ) => { switch ( subject . prop ( 'tagName' ) . toLowerCase ( ) ) { case NGX . TOGGLE : case NGX . CHECKBOX : return cy . wrap ( subject , LOG ) . each ( el => { originalFn ( findInput ( el ) , { ... options , force : true } , ... args ) ; } ) ; } return originalFn ( subject , options , ... args ) ; } ) ; /**
 * Overwrites `cy.check` to work with ngx-ui elements.
 */ Cypress_Commands_overwrite_Subject ( 'check' , ( originalFn , subject , options ? , ... args ) => { switch ( subject . prop ( 'tagName' ) . toLowerCase ( ) ) { case NGX . TOGGLE : case NGX . CHECKBOX : case NGX . RADIOBUTTON : return cy . wrap ( subject , LOG ) . each ( el => { originalFn ( findInput ( el ) , { ... options , force : true } ) ; } ) ; } return originalFn ( subject , options , ... args ) ; } ) ; /**
 * Overwrites `cy.uncheck` to work with ngx-ui elements.
 */ Cypress_Commands_overwrite_Subject ( 'uncheck' , ( originalFn , subject , options ? , ... args ) => { switch ( subject . prop ( 'tagName' ) . toLowerCase ( ) ) { case NGX . TOGGLE : case NGX . CHECKBOX : return cy . wrap ( subject , LOG ) . each ( el => { originalFn ( findInput ( el ) as JQuery < HTMLElement > , { ... options , force : true } , ... args ) ; } ) ; } return originalFn ( subject , options , ... args ) ; } ) ;