-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VueMultiSelect unit test #46
Changes from 21 commits
6d10687
59d5036
2e7380f
e338e6d
dfef1f1
136b112
99b6a4d
c169cb3
42c9ea9
dea27a2
34a6401
e1b4126
00bfbda
ec93745
6e2fef0
e59bcc1
1c09c30
a2665dd
9a6fc4b
1b24293
4c7c717
09a41f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template lang="jade"> | ||
div.slider | ||
div.slider(:disabled="disabled") | ||
</template> | ||
|
||
<script> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { expect } from "chai"; | ||
import { createVueField } from "../util"; | ||
import { createVueField, trigger } from "../util"; | ||
|
||
import Vue from "vue"; | ||
import fieldVueMultiSelect from "src/fields/fieldVueMultiSelect.vue"; | ||
|
@@ -20,7 +20,7 @@ describe("fieldVueMultiSelect.vue", () => { | |
type: "vueMultiSelect", | ||
label: "Cities", | ||
model: "city", | ||
multiSelect: false, | ||
multiSelect: true, | ||
required: false, | ||
values: [ | ||
"London", | ||
|
@@ -35,16 +35,67 @@ describe("fieldVueMultiSelect.vue", () => { | |
|
||
before( () => { | ||
createField(schema, model, false); | ||
input = el.getElementsByTagName("select")[0]; | ||
vm.$appendTo(document.body); | ||
input = el.querySelector(".multiselect"); | ||
}); | ||
|
||
it("should contain a select element", () => { | ||
expect(field).to.be.exist; | ||
expect(field.$el).to.be.exist; | ||
|
||
expect(input).to.be.defined; | ||
// expect(input.classList.contains("form-control")).to.be.false; | ||
// expect(input.disabled).to.be.false; | ||
expect(input.classList.contains("form-control")).to.be.false; | ||
expect(input.classList.contains("multiselect--disabled")).to.be.false; | ||
}); | ||
|
||
it("should contain option elements", () => { | ||
let options = input.querySelectorAll("li.multiselect__option"); | ||
console.log(options); | ||
expect(options.length).to.be.equal(schema.values.length); | ||
expect(options[1].querySelector("span").textContent).to.be.equal("Paris"); | ||
expect(options[1].classList.contains("multiselect__option--selected")).to.be.true; | ||
}); | ||
|
||
it("should set disabled", (done) => { | ||
field.disabled = true; | ||
vm.$nextTick( () => { | ||
expect(input.classList.contains("multiselect--disabled")).to.be.true; | ||
field.disabled = false; | ||
done(); | ||
}); | ||
}); | ||
|
||
it("input value should be the model value after changed", (done) => { | ||
model.city = "Rome"; | ||
vm.$nextTick( () => { | ||
let options = input.querySelectorAll("li.multiselect__option"); | ||
expect(options[2].querySelector("span").textContent).to.be.equal("Rome"); | ||
expect(options[2].classList.contains("multiselect__option--selected")).to.be.true; | ||
done(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check how many elements have |
||
}); | ||
}); | ||
|
||
it("input value should be the model value after changed (multiselection)", (done) => { | ||
model.city = ["Paris","Rome"]; | ||
vm.$nextTick( () => { | ||
let options = input.querySelectorAll("li.multiselect__option"); | ||
expect(options[1].querySelector("span").textContent).to.be.equal("Paris"); | ||
expect(options[1].classList.contains("multiselect__option--selected")).to.be.true; | ||
expect(options[2].querySelector("span").textContent).to.be.equal("Rome"); | ||
expect(options[2].classList.contains("multiselect__option--selected")).to.be.true; | ||
done(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check how many elements have |
||
}); | ||
}); | ||
|
||
it("model value should be the input value if changed", (done) => { | ||
let options = input.querySelectorAll("li.multiselect__option"); | ||
trigger(options[2], "mousedown"); | ||
|
||
vm.$nextTick( () => { | ||
expect(model.city[0]).to.be.equal("Paris"); | ||
done(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not too precize. Please check the model.city.length to be 1 |
||
}); | ||
|
||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the problem with skipped tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm following mocha documentation. It is better to skip a test than comment it.
As for why exactly I skipping them, there is a problem with the value.
Without
vm.model = { rating: 10 };
, the slider don't move (.noUi-origin
cssleft
value is 0%), the value is not set at all (part of the problem come form my mistake in the schema definition, but even when fixed, there is still a problem).When placed in a
before
hook, the value is set properly.When used in a
it
statement, I need to use asetTimeout
inside thenextTick()
to get the changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I trying to fix this test