Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions dev/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ module.exports = {
numeralDecimalScale: 2,
numeralDecimalMark: '.',
// General
blocks: [0, 2, 3, 4],
blocks: [0, 2, 0, 3, 4],
delimiter: ' ',
delimiters: ['(', ') ', '-', '-'],
delimiters: ['(', ')', ' ', '-', '-'],
// prefix: '(',
numericOnly: true,
uppercase: false,
Expand Down Expand Up @@ -406,6 +406,16 @@ module.exports = {
// direction: "ltr", //"ltr", "rtl"
// tooltips: false, // false, true, formatter, array[formatter or false]
// animate: true,
range:{
'min': [ 0 ],
'max': [ 10 ]
},
pips: {
mode: 'count',
values: 6,
density: 10,
stepped: true
}
},
// validator: validators.integer
},
Expand Down
2 changes: 1 addition & 1 deletion src/fields/fieldNoUiSlider.vue
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>
Expand Down
4 changes: 2 additions & 2 deletions src/fields/fieldVueMultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
:custom-label="schema.selectOptions.customLabel || null",
:taggable="schema.selectOptions.taggable",
:tag-placeholder="schema.selectOptions.tagPlaceholder",
:max="schema.max",
:max="schema.max || null",
@update="updateSelected",
@tag="addTag",
@select="onSelect",
Expand All @@ -33,7 +33,7 @@
:limit="schema.selectOptions.limit",
:limit-text="schema.selectOptions.limitText",
:loading="schema.selectOptions.loading",
:disabled="schema.disabled",
:disabled="disabled",
)
</template>
<script>
Expand Down
66 changes: 65 additions & 1 deletion test/unit/specs/fields/fieldNoUiSlider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,71 @@ describe("fieldNoUiSlider.vue", () => {
expect(field.$el).to.be.exist;

expect(input).to.be.defined;
expect(input.classList.contains("slider")).to.be.true;
expect(input.classList.contains("slider")).to.be.true;
expect(input.disabled).to.be.undefined;
});

before( () => {
vm.$appendTo(document.body);
});

it("should contain an handle element", (done) => {
if (window.noUiSlider) {
vm.$nextTick( () => {
let handle = input.querySelector(".noUi-handle");
expect(handle).to.be.defined;
// expect(input.classList.contains("noui-target")).to.be.true;
done();
});
} else {
// eslint-disable-next-line
throw new Exception("Library is not loaded");
}
});

it.skip("should contain the value", (done) => {
vm.$nextTick( () => {
let origin = input.querySelector(".noUi-origin");
expect(origin.style.left).to.be.within("70%", "90%");
done();
});
});

before( () => {
vm.model = { rating: 10 };
});

it("handle value should be the model value after changed", (done) => {
vm.$nextTick( () => {
let origin = input.querySelector(".noUi-origin");
expect(origin.style.left).to.be.equal("100%");
done();
});
});

// before( (done) => {
// input.querySelectorAll(".noUi-origin")[0].style.left = "0%";
// vm.$nextTick( () => {
// done();
// });
// });

it.skip("model value should be the handle value after changed", (done) => {
vm.$nextTick( () => {
Copy link
Member

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?

Copy link
Member Author

@lionel-bijaoui lionel-bijaoui Aug 24, 2016

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.

Best practice: Use .skip() instead of commenting tests out.

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 css left 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 a setTimeout inside the nextTick() to get the changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check too.

Copy link
Member

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

expect(vm.model.rating).to.be.equal("0");
done();
});
});

it.skip("should set disabled", (done) => {
console.log(field.disabled);
console.log(input);
vm.schema.disabled = true;
vm.$nextTick( () => {
console.log(input);
expect(input.disabled).to.be.true;
done();
});
});
});
});
61 changes: 56 additions & 5 deletions test/unit/specs/fields/fieldVueMultiSelect.spec.js
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";
Expand All @@ -20,7 +20,7 @@ describe("fieldVueMultiSelect.vue", () => {
type: "vueMultiSelect",
label: "Cities",
model: "city",
multiSelect: false,
multiSelect: true,
required: false,
values: [
"London",
Expand All @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check how many elements have multiselect__option--selected class.
input.querySelectorAll('li.multiselect__option--selected').length need to be 1, because 1 element selected

});
});

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check how many elements have multiselect__option--selected class.
input.querySelectorAll('li.multiselect__option--selected').length to be 2

});
});

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();
Copy link
Member

Choose a reason for hiding this comment

The 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

});

});
});
});