|
1 | | - |
2 | 1 | describe('Value Accessors', () => { |
3 | 2 |
|
4 | 3 | describe('Checkbox', () => { |
@@ -147,4 +146,79 @@ describe('Value Accessors', () => { |
147 | 146 | }); |
148 | 147 | }); |
149 | 148 |
|
| 149 | + describe('Input OTP', () => { |
| 150 | + beforeEach(() => cy.visit('/standalone/value-accessors/input-otp')); |
| 151 | + |
| 152 | + it('should update the form value', () => { |
| 153 | + cy.get('#formValue').should('have.text', JSON.stringify({ |
| 154 | + inputOtpString: '', |
| 155 | + inputOtpNumber: '' |
| 156 | + }, null, 2)); |
| 157 | + cy.get('ion-input-otp[formControlName="inputOtpString"]').should('have.class', 'ion-pristine'); |
| 158 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"]').should('have.class', 'ion-pristine'); |
| 159 | + |
| 160 | + cy.get('ion-input-otp[formControlName="inputOtpString"]').should('have.class', 'ion-invalid'); |
| 161 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"]').should('have.class', 'ion-invalid'); |
| 162 | + |
| 163 | + // Type into the string OTP input |
| 164 | + cy.get('ion-input-otp[formControlName="inputOtpString"] input').eq(0).type('a'); |
| 165 | + cy.get('ion-input-otp[formControlName="inputOtpString"] input').eq(1).type('b'); |
| 166 | + cy.get('ion-input-otp[formControlName="inputOtpString"] input').eq(2).type('c'); |
| 167 | + cy.get('ion-input-otp[formControlName="inputOtpString"] input').eq(3).type('d'); |
| 168 | + cy.get('ion-input-otp[formControlName="inputOtpString"] input').eq(3).blur(); |
| 169 | + |
| 170 | + // Type into the number OTP input |
| 171 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"] input').eq(0).type('1'); |
| 172 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"] input').eq(1).type('2'); |
| 173 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"] input').eq(2).type('3'); |
| 174 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"] input').eq(3).type('4'); |
| 175 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"] input').eq(3).blur(); |
| 176 | + |
| 177 | + cy.get('#formValue').should('have.text', JSON.stringify({ |
| 178 | + inputOtpString: 'abcd', |
| 179 | + inputOtpNumber: 1234 |
| 180 | + }, null, 2)); |
| 181 | + |
| 182 | + cy.get('ion-input-otp[formControlName="inputOtpString"]').should('have.class', 'ion-dirty'); |
| 183 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"]').should('have.class', 'ion-dirty'); |
| 184 | + |
| 185 | + cy.get('ion-input-otp[formControlName="inputOtpString"]').should('have.class', 'ion-valid'); |
| 186 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"]').should('have.class', 'ion-valid'); |
| 187 | + }); |
| 188 | + |
| 189 | + it('should remain invalid when partially filled', () => { |
| 190 | + cy.get('#formValue').should('have.text', JSON.stringify({ |
| 191 | + inputOtpString: '', |
| 192 | + inputOtpNumber: '' |
| 193 | + }, null, 2)); |
| 194 | + cy.get('ion-input-otp[formControlName="inputOtpString"]').should('have.class', 'ion-pristine'); |
| 195 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"]').should('have.class', 'ion-pristine'); |
| 196 | + |
| 197 | + cy.get('ion-input-otp[formControlName="inputOtpString"]').should('have.class', 'ion-invalid'); |
| 198 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"]').should('have.class', 'ion-invalid'); |
| 199 | + |
| 200 | + // Type only 2 characters into the string OTP input |
| 201 | + cy.get('ion-input-otp[formControlName="inputOtpString"] input').eq(0).type('a'); |
| 202 | + cy.get('ion-input-otp[formControlName="inputOtpString"] input').eq(1).type('b'); |
| 203 | + cy.get('ion-input-otp[formControlName="inputOtpString"] input').eq(2).blur(); |
| 204 | + |
| 205 | + // Type only 2 characters into the number OTP input |
| 206 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"] input').eq(0).type('1'); |
| 207 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"] input').eq(1).type('2'); |
| 208 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"] input').eq(2).blur(); |
| 209 | + |
| 210 | + cy.get('#formValue').should('have.text', JSON.stringify({ |
| 211 | + inputOtpString: 'ab', |
| 212 | + inputOtpNumber: 12 |
| 213 | + }, null, 2)); |
| 214 | + |
| 215 | + cy.get('ion-input-otp[formControlName="inputOtpString"]').should('have.class', 'ion-dirty'); |
| 216 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"]').should('have.class', 'ion-dirty'); |
| 217 | + |
| 218 | + // Verify both inputs remain invalid when partially filled |
| 219 | + cy.get('ion-input-otp[formControlName="inputOtpString"]').should('have.class', 'ion-invalid'); |
| 220 | + cy.get('ion-input-otp[formControlName="inputOtpNumber"]').should('have.class', 'ion-invalid'); |
| 221 | + }); |
| 222 | + }); |
| 223 | + |
150 | 224 | }); |
0 commit comments