Skip to content

Commit 05fc81c

Browse files
authored
Merge pull request #51 from icebob/improvetest
Add new fields tests #40
2 parents 2be0307 + 012ee91 commit 05fc81c

37 files changed

+464
-217
lines changed

src/fields/fieldCleave.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export default {
4343
} else {
4444
console.warn("Cleave is missing. Please download from https://github.com/nosir/cleave.js/ and load the script in the HTML head section!");
4545
}
46+
},
47+
48+
beforeDestroy() {
49+
if (this.cleave)
50+
this.cleave.destroy();
4651
}
4752
};
4853
</script>

src/fields/fieldDateTime.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* global $ */
1010
import abstractField from "./abstractField";
1111
import moment from "moment";
12+
import { defaults } from "lodash";
1213
1314
let inputFormat = "YYYY-MM-DD HH:mm:ss";
1415
@@ -46,11 +47,13 @@
4647
},
4748
4849
ready() {
49-
if ($.fn.datetimepicker)
50-
$(this.$el).datetimepicker(this.schema.dateTimePickerOptions);
50+
if ($.fn.datetimepicker) {
51+
$(this.$el).datetimepicker(defaults(this.schema.dateTimePickerOptions || {}, {
52+
format: inputFormat
53+
}));
54+
}
5155
else
5256
console.warn("Bootstrap datetimepicker library is missing. Please download from https://eonasdan.github.io/bootstrap-datetimepicker/ and load the script and CSS in the HTML head section!");
53-
5457
}
5558
};
5659
</script>

src/fields/fieldGoogleAddress.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
//google inputs retrieved
2525
"inputs": {
26-
"street_number": "long_name",
26+
street_number: "long_name",
2727
route: "long_name",
2828
country: "long_name",
2929
administrative_area_level_1: "long_name",
@@ -89,7 +89,7 @@
8989
lng: position.coords.longitude
9090
};
9191
92-
let circle = new google.maps.Circle({
92+
let circle = new window.google.maps.Circle({
9393
center: geolocation,
9494
radius: position.coords.accuracy
9595
});

src/fields/fieldPikaday.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import moment from "moment";
88
import { defaults } from "lodash";
99
10-
let inputFormat = "YYYY-MM-DD HH:mm:ss";
10+
let inputFormat = "YYYY-MM-DD";
1111
1212
export default {
1313
mixins: [ abstractField ],
@@ -53,7 +53,7 @@
5353
position: "bottom left", // preferred position of the datepicker relative to the form field, e.g.: `top right`, `bottom right` **Note:** automatic adjustment may occur to avoid datepicker from being displayed outside the viewport, see [positions example][] (default to "bottom left")
5454
reposition: true, // can be set to false to not reposition datepicker within the viewport, forcing it to take the configured `position` (default: true)
5555
// container: , // DOM node to render calendar into, see [container example][] (default: undefined)
56-
// format: , // the default output format for `.toString()` and `field` value (requires [Moment.js][moment] for custom formatting)
56+
format: inputFormat, // the default output format for `.toString()` and `field` value (requires [Moment.js][moment] for custom formatting)
5757
// formatStrict: , // the default flag for moment"s strict date parsing (requires [Moment.js][moment] for custom formatting)
5858
// defaultDate: , // the initial date to view when first opened
5959
// setDefaultDate: , // make the `defaultDate` the initial selected value
@@ -88,7 +88,12 @@
8888
console.warn("Pikaday is missing. Please download from https://github.com/dbushell/Pikaday/ and load the script and CSS in the HTML head section!");
8989
}
9090
91-
}
91+
},
92+
93+
beforeDestroy() {
94+
if (this.picker)
95+
this.picker.destroy();
96+
}
9297
};
9398
</script>
9499

