1
+ import { expect } from "chai" ;
2
+ import { createVueField , trigger } from "../util" ;
3
+
4
+ import Vue from "vue" ;
5
+ import FieldColor from "src/fields/fieldColor.vue" ;
6
+
7
+ Vue . component ( "FieldColor" , FieldColor ) ;
8
+
9
+ let el , vm , field ;
10
+
11
+ function createField ( schema = { } , model = null , disabled = false , options ) {
12
+ [ el , vm , field ] = createVueField ( "fieldColor" , schema , model , disabled , options ) ;
13
+ }
14
+
15
+ describe ( "fieldColor.vue" , ( ) => {
16
+
17
+ describe ( "check template" , ( ) => {
18
+ let schema = {
19
+ type : "color" ,
20
+ label : "Color" ,
21
+ model : "color"
22
+ } ;
23
+ let model = { color : "#ff8822" } ;
24
+ let input ;
25
+
26
+ before ( ( ) => {
27
+ createField ( schema , model , false ) ;
28
+ input = el . getElementsByTagName ( "input" ) [ 0 ] ;
29
+ } ) ;
30
+
31
+ it ( "should contain an input color element" , ( ) => {
32
+ expect ( field ) . to . be . exist ;
33
+ expect ( field . $el ) . to . be . exist ;
34
+
35
+ expect ( input ) . to . be . defined ;
36
+ expect ( input . type ) . to . be . equal ( "color" ) ;
37
+ //expect(input.classList.contains("form-control")).to.be.true;
38
+ expect ( input . disabled ) . to . be . false ;
39
+ } ) ;
40
+
41
+ it ( "should contain the value" , ( done ) => {
42
+ vm . $nextTick ( ( ) => {
43
+ expect ( input . value ) . to . be . equal ( "#ff8822" ) ;
44
+ done ( ) ;
45
+ } ) ;
46
+ } ) ;
47
+
48
+ it ( "should set disabled" , ( done ) => {
49
+ field . disabled = true ;
50
+ vm . $nextTick ( ( ) => {
51
+ expect ( input . disabled ) . to . be . true ;
52
+ done ( ) ;
53
+ } ) ;
54
+ } ) ;
55
+
56
+ it ( "input value should be the model value after changed" , ( done ) => {
57
+ model . color = "#ffff00" ;
58
+ vm . $nextTick ( ( ) => {
59
+ expect ( input . value ) . to . be . equal ( "#ffff00" ) ;
60
+ done ( ) ;
61
+ } ) ;
62
+
63
+ } ) ;
64
+
65
+ it ( "model value should be the input value if changed" , ( done ) => {
66
+ input . value = "#123456" ;
67
+ trigger ( input , "change" ) ;
68
+
69
+ vm . $nextTick ( ( ) => {
70
+ expect ( model . color ) . to . be . equal ( "#123456" ) ;
71
+ done ( ) ;
72
+ } ) ;
73
+
74
+ } ) ;
75
+
76
+ } ) ;
77
+
78
+ } ) ;
0 commit comments