1
+ /* global sinon */
2
+ import { expect } from "chai" ;
3
+ import { createVueField } from "../util" ;
4
+
5
+ import Vue from "vue" ;
6
+ import FieldSubmit from "src/fields/fieldSubmit.vue" ;
7
+
8
+ Vue . component ( "FieldSubmit" , FieldSubmit ) ;
9
+
10
+ // eslint-disable-next-line
11
+ let el , vm , field ;
12
+
13
+ function createField ( schema = { } , model = null , disabled = false , options ) {
14
+ [ el , vm , field ] = createVueField ( "fieldSubmit" , schema , model , disabled , options ) ;
15
+ }
16
+
17
+ describe ( "fieldSubmit.vue" , ( ) => {
18
+
19
+ describe ( "check template" , ( ) => {
20
+ let schema = {
21
+ type : "submit" ,
22
+ caption : "Submit form" ,
23
+ validateBeforeSubmit : false ,
24
+ onSubmit ( ) { }
25
+ } ;
26
+ let model = { name : "John Doe" } ;
27
+ let input ;
28
+
29
+ before ( ( ) => {
30
+ createField ( schema , model , false ) ;
31
+ input = el . getElementsByTagName ( "input" ) [ 0 ] ;
32
+ } ) ;
33
+
34
+ it ( "should contain an input submit element" , ( ) => {
35
+ expect ( field ) . to . be . exist ;
36
+ expect ( field . $el ) . to . be . exist ;
37
+
38
+ expect ( input ) . to . be . defined ;
39
+ expect ( input . type ) . to . be . equal ( "submit" ) ;
40
+ expect ( input . value ) . to . be . equal ( "Submit form" ) ;
41
+ } ) ;
42
+
43
+ it ( "should not call validate if validateBeforeSubmit is false" , ( ) => {
44
+ schema . onSubmit = sinon . spy ( ) ;
45
+ let cb = sinon . spy ( ) ;
46
+ field . $parent . validate = cb ;
47
+
48
+ input . click ( ) ;
49
+ expect ( cb . called ) . to . be . false ;
50
+ expect ( schema . onSubmit . calledOnce ) . to . be . true ;
51
+ expect ( schema . onSubmit . calledWith ( model , schema ) ) . to . be . true ;
52
+ } ) ;
53
+
54
+
55
+ it ( "should call validate if validateBeforeSubmit is true" , ( ) => {
56
+ schema . validateBeforeSubmit = true ;
57
+ schema . onSubmit = sinon . spy ( ) ;
58
+ let cb = sinon . spy ( ) ;
59
+ field . $parent . validate = cb ;
60
+
61
+ input . click ( ) ;
62
+ expect ( cb . called ) . to . be . true ;
63
+ expect ( schema . onSubmit . called ) . to . be . false ;
64
+ } ) ;
65
+
66
+ } ) ;
67
+
68
+ } ) ;
0 commit comments