From ebf3f018b83950b14a9c8013c6ef5a5613ad54e4 Mon Sep 17 00:00:00 2001 From: Lionel Bijaoui Date: Tue, 6 Sep 2016 16:30:03 +0200 Subject: [PATCH] test: update to many test to check optional attributes --- test/unit/specs/fields/fieldCheckbox.spec.js | 20 ++++++----- test/unit/specs/fields/fieldChecklist.spec.js | 8 ----- test/unit/specs/fields/fieldCleave.spec.js | 32 +++++++---------- test/unit/specs/fields/fieldColor.spec.js | 20 ++++++----- test/unit/specs/fields/fieldDateTime.spec.js | 21 +++++------ test/unit/specs/fields/fieldEmail.spec.js | 32 ++++++++--------- .../specs/fields/fieldGoogleAddress.spec.js | 34 ++++++++---------- test/unit/specs/fields/fieldImage.spec.js | 26 ++++++-------- test/unit/specs/fields/fieldMasked.spec.js | 34 ++++++------------ test/unit/specs/fields/fieldNumber.spec.js | 29 +++++++-------- test/unit/specs/fields/fieldPassword.spec.js | 26 ++++++-------- test/unit/specs/fields/fieldPikaday.spec.js | 21 ++++++----- test/unit/specs/fields/fieldRange.spec.js | 17 +++++---- test/unit/specs/fields/fieldSelect.spec.js | 15 ++++---- test/unit/specs/fields/fieldSelectEx.spec.js | 19 +++++----- test/unit/specs/fields/fieldSlider.spec.js | 21 ++++++----- test/unit/specs/fields/fieldSpectrum.spec.js | 22 +++++++----- test/unit/specs/fields/fieldText.spec.js | 32 ++++++++--------- test/unit/specs/fields/fieldTextArea.spec.js | 31 +++++++--------- test/unit/specs/util.js | 36 +++++++++++++++++-- 20 files changed, 250 insertions(+), 246 deletions(-) diff --git a/test/unit/specs/fields/fieldCheckbox.spec.js b/test/unit/specs/fields/fieldCheckbox.spec.js index f11a89d5..96f6e30b 100644 --- a/test/unit/specs/fields/fieldCheckbox.spec.js +++ b/test/unit/specs/fields/fieldCheckbox.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldCheckbox from "src/fields/fieldCheckbox.vue"; @@ -18,7 +18,8 @@ describe("FieldCheckbox.vue", function() { let schema = { type: "checkbox", label: "Status", - model: "status" + model: "status", + autocomplete: "off" }; let model = { status: true }; let input; @@ -34,7 +35,7 @@ describe("FieldCheckbox.vue", function() { expect(input).to.be.defined; expect(input.type).to.be.equal("checkbox"); - expect(input.disabled).to.be.false; + // expect(input.disabled).to.be.false; }); it("should contain the value", (done) => { @@ -44,11 +45,14 @@ describe("FieldCheckbox.vue", function() { }); }); - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled"]; + + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldChecklist.spec.js b/test/unit/specs/fields/fieldChecklist.spec.js index 8f3db983..f7c87c7c 100644 --- a/test/unit/specs/fields/fieldChecklist.spec.js +++ b/test/unit/specs/fields/fieldChecklist.spec.js @@ -64,14 +64,6 @@ describe("fieldChecklist.vue", function() { expect(isChecked(6)).to.be.true; }); - /*it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(listbox.disabled).to.be.true; - done(); - }); - });*/ - it("listbox value should be the model value after changed", (done) => { model.skills = ["ReactJS"]; vm.$nextTick( () => { diff --git a/test/unit/specs/fields/fieldCleave.spec.js b/test/unit/specs/fields/fieldCleave.spec.js index b649b9b9..75af8a7c 100644 --- a/test/unit/specs/fields/fieldCleave.spec.js +++ b/test/unit/specs/fields/fieldCleave.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldCleave from "src/fields/fieldCleave.vue"; @@ -19,8 +19,9 @@ describe("fieldCleave.vue", function() { type: "masked", label: "Phone", model: "phone", + autocomplete: "off", + placeholder: "", readonly: false, - placeholder: "Field placeholder", cleaveOptions: { phone: true, phoneRegionCode: "HU", @@ -41,9 +42,9 @@ describe("fieldCleave.vue", function() { 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; + // 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) => { @@ -53,21 +54,14 @@ describe("fieldCleave.vue", function() { }); }); - it("should set readOnly", (done) => { - schema.readonly = true; - vm.$nextTick( () => { - expect(input.readOnly).to.be.true; - schema.readonly = false; - done(); - }); - }); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "readonly"]; - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - field.disabled = false; - done(); + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldColor.spec.js b/test/unit/specs/fields/fieldColor.spec.js index f6b459b4..7d2602a6 100644 --- a/test/unit/specs/fields/fieldColor.spec.js +++ b/test/unit/specs/fields/fieldColor.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldColor from "src/fields/fieldColor.vue"; @@ -18,7 +18,8 @@ describe("fieldColor.vue", function() { let schema = { type: "color", label: "Color", - model: "color" + model: "color", + autocomplete: "off" }; let model = { color: "#ff8822" }; let input; @@ -35,7 +36,7 @@ describe("fieldColor.vue", function() { expect(input).to.be.defined; expect(input.type).to.be.equal("color"); //expect(input.classList.contains("form-control")).to.be.true; - expect(input.disabled).to.be.false; + // expect(input.disabled).to.be.false; }); it("should contain the value", (done) => { @@ -45,11 +46,14 @@ describe("fieldColor.vue", function() { }); }); - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete"]; + + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldDateTime.spec.js b/test/unit/specs/fields/fieldDateTime.spec.js index 16c67a42..2e42cf71 100644 --- a/test/unit/specs/fields/fieldDateTime.spec.js +++ b/test/unit/specs/fields/fieldDateTime.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import moment from "moment"; import Vue from "vue"; @@ -19,7 +19,10 @@ describe("fieldDateTime.vue", function() { let schema = { type: "dateTime", label: "Event", - model: "event" + model: "event", + autocomplete: "off", + placeholder: "", + readonly: false }; let model = { event: 1462799081231 }; let input; @@ -46,15 +49,13 @@ describe("fieldDateTime.vue", function() { }); }); - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; - // Rollback - field.disabled = false; - vm.$nextTick( () => { - done(); + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); }); }); }); diff --git a/test/unit/specs/fields/fieldEmail.spec.js b/test/unit/specs/fields/fieldEmail.spec.js index bbaeb094..7aa54de4 100644 --- a/test/unit/specs/fields/fieldEmail.spec.js +++ b/test/unit/specs/fields/fieldEmail.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldEmail from "src/fields/fieldEmail.vue"; @@ -20,8 +20,9 @@ describe("fieldEmail.vue", function() { type: "text", label: "E-mail", model: "email", - readonly: false, - placeholder: "Field placeholder" + autocomplete: "off", + placeholder: "Field placeholder", + readonly: false }; let model = { email: "john.doe@company.org" }; let input; @@ -38,9 +39,9 @@ describe("fieldEmail.vue", function() { expect(input).to.be.defined; expect(input.type).to.be.equal("email"); 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; + // 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) => { @@ -50,19 +51,14 @@ describe("fieldEmail.vue", function() { }); }); - it("should set readOnly", (done) => { - schema.readonly = true; - vm.$nextTick( () => { - expect(input.readOnly).to.be.true; - done(); - }); - }); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldGoogleAddress.spec.js b/test/unit/specs/fields/fieldGoogleAddress.spec.js index 7686d602..7e89430f 100644 --- a/test/unit/specs/fields/fieldGoogleAddress.spec.js +++ b/test/unit/specs/fields/fieldGoogleAddress.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldGoogleAddress from "src/fields/fieldGoogleAddress.vue"; @@ -19,8 +19,9 @@ describe("fieldGoogleAddress.vue", function() { type: "text", label: "Address", model: "address", - readonly: false, - placeholder: "Field placeholder" + autocomplete: "off", + placeholder: "Field placeholder", + readonly: false }; let model = { address: "Paris, France" }; let input; @@ -37,9 +38,9 @@ describe("fieldGoogleAddress.vue", function() { 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; + // 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) => { @@ -49,21 +50,14 @@ describe("fieldGoogleAddress.vue", function() { }); }); - it("should set readOnly", (done) => { - schema.readonly = true; - vm.$nextTick( () => { - expect(input.readOnly).to.be.true; - schema.readonly = false; - done(); - }); - }); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - field.disabled = false; - done(); + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldImage.spec.js b/test/unit/specs/fields/fieldImage.spec.js index ddf189a5..b7b8039a 100644 --- a/test/unit/specs/fields/fieldImage.spec.js +++ b/test/unit/specs/fields/fieldImage.spec.js @@ -1,7 +1,7 @@ /* global sinon */ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldImage from "src/fields/fieldImage.vue"; @@ -21,8 +21,9 @@ describe("fieldImage.vue", function() { type: "image", label: "Avatar", model: "avatar", - readonly: false, - placeholder: "Field placeholder" + autocomplete: "off", + placeholder: "Field placeholder", + readonly: false }; let model = { avatar: "https://s3.amazonaws.com/uifaces/faces/twitter/calebogden/128.jpg" }; let input; @@ -66,19 +67,14 @@ describe("fieldImage.vue", function() { }); }); - it("should set readOnly", (done) => { - schema.readonly = true; - vm.$nextTick( () => { - expect(input.readOnly).to.be.true; - done(); - }); - }); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldMasked.spec.js b/test/unit/specs/fields/fieldMasked.spec.js index 9aa7d400..ee25c507 100644 --- a/test/unit/specs/fields/fieldMasked.spec.js +++ b/test/unit/specs/fields/fieldMasked.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldMasked from "src/fields/fieldMasked.vue"; @@ -20,8 +20,9 @@ describe("fieldMasked.vue", function() { label: "Phone", model: "phone", mask: "(99) 999-9999", - readonly: false, - placeholder: "Field placeholder" + autocomplete: "off", + placeholder: "Field placeholder", + readonly: false }; let model = { phone: "(30) 123-4567" }; let input; @@ -50,28 +51,13 @@ describe("fieldMasked.vue", function() { }); }); - it("should set readOnly", (done) => { - schema.readonly = true; - vm.$nextTick( () => { - expect(input.readOnly).to.be.true; + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; - // Rollback - schema.readonly = false; - vm.$nextTick( () => { - done(); - }); - }); - }); - - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - - // Rollback - field.disabled = false; - vm.$nextTick( () => { - done(); + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); }); }); }); diff --git a/test/unit/specs/fields/fieldNumber.spec.js b/test/unit/specs/fields/fieldNumber.spec.js index c82c1504..560e5737 100644 --- a/test/unit/specs/fields/fieldNumber.spec.js +++ b/test/unit/specs/fields/fieldNumber.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldNumber from "src/fields/fieldNumber.vue"; @@ -19,10 +19,11 @@ describe("fieldNumber.vue", function() { type: "number", label: "Age", model: "age", - readonly: false, min: 18, max: 100, - placeholder: "Field placeholder" + autocomplete:"off", + placeholder: "Field placeholder", + readonly: false }; let model = { age: 27 }; let input; @@ -52,20 +53,14 @@ describe("fieldNumber.vue", function() { done(); }); }); - - it("should set readOnly", (done) => { - schema.readonly = true; - vm.$nextTick( () => { - expect(input.readOnly).to.be.true; - done(); - }); - }); - - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; + + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldPassword.spec.js b/test/unit/specs/fields/fieldPassword.spec.js index 6ea2c526..314cd420 100644 --- a/test/unit/specs/fields/fieldPassword.spec.js +++ b/test/unit/specs/fields/fieldPassword.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldPassword from "src/fields/fieldPassword.vue"; @@ -20,8 +20,9 @@ describe("fieldPassword.vue", function() { type: "password", label: "Password", model: "password", - readonly: false, - placeholder: "Field placeholder" + autocomplete:"off", + placeholder: "Field placeholder", + readonly: false }; let model = { password: "123456!" }; let input; @@ -50,19 +51,14 @@ describe("fieldPassword.vue", function() { }); }); - it("should set readOnly", (done) => { - schema.readonly = true; - vm.$nextTick( () => { - expect(input.readOnly).to.be.true; - done(); - }); - }); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldPikaday.spec.js b/test/unit/specs/fields/fieldPikaday.spec.js index 779672ca..4beaef24 100644 --- a/test/unit/specs/fields/fieldPikaday.spec.js +++ b/test/unit/specs/fields/fieldPikaday.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField } from "../util"; +import { createVueField, checkAttribute } from "../util"; import moment from "moment"; import Vue from "vue"; @@ -19,7 +19,10 @@ describe("fieldPikaday.vue", function() { let schema = { type: "dateTime", label: "Event", - model: "event" + model: "event", + autocomplete:"off", + placeholder: "Field placeholder", + readonly: false }; let model = { event: 1462799081231 }; let input; @@ -46,12 +49,14 @@ describe("fieldPikaday.vue", function() { }); }); - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - field.disabled = false; - done(); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; + + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldRange.spec.js b/test/unit/specs/fields/fieldRange.spec.js index cc4c29b1..51120faf 100644 --- a/test/unit/specs/fields/fieldRange.spec.js +++ b/test/unit/specs/fields/fieldRange.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldRange from "src/fields/fieldRange.vue"; @@ -21,7 +21,7 @@ describe("fieldRange.vue", function() { model: "rating", min: 1, max: 10, - placeholder: "Field placeholder" + autocomplete: "off" }; let model = { rating: 8 }; let input; @@ -50,11 +50,14 @@ describe("fieldRange.vue", function() { }); }); - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled"]; + + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldSelect.spec.js b/test/unit/specs/fields/fieldSelect.spec.js index 21c71383..787035cb 100644 --- a/test/unit/specs/fields/fieldSelect.spec.js +++ b/test/unit/specs/fields/fieldSelect.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldSelect from "src/fields/fieldSelect.vue"; @@ -67,11 +67,14 @@ describe("fieldSelect.vue", function() { }); }); - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["disabled"]; + + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldSelectEx.spec.js b/test/unit/specs/fields/fieldSelectEx.spec.js index d9397be4..0a66e75d 100644 --- a/test/unit/specs/fields/fieldSelectEx.spec.js +++ b/test/unit/specs/fields/fieldSelectEx.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldSelectEx from "src/fields/fieldSelectEx.vue"; @@ -41,8 +41,8 @@ describe("fieldSelectEx.vue", function() { expect(field.$el).to.be.exist; expect(input).to.be.defined; - expect(input.disabled).to.be.false; - expect(input.multiple).to.be.false; + // expect(input.disabled).to.be.false; + expect(input.multiple).to.be.false; }); it("should contain option elements", () => { @@ -67,11 +67,14 @@ describe("fieldSelectEx.vue", function() { }); }); - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["disabled", "multiSelect"]; + + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldSlider.spec.js b/test/unit/specs/fields/fieldSlider.spec.js index 32fb2c0d..001d1b75 100644 --- a/test/unit/specs/fields/fieldSlider.spec.js +++ b/test/unit/specs/fields/fieldSlider.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField } from "../util"; +import { createVueField, checkAttribute } from "../util"; import Vue from "vue"; import FieldSlider from "src/fields/fieldSlider.vue"; @@ -20,7 +20,10 @@ describe("fieldSlider.vue", function() { label: "Rating", model: "rating", min: 1, - max: 10 + max: 10, + autocomplete:"off", + placeholder: "Field placeholder", + readonly: false }; let model = { rating: 8 }; let input; @@ -49,12 +52,14 @@ describe("fieldSlider.vue", function() { }); }); - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.getAttribute("data-disable")).to.be.equal(""); - field.disabled = false; - done(); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "placeholder", "readonly"]; + + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldSpectrum.spec.js b/test/unit/specs/fields/fieldSpectrum.spec.js index 6c885d07..dbde58f3 100644 --- a/test/unit/specs/fields/fieldSpectrum.spec.js +++ b/test/unit/specs/fields/fieldSpectrum.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldSpectrum from "src/fields/fieldSpectrum.vue"; @@ -19,7 +19,10 @@ describe("fieldSpectrum.vue", function() { let schema = { type: "color", label: "Color", - model: "color" + model: "color", + autocomplete:"off", + placeholder: "Field placeholder", + readonly: false }; let model = { color: "#ff8822" }; let input; @@ -46,13 +49,14 @@ describe("fieldSpectrum.vue", function() { }); }); - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - expect(el.querySelectorAll(".sp-disabled").length).to.be.equal(1); - field.disabled = false; - done(); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; + + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldText.spec.js b/test/unit/specs/fields/fieldText.spec.js index 371f1adb..f7fa4ed7 100644 --- a/test/unit/specs/fields/fieldText.spec.js +++ b/test/unit/specs/fields/fieldText.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldText from "src/fields/fieldText.vue"; @@ -19,8 +19,9 @@ describe("fieldText.vue", function() { type: "text", label: "Name", model: "name", - readonly: false, - placeholder: "Field placeholder" + autocomplete:"off", + placeholder: "Field placeholder", + readonly: false }; let model = { name: "John Doe" }; let input; @@ -37,9 +38,9 @@ describe("fieldText.vue", function() { 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; + 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) => { @@ -49,19 +50,14 @@ describe("fieldText.vue", function() { }); }); - it("should set readOnly", (done) => { - schema.readonly = true; - vm.$nextTick( () => { - expect(input.readOnly).to.be.true; - done(); - }); - }); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["autocomplete", "disabled", "placeholder", "readonly"]; - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/fields/fieldTextArea.spec.js b/test/unit/specs/fields/fieldTextArea.spec.js index de475870..2afa73e4 100644 --- a/test/unit/specs/fields/fieldTextArea.spec.js +++ b/test/unit/specs/fields/fieldTextArea.spec.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createVueField, trigger } from "../util"; +import { createVueField, trigger, checkAttribute } from "../util"; import Vue from "vue"; import FieldTextArea from "src/fields/fieldTextArea.vue"; @@ -20,9 +20,9 @@ describe("fieldTextArea.vue", function() { type: "textarea", label: "Description", model: "desc", - readonly: false, + max: 500, placeholder: "Field placeholder", - max: 500 + readonly: false }; let model = { desc: "Lorem ipsum dolor sit amet, consectetur adipiscing elit." }; let input; @@ -38,9 +38,9 @@ describe("fieldTextArea.vue", function() { expect(input).to.be.defined; 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; + // expect(input.placeholder).to.be.equal(schema.placeholder); + // expect(input.readOnly).to.be.false; + // expect(input.disabled).to.be.false; expect(input.rows).to.be.equal(2); // default value is 2 expect(input.maxLength).to.be.equal(500); }); @@ -60,19 +60,14 @@ describe("fieldTextArea.vue", function() { }); }); - it("should set readOnly", (done) => { - schema.readonly = true; - vm.$nextTick( () => { - expect(input.readOnly).to.be.true; - done(); - }); - }); + describe("check optional attribute", () => { + // name which attributes you want to test and that's it. + let attributes = ["disabled", "placeholder", "readonly"]; - it("should set disabled", (done) => { - field.disabled = true; - vm.$nextTick( () => { - expect(input.disabled).to.be.true; - done(); + attributes.forEach(function(name) { + it("should set " + name, function(done) { + checkAttribute(name, vm, input, field, schema, done); + }); }); }); diff --git a/test/unit/specs/util.js b/test/unit/specs/util.js index ab16d9c1..0a4d1cff 100644 --- a/test/unit/specs/util.js +++ b/test/unit/specs/util.js @@ -1,3 +1,4 @@ +import { expect } from "chai"; import Vue from "vue"; export function trigger (el, event, args) { @@ -43,5 +44,36 @@ export function createVueField(test, type, schema = {}, model = null, disabled = }); let field = vm.$refs.field; - return [ el, vm, field ]; -} \ No newline at end of file + return [el, vm, field]; +} + +export let attributesList = { + "autocomplete": { before: "on", after: "off" }, + "disabled": { before: true, after: false, field: true }, + "multiSelect": { before: true, after: false, name: "multiple" }, + "placeholder": { before: "Field placeholder", after: "" }, + "readonly": { before: true, after: false, name: "readOnly" } + +}; + +export function checkAttribute(name, vm, input, field, schema, done) { + + let schematic; + let attr = attributesList[name]; + + if (attr.field) { + schematic = field; + } else { + schematic = schema; + } + schematic[name] = attr.before; + vm.$nextTick(() => { + if (attr.name) { + expect(input[attr.name]).to.be.equal(schematic[name]); + } else { + expect(input[name]).to.be.equal(schematic[name]); + } + schematic[name] = attr.after; + return done(); + }); +}