import { fillValue , findInput , findLabel , getValue , iff , LOG , NGX , setValue , open , close , getByLabel , getByPlaceholder } from './functions' ; function Cypress_Commands_add_Subject < T extends keyof Cypress . Chainable > ( name , options , fn ) { Cypress . Commands . add ( name , options , fn ) ; } /**
 * Find element by name attribute.
 */ Cypress . Commands . add ( 'getByName' , ( name , options = { } ) => { return cy . get ( `*[name="${ name }"]` , options ) ; } ) ; /**
 * Find element by label attribute.
 */ Cypress . Commands . add ( 'getByLabel' , ( label , options ) => { options = { log : true , withinSubject : cy [ 'state' ] ( 'withinSubject' ) , ... options } ; const $el = getByLabel ( label , options ) as JQuery < any > ; if ( options . log ) { Cypress . log ( { name : 'getByLabel' , message : label , $el , consoleProps : ( ) => { return { Yielded : $el , Elements : $el ?. length , Label : label } ; } } ) ; } return cy . wrap ( $el , LOG ) ; } ) ; /**
 * Find element by placeholder text.
 */ Cypress . Commands . add ( 'getByPlaceholder' , ( text , options ) => { options = { log : true , withinSubject : cy [ 'state' ] ( 'withinSubject' ) , ... options } ; const $el = getByPlaceholder ( text , options ) as JQuery < any > ; if ( options . log ) { Cypress . log ( { name : 'getByPlaceholder' , message : text , $el , consoleProps : ( ) => { return { Yielded : $el , Elements : $el ?. length , Placeholder : text } ; } } ) ; } return cy . wrap ( $el , LOG ) ; } ) ; /**
 * Like `cy.within`, but for each element.
 */ Cypress_Commands_add_Subject ( 'withinEach' , { prevSubject : 'element' } , ( subject , fn , options ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'withinEach' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length } ; } } ) ; } subject . each ( ( _ , element ) => { cy . wrap ( element , LOG ) . within ( LOG , fn ) ; } ) ; return cy . wrap ( subject , LOG ) ; } ) ; Cypress_Commands_add_Subject ( 'ngxHover' , { prevSubject : 'element' } , ( subject , options ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'hover' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length } ; } } ) ; } return cy . wrap ( subject , LOG ) . trigger ( 'mouseover' , LOG ) . trigger ( 'mouseenter' , LOG ) . invoke ( LOG , 'addClass' , 'cy-hover' ) ; } ) ; Cypress_Commands_add_Subject ( 'ngxUnhover' , { prevSubject : 'element' } , ( subject , options ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'unhover' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length } ; } } ) ; } return cy . wrap ( subject , LOG ) . invoke ( LOG , 'removeClass' , 'cy-hover' ) . trigger ( 'mouseleave' , LOG ) . trigger ( 'mouseout' , LOG ) ; } ) ; /**
 * Like `cy.within` but also forces the element into a hover state.
 */ Cypress_Commands_add_Subject ( 'whileHovering' , { prevSubject : 'element' } , ( subject , fn , options ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'whileHovering' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length } ; } } ) ; } cy . wrap ( subject , LOG ) . ngxHover ( LOG ) . within ( LOG , fn ) . iff ( undefined , $el => { return cy . wrap ( $el , LOG ) . ngxUnhover ( LOG ) ; } , LOG ) ; return cy . wrap ( subject , LOG ) ; } ) ; /**
 * Like `cy.within` but only if the element exists in the DOM.
 */ Cypress_Commands_add_Subject ( 'iff' , { prevSubject : true } , ( subject , selector , fn , options ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'iff' , $el : subject , message : selector , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length , Selector : selector } ; } } ) ; } iff ( subject , selector , fn ) ; return cy . wrap ( subject , LOG ) ; } ) ; /**
 * Set ngx-ui-testing debug mode.
 */ Cypress . Commands . add ( 'ngxDebug' , ( value ) : any => { LOG . log = value ; } ) ; /**
 * Given an ngx-ui element, returns the child native input element.
 */ Cypress_Commands_add_Subject ( 'ngxFindNativeInput' , { prevSubject : 'element' } , ( subject , options = { } ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; const $el = findInput ( subject ) ; if ( options . log ) { Cypress . log ( { name : 'ngxFindNativeInput' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length , Yielded : $el } ; } } ) ; } return cy . wrap ( $el , LOG ) ; } ) ; /**
 * Given an element, returns the label element.
 */ Cypress_Commands_add_Subject ( 'ngxFindLabel' , { prevSubject : 'element' } , ( subject , options = { } ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; const $el = findLabel ( subject ) ; if ( options . log ) { Cypress . log ( { name : 'ngxFindLabel' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length , Yielded : $el } ; } } ) ; } return cy . wrap ( $el ) ; } ) ; /**
 * Close all ngx-ui notifications, if any.
 */ Cypress . Commands . add ( 'ngxCloseNotifications' , ( ) => { return cy . get ( 'ngx-notification-container' ) . iff ( '.ngx-notification-close' , $el => $el . trigger ( 'click' ) ) ; } ) ; Cypress_Commands_add_Subject ( 'ngxOpen' , { prevSubject : 'element' } , ( subject , options = { } ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'ngxOpen' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length } ; } } ) ; } switch ( subject . prop ( 'tagName' ) . toLowerCase ( ) ) { case NGX . SELECT : case NGX . SECTION : case NGX . DROPDOWN : case NGX . PLUS_MENU : case NGX . NAG : return cy . wrap ( subject , LOG ) . withinEach ( open , LOG ) ; } return ; } ) ; Cypress_Commands_add_Subject ( 'ngxClose' , { prevSubject : 'element' } , ( subject , options = { } ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'ngxClose' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length } ; } } ) ; } switch ( subject . prop ( 'tagName' ) . toLowerCase ( ) ) { case NGX . SELECT : case NGX . SECTION : case NGX . DROPDOWN : case NGX . PLUS_MENU : case NGX . LFD : case NGX . NOTIFICATION : case NGX . NAG : case NGX . ALERT : case NGX . DRAWER : return cy . wrap ( subject , LOG ) . withinEach ( close , LOG ) ; } return ; } ) ; /**
 * Like `cy.type` but clears existing text before and works with ngx-ui elements.
 */ Cypress_Commands_add_Subject ( 'ngxFill' , { prevSubject : 'element' } , ( subject , text ? , options = { } ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'ngxFill' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length , text } ; } } ) ; } return cy . wrap ( subject , LOG ) . each ( el => fillValue ( el , text , options ) ) ; } ) ; /**
 * Given an element, returns the element's value.
 */ Cypress_Commands_add_Subject ( 'ngxGetValue' , { prevSubject : 'element' } , ( subject , options = { } ) : Cypress . Chainable < string | number | string [ ] | undefined | boolean > => { options = { log : true , ... options } ; const value = getValue ( subject ) ; if ( options . log ) { Cypress . log ( { name : 'ngxGetValue' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length , Returned : value } ; } } ) ; } return cy . wrap ( value ) ; } ) ; /**
 * Set an elements value directly
 */ Cypress_Commands_add_Subject ( 'ngxSetValue' , { prevSubject : 'element' } , ( subject , text ? , options = { } ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'ngxSetValue' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length , Value : text } ; } } ) ; } return cy . wrap ( subject , LOG ) . each ( el => setValue ( el , text ) ) ; } ) ; Cypress_Commands_add_Subject ( 'ngxSelectTab' , { prevSubject : 'element' } , ( subject , textOrIndex , options = { } ) : Cypress . Chainable < JQuery < Element > > => { options = { log : true , ... options } ; if ( options . log ) { Cypress . log ( { name : 'ngxSelectTab' , $el : subject , consoleProps : ( ) => { return { 'Applied To' : subject , Elements : subject ?. length } ; } } ) ; } switch ( subject . prop ( 'tagName' ) . toLowerCase ( ) ) { case NGX . TABS : return cy . wrap ( subject , LOG ) . withinEach ( ( ) => { if ( typeof textOrIndex === 'number' ) { cy . get ( '.ngx-tabs-list button.ngx-tab' ) . eq ( textOrIndex ) . click ( ) ; } else { cy . get ( '.ngx-tabs-list button.ngx-tab' ) . contains ( textOrIndex ) . click ( ) ; } } , LOG ) ; } return ; } ) ;