src/fields/fieldSlider.vue

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
export default {
1111
mixins: [ abstractField ],
1212
13+
data() {
14+
return {
15+
slider: null
16+
};
17+
},
18+
1319
watch: {
1420
model: function() {
1521
if ($.fn.ionRangeSlider) {
@@ -19,9 +25,8 @@
1925
} else
2026
valueFrom = this.value;
2127
22-
let ionRangeSlider = $(this.$el).data("ionRangeSlider");
23-
if (ionRangeSlider) {
24-
ionRangeSlider.update({
28+
if (this.slider) {
29+
this.slider.update({
2530
from: valueFrom,
2631
to: valueTo
2732
});
@@ -38,24 +43,31 @@
3843
} else
3944
valueFrom = this.value;
4045
46+
let self = this;
4147
$(this.$el).ionRangeSlider(defaults(this.schema.sliderOptions || {}, {
4248
type: "single",
4349
grid: true,
4450
hide_min_max: true,
4551
from: valueFrom,
4652
to: valueTo,
47-
onChange: (slider) => {
48-
if (this.schema.sliderOptions.type == "double") {
49-
this.value = [ slider.from, slider.to ];
53+
onChange(slider) {
54+
if (self.slider.options.type == "double") {
55+
self.value = [ slider.from, slider.to ];
5056
} else {
51-
this.value = slider.from;
57+
self.value = slider.from;
5258
}
5359
}
5460
}));
61+
this.slider = $(this.$el).data("ionRangeSlider");
5562
}
5663
else
5764
console.warn("ion.rangeSlider library is missing. Please download from https://github.com/IonDen/ion.rangeSlider and load the script and CSS in the HTML head section!");
58-
}
65+
},
66+
67+
beforeDestroy() {
68+
if (this.slider)
69+
this.slider.destroy();
70+
}
5971
};
6072
</script>
6173

src/fields/fieldSpectrum.vue

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,30 @@
99
export default {
1010
mixins: [ abstractField ],
1111
12+
data() {
13+
return {
14+
picker: null
15+
};
16+
},
17+
1218
watch: {
1319
model() {
1420
if ($.fn.spectrum) {
15-
$(this.$el).spectrum("set", this.value);
21+
this.picker.spectrum("set", this.value);
1622
}
23+
},
24+
25+
disabled(val) {
26+
if (val)
27+
this.picker.spectrum("disable");
28+
else
29+
this.picker.spectrum("enable");
1730
}
1831
},
1932
2033
ready() {
21-
if ($.fn.spectrum)
22-
$(this.$el).spectrum("destroy").spectrum(defaults(this.schema.colorOptions || {}, {
34+
if ($.fn.spectrum) {
35+
this.picker = $(this.$el).spectrum("destroy").spectrum(defaults(this.schema.colorOptions || {}, {
2336
showInput: true,
2437
showAlpha: true,
2538
disabled: this.schema.disabled,
@@ -29,8 +42,16 @@
2942
this.value = color ? color.toString() : null;
3043
}
3144
}));
32-
else
45+
this.picker.spectrum("set", this.value);
46+
47+
} else {
3348
console.warn("Spectrum color library is missing. Please download from http://bgrins.github.io/spectrum/ and load the script and CSS in the HTML head section!");
49+
}
50+
},
51+
52+
beforeDestroy() {
53+
if (this.picker)
54+
this.picker.spectrum("destroy");
3455
}
3556
3657
};

src/formGenerator.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@
163163
$errorColor: lighten(#F00, 0%);
164164
165165
fieldset.vue-form-generator {
166+
167+
* {
168+
box-sizing: border-box;
169+
}
166170
167171
.form-control {
168172
// Default Bootstrap .form-control style

test/unit/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ testsContext.keys().forEach(testsContext);
88
// you want coverage for.
99
var srcContext = require.context("src", true, /\.(js|vue)$/);
1010
srcContext.keys().forEach(srcContext);
11+
12+
require("./style.scss");

test/unit/karma.conf.js

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,65 @@
11
var wsConfig = require("./webpack.test.config");
22

33
module.exports = function(config) {
4-
var settings = {
5-
// base path that will be used to resolve all patterns (eg. files, exclude)
6-
basePath: "",
4+
var settings = {
5+
// base path that will be used to resolve all patterns (eg. files, exclude)
6+
basePath: "",
77

8-
browsers: ["PhantomJS"],
8+
browsers: ["PhantomJS"],
99

10-
reporters: ["spec", "coverage"],
10+
reporters: ["spec", "coverage"],
1111

12-
frameworks: ["mocha", "chai", "sinon-chai"],
12+
frameworks: ["mocha", "chai", "sinon-chai"],
1313

14-
files: [
15-
"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.js",
16-
"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js",
17-
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js",
18-
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js",
19-
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js",
20-
"https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.js",
21-
"https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.js",
22-
"https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.4/js/ion.rangeSlider.js",
23-
"https://rawgit.com/monterail/vue-multiselect/master/lib/vue-multiselect.min.js",
24-
"https://rawgit.com/nosir/cleave.js/master/dist/cleave.min.js",
25-
"https://nosir.github.io/cleave.js/lib/cleave-phone.i18n.js",
26-
"https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/8.5.1/nouislider.js",
27-
"https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.4.0/pikaday.min.js",
14+
files: [
15+
"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.js",
16+
"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js",
17+
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js",
18+
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js",
19+
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js",
20+
"https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.js",
21+
"https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.js",
22+
"https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.4/js/ion.rangeSlider.js",
23+
"https://rawgit.com/monterail/vue-multiselect/master/lib/vue-multiselect.min.js",
24+
"https://rawgit.com/nosir/cleave.js/master/dist/cleave.js",
25+
"https://nosir.github.io/cleave.js/lib/cleave-phone.i18n.js",
26+
"https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/8.5.1/nouislider.js",
27+
"https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.4.0/pikaday.js",
28+
"https://maps.googleapis.com/maps/api/js?key=AIzaSyCEz-sX9bRJorDS-D_JL0JkZVZe2gzoUMw&libraries=places",
2829

29-
"./index.js"
30-
],
30+
"./index.js"
31+
],
3132

32-
exclude: [],
33+
exclude: [],
3334

34-
preprocessors: {
35-
"./index.js": ["webpack", "sourcemap"]
36-
},
35+
preprocessors: {
36+
"./index.js": ["webpack", "sourcemap"]
37+
},
3738

38-
webpack: wsConfig,
39+
webpack: wsConfig,
3940

40-
webpackMiddleware: {
41-
noInfo: true
42-
},
41+
webpackMiddleware: {
42+
noInfo: true
43+
},
4344

44-
port: 9876,
45+
port: 9876,
4546

46-
colors: true,
47+
colors: true,
4748

48-
logLevel: config.LOG_INFO,
49+
logLevel: config.LOG_INFO,
4950

50-
autoWatch: false,
51+
autoWatch: false,
5152

52-
singleRun: true,
53+
singleRun: true,
5354

54-
coverageReporter: {
55-
dir: "./coverage",
56-
reporters: [
57-
{ type: "lcov", subdir: "." },
58-
{ type: "text-summary" }
59-
]
60-
}
61-
}
55+
coverageReporter: {
56+
dir: "./coverage",
57+
reporters: [
58+
{ type: "lcov", subdir: "." },
59+
{ type: "text-summary" }
60+
]
61+
}
62+
}
6263

63-
config.set(settings);
64+
config.set(settings);
6465
}

0 commit comments

Comments
 (0)