1- import Ember from 'ember' ;
21import hbs from 'htmlbars-inline-precompile' ;
32import { moduleForComponent , test } from 'ember-qunit' ;
43
54moduleForComponent ( 'bootstrap-datepicker' , 'BootstrapDatepickerComponent' , {
65 integration : true
76} ) ;
87
9- test ( 'resets date when input is cleared ' , function ( assert ) {
10- assert . expect ( 2 ) ;
8+ test ( 'triggers specified action on focusout event ' , function ( assert ) {
9+ assert . expect ( 1 ) ;
1110
12- this . set ( 'myDate' , new Date ( ) ) ;
11+ this . render ( hbs `
12+ {{bootstrap-datepicker focus-out="focusOutAction"}}
13+ ` ) ;
14+
15+ var actionIsTriggered = false ;
16+ this . on ( 'focusOutAction' , ( ) => {
17+ actionIsTriggered = true ;
18+ } ) ;
19+
20+ this . $ ( 'input.ember-text-field' ) . trigger ( 'focusout' ) ;
21+
22+ assert . ok ( actionIsTriggered , 'action is triggered on focusout' ) ;
23+ } ) ;
24+
25+ test ( 'triggers specified action on focusin event' , function ( assert ) {
26+ assert . expect ( 1 ) ;
1327
1428 this . render ( hbs `
15- {{bootstrap-datepicker value=myDate }}
29+ {{bootstrap-datepicker focus-in="focusInAction" }}
1630 ` ) ;
17-
18- var datepicker = this . $ ( 'input.ember-text-field' ) . datepicker ( ) ;
19-
20- datepicker . val ( '' ) ;
21- Ember . run ( ( ) => {
22- datepicker . trigger ( 'input' ) ;
31+
32+ var actionIsTriggered = false ;
33+ this . on ( 'focusInAction' , ( ) => {
34+ actionIsTriggered = true ;
2335 } ) ;
2436
25- assert . equal ( this . get ( 'myDate' ) , null , 'value is reset' ) ;
26- assert . equal ( this . $ ( 'input.ember-text-field' ) . datepicker ( 'getDate' ) , null , 'datepicker is updated' ) ;
37+ this . $ ( 'input.ember-text-field' ) . trigger ( 'focusin' ) ;
38+
39+ assert . ok ( actionIsTriggered , 'action is triggered on focusin' ) ;
2740} ) ;
2841
29- test ( 'triggers changeDate action when input field is cleared ' , function ( assert ) {
42+ test ( 'triggers changeDate action when date selection changes ' , function ( assert ) {
3043 assert . expect ( 1 ) ;
3144
32- this . set ( 'myDate' , new Date ( ) ) ;
45+ this . set ( 'myDate' , null ) ;
3346
3447 var actionIsTriggered = false ;
3548 this . on ( 'myAction' , ( ) => {
@@ -40,47 +53,62 @@ test('triggers changeDate action when input field is cleared', function (assert)
4053 {{bootstrap-datepicker value=myDate changeDate="myAction"}}
4154 ` ) ;
4255
43- var datepicker = this . $ ( 'input.ember-text-field' ) . datepicker ( ) ;
44-
45- datepicker . val ( '' ) ;
46- Ember . run ( ( ) => {
47- datepicker . trigger ( 'input' ) ;
48- } ) ;
56+ var input = this . $ ( 'input.ember-text-field' ) ;
57+ input . datepicker ( 'setDate' , new Date ( ) ) ;
4958
5059 assert . ok ( actionIsTriggered , 'action is triggered' ) ;
5160} ) ;
5261
53- test ( 'triggers specified action on focusout event ' , function ( assert ) {
62+ test ( 'triggers clearDate action when date selection is cleared ' , function ( assert ) {
5463 assert . expect ( 1 ) ;
5564
56- this . render ( hbs `
57- {{bootstrap-datepicker focus-out="focusOutAction"}}
58- ` ) ;
65+ this . set ( 'myDate' , new Date ( ) ) ;
5966
6067 var actionIsTriggered = false ;
61- this . on ( 'focusOutAction ' , ( ) => {
68+ this . on ( 'myAction ' , ( ) => {
6269 actionIsTriggered = true ;
6370 } ) ;
6471
65- this . $ ( 'input.ember-text-field' ) . trigger ( 'focusout' ) ;
72+ this . render ( hbs `
73+ {{bootstrap-datepicker value=myDate clearDate="myAction"}}
74+ ` ) ;
6675
67- assert . ok ( actionIsTriggered , 'action is triggered on focusout ') ;
68- } ) ;
76+ var input = this . $ ( 'input.ember-text-field ') ;
77+ input . datepicker ( 'setDate' , null ) ;
6978
79+ assert . ok ( actionIsTriggered , 'action is triggered' ) ;
80+ } ) ;
7081
71- test ( 'triggers specified action on focusin event ' , function ( assert ) {
82+ test ( 'triggers show action when date datepicker is displayed ' , function ( assert ) {
7283 assert . expect ( 1 ) ;
7384
85+ var actionIsTriggered = false ;
86+ this . on ( 'myAction' , ( ) => {
87+ actionIsTriggered = true ;
88+ } ) ;
89+
7490 this . render ( hbs `
75- {{bootstrap-datepicker focus-in="focusInAction "}}
91+ {{bootstrap-datepicker show="myAction "}}
7692 ` ) ;
7793
94+ this . $ ( 'input.ember-text-field' ) . trigger ( 'show' ) ;
95+
96+ assert . ok ( actionIsTriggered , 'action is triggered' ) ;
97+ } ) ;
98+
99+ test ( 'triggers hide action when date datepicker is hidden' , function ( assert ) {
100+ assert . expect ( 1 ) ;
101+
78102 var actionIsTriggered = false ;
79- this . on ( 'focusInAction ' , ( ) => {
103+ this . on ( 'myAction ' , ( ) => {
80104 actionIsTriggered = true ;
81105 } ) ;
82106
83- this . $ ( 'input.ember-text-field' ) . trigger ( 'focusin' ) ;
107+ this . render ( hbs `
108+ {{bootstrap-datepicker hide="myAction"}}
109+ ` ) ;
84110
85- assert . ok ( actionIsTriggered , 'action is triggered on focusin' ) ;
111+ this . $ ( 'input.ember-text-field' ) . trigger ( 'hide' ) ;
112+
113+ assert . ok ( actionIsTriggered , 'action is triggered' ) ;
86114} ) ;
0 commit comments