-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { expect } from "chai"; | ||
import { createVueField, trigger } from "../util"; | ||
|
||
import Vue from "vue"; | ||
import FieldSwitch from "src/fields/fieldSwitch.vue"; | ||
|
||
Vue.component("FieldSwitch", FieldSwitch); | ||
|
||
let el, vm, field; | ||
|
||
function createField(schema = {}, model = null, disabled = false, options) { | ||
[ el, vm, field ] = createVueField("fieldSwitch", schema, model, disabled, options); | ||
} | ||
|
||
describe("FieldSwitch.vue", () => { | ||
|
||
describe("check template", () => { | ||
let schema = { | ||
type: "switch", | ||
label: "Status", | ||
model: "status" | ||
}; | ||
let model = { status: true }; | ||
let input; | ||
|
||
before( () => { | ||
createField(schema, model, false); | ||
input = el.querySelector("input"); | ||
}); | ||
|
||
it("should contain a checkbox element", () => { | ||
expect(field).to.be.exist; | ||
expect(field.$el).to.be.exist; | ||
|
||
expect(input).to.be.defined; | ||
expect(input.type).to.be.equal("checkbox"); | ||
expect(input.disabled).to.be.false; | ||
}); | ||
|
||
it("should contain the value", (done) => { | ||
vm.$nextTick( () => { | ||
expect(input.checked).to.be.true; | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should contain the default On/Off texts", () => { | ||
let span = field.$el.querySelector("span.label"); | ||
expect(span.getAttribute("data-on")).to.be.equal("On"); | ||
expect(span.getAttribute("data-off")).to.be.equal("Off"); | ||
}); | ||
|
||
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.status = false; | ||
vm.$nextTick( () => { | ||
expect(input.checked).to.be.false; | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
it("model value should be the input value if changed", (done) => { | ||
input.checked = true; | ||
trigger(input, "change"); | ||
|
||
vm.$nextTick( () => { | ||
expect(model.status).to.be.true; | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe("check template with custom On/Off texts", () => { | ||
let schema = { | ||
type: "switch", | ||
label: "Status", | ||
model: "status", | ||
textOn: "Yes", | ||
textOff: "No" | ||
}; | ||
let model = { status: true }; | ||
|
||
before( () => { | ||
createField(schema, model, false); | ||
}); | ||
|
||
it("check attributes", () => { | ||
let span = field.$el.querySelector("span.label"); | ||
expect(span.getAttribute("data-on")).to.be.equal("Yes"); | ||
expect(span.getAttribute("data-off")).to.be.equal("No"); | ||
}); | ||
|
||
}); | ||
|
||
}); |