@@ -24,9 +24,9 @@ class ToggleModel {
24
24
if ( isEnabled ) {
25
25
cy . wrap ( test ) . find ( ".toggle input" ) . should ( "be.enabled" ) ;
26
26
} else if ( inputAttr == 'disabled' ) {
27
- cy . wrap ( test ) . find ( 'input' ) . should ( 'be.disabled' ) . and ( 'not.have.attr' , 'readonly' ) ;
27
+ cy . wrap ( test ) . find ( '.toggle input' ) . should ( 'be.disabled' ) . and ( 'not.have.attr' , 'readonly' ) ;
28
28
} else if ( inputAttr == 'readonly' ) {
29
- cy . wrap ( test ) . find ( 'input' ) . should ( 'be.enabled' ) . and ( 'have.attr' , 'readonly' ) ;
29
+ cy . wrap ( test ) . find ( '.toggle input' ) . should ( 'be.enabled' ) . and ( 'have.attr' , 'readonly' ) ;
30
30
} else {
31
31
throw new Error ( "Test fail. Argument not supported for inputAttr " + inputAttr ) ;
32
32
}
@@ -40,6 +40,35 @@ class ToggleModel {
40
40
CYPRESS ISSUE 22750 (https://github.com/cypress-io/cypress/issues/22750)*/
41
41
} ) ;
42
42
}
43
+ /**
44
+ * Check a Keypress with focused toggle
45
+ * @param {Chainable<JQuery<HTMLElementTagNameMap[K]>> } test : test element
46
+ * @param {Boolean } isEnabled: Toggle enabled (Y/N)
47
+ * @param {String } inputAttr: input attribute for disabled toggle [disabled (default) or readonly]
48
+ * @static
49
+ */
50
+ static checkToggleKeypress ( test , isEnabled , inputAttr = 'disabled' ) {
51
+ let prevState = test . find ( ".toggle input" ) . is ( "[checked]" ) ;
52
+
53
+ if ( isEnabled ) {
54
+ cy . wrap ( test ) . find ( ".toggle input" ) . should ( "be.enabled" ) ;
55
+ } else if ( inputAttr == 'disabled' ) {
56
+ cy . wrap ( test ) . find ( '.toggle input' ) . should ( 'be.disabled' ) . and ( 'not.have.attr' , 'readonly' ) ;
57
+ } else if ( inputAttr == 'readonly' ) {
58
+ cy . wrap ( test ) . find ( '.toggle input' ) . should ( 'be.enabled' ) . and ( 'have.attr' , 'readonly' ) ;
59
+ } else {
60
+ throw new Error ( "Test fail. Argument not supported for inputAttr " + inputAttr ) ;
61
+ }
62
+
63
+ cy . wrap ( test ) . find ( ".toggle" ) . focus ( ) . type ( ' ' ) . then ( ( ) => {
64
+ let isChecked = ( isEnabled && ! prevState ) || ( ! isEnabled && prevState ) ;
65
+ cy . wrap ( test ) . find ( ".toggle input" ) . should ( isChecked ? "be.checked" : "not.be.checked" ) ;
66
+ cy . wrap ( test ) . find ( ".toggle" ) . should ( isChecked ? "not.have.class" : "have.class" , "off" ) ;
67
+ /*cy.wrap(test).find(isChecked ? '.toggle-on' : '.toggle-off').should('be.visible');
68
+ cy.wrap(test).find(isChecked ? '.toggle-off' : '.toggle-on').should('not.be.visible');
69
+ CYPRESS ISSUE 22750 (https://github.com/cypress-io/cypress/issues/22750)*/
70
+ } ) ;
71
+ }
43
72
44
73
/**
45
74
* Check a toggle base on the toggle options
0 commit comments