11import EmberObject from '@ember/object' ;
2+ import ObjectProxy from '@ember/object/proxy' ;
23import { setOwner } from '@ember/application' ;
34import { module , test } from 'qunit' ;
45import { setupRenderingTest } from 'ember-qunit' ;
@@ -14,6 +15,9 @@ const Validations = buildValidations({
1415const Model = EmberObject . extend ( Validations , {
1516 test : null
1617} ) ;
18+ const BufferedModel = ObjectProxy . extend ( Validations , {
19+ test : null
20+ } ) ;
1721
1822module ( 'Integration | Component | bs form element' , function ( hooks ) {
1923 setupRenderingTest ( hooks ) ;
@@ -66,4 +70,61 @@ module('Integration | Component | bs form element', function(hooks) {
6670 await triggerEvent ( 'form' , 'submit' ) ;
6771 assert . ok ( find ( '.form-group' ) . classList . contains ( 'has-error' ) , 'form element group has error class' ) ;
6872 } ) ;
73+
74+ test ( 'valid validation is supported as expected when working with an ember-buffered-proxy model' , async function ( assert ) {
75+ let proxiedModel = EmberObject . create ( ) ;
76+ setOwner ( proxiedModel , this . owner ) ;
77+
78+ let model = BufferedModel . create ( {
79+ content : proxiedModel ,
80+ test : '123'
81+ } ) ;
82+ setOwner ( model , this . owner ) ;
83+
84+ this . set ( 'model' , model ) ;
85+ this . submitAction = function ( ) {
86+ assert . ok ( true , 'submit action has been called.' ) ;
87+ } ;
88+ this . invalidAction = function ( ) {
89+ assert . ok ( false , 'Invalid action must not been called.' ) ;
90+ } ;
91+
92+ await render ( hbs `
93+ {{#bs-form model=model onSubmit=(action submitAction) onInvalid=(action invalidAction) as |form|}}
94+ {{form.element label="test" property="test"}}
95+ {{/bs-form}}
96+ ` ) ;
97+
98+ assert . expect ( 1 ) ;
99+
100+ await triggerEvent ( 'form' , 'submit' ) ;
101+ } ) ;
102+
103+ test ( 'invalid validation is supported as expected when working with an ember-buffered-proxy model' , async function ( assert ) {
104+ let proxiedModel = EmberObject . create ( ) ;
105+ setOwner ( proxiedModel , this . owner ) ;
106+
107+ let model = BufferedModel . create ( {
108+ content : proxiedModel
109+ } ) ;
110+ setOwner ( model , this . owner ) ;
111+
112+ this . set ( 'model' , model ) ;
113+ this . submitAction = function ( ) {
114+ assert . ok ( false , 'submit action must not been called.' ) ;
115+ } ;
116+ this . invalidAction = function ( ) {
117+ assert . ok ( true , 'Invalid action has been called.' ) ;
118+ } ;
119+
120+ await render ( hbs `
121+ {{#bs-form model=model onSubmit=(action submitAction) onInvalid=(action invalidAction) as |form|}}
122+ {{form.element label="test" property="test"}}
123+ {{/bs-form}}
124+ ` ) ;
125+
126+ assert . expect ( 1 ) ;
127+
128+ await triggerEvent ( 'form' , 'submit' ) ;
129+ } ) ;
69130} ) ;
0 commit comments