Skip to content

Commit

Permalink
test: unit test for fieldGoogleAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Aug 26, 2016
1 parent 0b65bdb commit 63d47aa
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/fields/fieldGoogleAddress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//google inputs retrieved
"inputs": {
"street_number": "long_name",
street_number: "long_name",
route: "long_name",
country: "long_name",
administrative_area_level_1: "long_name",
Expand Down Expand Up @@ -89,7 +89,7 @@
lng: position.coords.longitude
};
let circle = new google.maps.Circle({
let circle = new window.google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
Expand Down
89 changes: 45 additions & 44 deletions test/unit/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
var wsConfig = require("./webpack.test.config");

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

browsers: ["PhantomJS"],
browsers: ["PhantomJS"],

reporters: ["spec", "coverage"],
reporters: ["spec", "coverage"],

frameworks: ["mocha", "chai", "sinon-chai"],
frameworks: ["mocha", "chai", "sinon-chai"],

files: [
"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.js",
"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js",
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.js",
"https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.js",
"https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.4/js/ion.rangeSlider.js",
"https://rawgit.com/monterail/vue-multiselect/master/lib/vue-multiselect.min.js",
"https://rawgit.com/nosir/cleave.js/master/dist/cleave.min.js",
"https://nosir.github.io/cleave.js/lib/cleave-phone.i18n.js",
"https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/8.5.1/nouislider.js",
"https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.4.0/pikaday.min.js",
files: [
"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.js",
"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js",
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.js",
"https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.js",
"https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.4/js/ion.rangeSlider.js",
"https://rawgit.com/monterail/vue-multiselect/master/lib/vue-multiselect.min.js",
"https://rawgit.com/nosir/cleave.js/master/dist/cleave.min.js",
"https://nosir.github.io/cleave.js/lib/cleave-phone.i18n.js",
"https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/8.5.1/nouislider.js",
"https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.4.0/pikaday.min.js",
"https://maps.googleapis.com/maps/api/js?key=AIzaSyCEz-sX9bRJorDS-D_JL0JkZVZe2gzoUMw&libraries=places",

"./index.js"
],
"./index.js"
],

exclude: [],
exclude: [],

preprocessors: {
"./index.js": ["webpack", "sourcemap"]
},
preprocessors: {
"./index.js": ["webpack", "sourcemap"]
},

webpack: wsConfig,
webpack: wsConfig,

webpackMiddleware: {
noInfo: true
},
webpackMiddleware: {
noInfo: true
},

port: 9876,
port: 9876,

colors: true,
colors: true,

logLevel: config.LOG_INFO,
logLevel: config.LOG_INFO,

autoWatch: false,
autoWatch: false,

singleRun: true,
singleRun: true,

coverageReporter: {
dir: "./coverage",
reporters: [
{ type: "lcov", subdir: "." },
{ type: "text-summary" }
]
}
}
coverageReporter: {
dir: "./coverage",
reporters: [
{ type: "lcov", subdir: "." },
{ type: "text-summary" }
]
}
}

config.set(settings);
config.set(settings);
}
99 changes: 99 additions & 0 deletions test/unit/specs/fields/fieldGoogleAddress.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { expect } from "chai";
import { createVueField, trigger } from "../util";

import Vue from "vue";
import FieldGoogleAddress from "src/fields/fieldGoogleAddress.vue";

Vue.component("FieldGoogleAddress", FieldGoogleAddress);

let el, vm, field;

function createField(schema = {}, model = null, disabled = false, options) {
[ el, vm, field ] = createVueField("fieldGoogleAddress", schema, model, disabled, options);
}

describe("fieldGoogleAddress.vue", () => {

describe("check template", () => {
let schema = {
type: "text",
label: "Address",
model: "address",
readonly: false,
placeholder: "Field placeholder"
};
let model = { address: "Paris, France" };
let input;

before( () => {
createField(schema, model, false);
input = el.getElementsByTagName("input")[0];
});

it("should contain an input text element", () => {
expect(field).to.be.exist;
expect(field.$el).to.be.exist;

expect(input).to.be.defined;
expect(input.type).to.be.equal("text");
expect(input.classList.contains("form-control")).to.be.true;
expect(input.placeholder).to.be.equal(schema.placeholder);
expect(input.readOnly).to.be.false;
expect(input.disabled).to.be.false;
});

it("should contain the value", (done) => {
vm.$nextTick( () => {
expect(input.value).to.be.equal("Paris, France");
done();
});
});

it("should set readOnly", (done) => {
schema.readonly = true;
vm.$nextTick( () => {
expect(input.readOnly).to.be.true;
schema.readonly = false;
done();
});
});

it("should set disabled", (done) => {
field.disabled = true;
vm.$nextTick( () => {
expect(input.disabled).to.be.true;
field.disabled = false;
done();
});
});

it("input value should be the model value after changed", (done) => {
model.address = "Rome, Italy";
vm.$nextTick( () => {
expect(input.value).to.be.equal("Rome, Italy");
done();
});

});

it("model value should be the input value if changed", (done) => {
input.value = "Budapest, Hungary";
trigger(input, "change");

vm.$nextTick( () => {
expect(model.address).to.be.equal("Budapest, Hungary");
done();
});

});

/*
TODO:
1. check HTML list if typing
2. check geolocate called if input got focus
3. check onPlaceChanged called
*/

});

});

0 comments on commit 63d47aa

Please sign in to comment.