Skip to content

Commit

Permalink
✅ test: add tests to dateTime field
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed May 9, 2016
1 parent a5d714d commit 4cd7bc6
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
115 changes: 115 additions & 0 deletions test/unit/specs/fields/fieldDateTime.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { expect } from "chai";
import { createVueField, trigger } from "../util";

import Vue from "vue";
import FieldDateTime from "src/fields/fieldDateTime.vue";

Vue.component("FieldDateTime", FieldDateTime);

let el, vm, field;

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

describe.only("fieldDateTime.vue", () => {

describe("check template", () => {
let schema = {
type: "dateTime",
label: "Event",
model: "event"
};
let model = { event: 1462799081231 };
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.disabled).to.be.false;
});

it("should contain the value", (done) => {
vm.$nextTick( () => {
expect(input.value).to.be.equal("2016-05-09 15:04:41");
done();
});
});

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

it("input value should be the model value after changed", (done) => {
model.event = 1234567890123;
vm.$nextTick( () => {
expect(input.value).to.be.equal("2009-02-14 00:31:30");
done();
});

});

it("model value should be the input value if changed", (done) => {
input.value = "2015-01-02 11:22:33";
trigger(input, "input");

vm.$nextTick( () => {
expect(model.event).to.be.equal(1420194153000);
done();
});

});

});

describe("check YYYYMMDD format", () => {
let schema = {
type: "dateTime",
label: "Event",
model: "event",
format: "YYYYMMDD",
dateTimePickerOptions: {
format: "YYYY.MM.DD"
}
};
let model = { event: "20160509" };
let input;

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

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

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

vm.$nextTick( () => {
expect(model.event).to.be.equal("20150102");
done();
});

});
});

});
2 changes: 2 additions & 0 deletions test/unit/specs/fields/fieldImage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ describe("fieldImage.vue", () => {
let remove = el.querySelector(".remove");
expect(input.value).to.be.equal("base64 image data");
expect(model.avatar).to.be.equal("base64 image data");

window.FileReader = FR;
done();
});
});
Expand Down

0 comments on commit 4cd7bc6

Please sign in to comment.