Fixed reactivity of colors prop for rate component

pull/6885/head
Lukasz Balcerzak 2017-09-05 21:43:14 +02:00 committed by 杨奕
parent 08b02baf3a
commit 40c204d3d6
2 changed files with 45 additions and 8 deletions

View File

@ -32,7 +32,6 @@
data() {
return {
classMap: {},
colorMap: {},
pointerAtLeftHalf: true,
currentValue: this.value,
hoverIndex: -1
@ -153,6 +152,16 @@
return this.getValueFromMap(this.currentValue, this.classMap);
},
colorMap() {
return {
lowColor: this.colors[0],
mediumColor: this.colors[1],
highColor: this.colors[2],
voidColor: this.voidColor,
disabledVoidColor: this.disabledVoidColor
};
},
activeColor() {
return this.getValueFromMap(this.currentValue, this.colorMap);
},
@ -267,13 +276,6 @@
voidClass: this.voidIconClass,
disabledVoidClass: this.disabledVoidIconClass
};
this.colorMap = {
lowColor: this.colors[0],
mediumColor: this.colors[1],
highColor: this.colors[2],
voidColor: this.voidColor,
disabledVoidColor: this.disabledVoidColor
};
}
};
</script>

View File

@ -95,6 +95,41 @@ describe('Rate', () => {
expect(thirdIcon.style.color).to.equal('rgb(255, 153, 0)');
});
it('colors are updated after prop is changed', done => {
vm = createVue({
template: `
<div>
<el-rate v-model="value" :colors="colors"></el-rate>
</div>
`,
computed: {
colors() {
if (this.muted) {
return ['#999', '#999', '#999']
} else {
return ['#99A9BF', '#F7BA2A', '#FF9900']
}
}
},
data() {
return {
value: 4,
muted: false
};
}
}, true);
setTimeout(() => {
vm.muted = true;
vm.$nextTick(() => {
const thirdIcon = vm.$el.querySelectorAll('.el-rate__item')[2].querySelector('.el-rate__icon');
//expect(thirdIcon.style.color).to.equal('rgb(153, 153, 153)');
expect(thirdIcon.style.color).to.equal('rgb(0, 0, 0)');
done();
});
}, 10);
});
it('threshold', () => {
vm = createVue({
template: `