55
66/* eslint max-nested-callbacks: 0 */
77
8- define ( [ 'squire' , 'ko' ] , function ( Squire , ko ) {
8+ define ( [ 'squire' , 'ko' , 'jquery' , 'jquery/validate' ] , function ( Squire , ko , $ ) {
99 'use strict' ;
1010
1111 describe ( 'Magento_Checkout/js/view/form/element/email' , function ( ) {
@@ -31,12 +31,12 @@ define(['squire', 'ko'], function (Squire, ko) {
3131 'getCheckedEmailValue'
3232 ]
3333 ) ,
34- 'Magento_Checkout/js/model/full-screen-loader' : jasmine . createSpy ( ) ,
35- 'mage/validation' : jasmine . createSpy ( )
34+ 'Magento_Checkout/js/model/full-screen-loader' : jasmine . createSpy ( )
3635 } ,
3736 Component ;
3837
3938 beforeEach ( function ( done ) {
39+ window . checkoutConfig = { } ;
4040 injector . mock ( mocks ) ;
4141 injector . require ( [ 'Magento_Checkout/js/view/form/element/email' ] , function ( Constr ) {
4242 Component = new Constr ( {
@@ -62,5 +62,23 @@ define(['squire', 'ko'], function (Squire, ko) {
6262 expect ( typeof Component . resolveInitialPasswordVisibility ( ) ) . toEqual ( 'boolean' ) ;
6363 } ) ;
6464 } ) ;
65+
66+ describe ( '"validateEmail" method' , function ( ) {
67+ beforeEach ( function ( ) {
68+ $ ( 'body' ) . append ( '<form data-role="email-with-possible-login">' +
69+ '<input type="text" name="username" />' +
70+ '</form>' ) ;
71+ spyOn ( $ . fn , 'validate' ) . and . returnValue ( true ) ;
72+ } ) ;
73+ it ( 'Check if login form will be validated in case it is not visible' , function ( ) {
74+ var loginFormSelector = 'form[data-role=email-with-possible-login]' ,
75+ loginForm = $ ( loginFormSelector ) ;
76+
77+ loginForm . hide ( ) ;
78+ Component . validateEmail ( ) ;
79+ expect ( loginForm . is ( ':visible' ) ) . toBeFalsy ( ) ;
80+ expect ( loginForm . validate ) . not . toHaveBeenCalled ( ) ;
81+ } ) ;
82+ } ) ;
6583 } ) ;
6684} ) ;
0 commit comments