-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
1 parent
4bdfcec
commit c5f4bf7
Showing
3 changed files
with
84 additions
and
2 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
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
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,81 @@ | ||
import { createTest, createVue } from '../util'; | ||
import Switch from 'packages/switch'; | ||
import Vue from 'vue'; | ||
|
||
describe('Switch', () => { | ||
it('create', () => { | ||
const vm = createTest(Switch, { | ||
onText: 'on', | ||
offText: 'off', | ||
onColor: '#0f0', | ||
offColor: '#f00', | ||
width: 100 | ||
}); | ||
|
||
const core = vm.$el.querySelector('.el-switch__core'); | ||
expect(core.style.backgroundColor).to.equal('rgb(0, 255, 0)'); | ||
expect(core.style.width).to.equal('100px'); | ||
expect(vm.$el.querySelector('.el-switch__label--left').querySelector('span').textContent).to.equal('on'); | ||
}); | ||
|
||
it('switch with icons', () => { | ||
const vm = createTest(Switch, { | ||
onIconClass: 'el-icon-check', | ||
offIconClass: 'el-icon-close', | ||
}); | ||
|
||
const icon = vm.$el.querySelector('.el-switch__label--left').querySelector('i'); | ||
expect(icon.classList.contains('el-icon-check')).to.true; | ||
}); | ||
|
||
it('value correctly update', done => { | ||
const vm = createVue({ | ||
template: ` | ||
<div> | ||
<el-switch v-model="value"></el-switch> | ||
</div> | ||
`, | ||
|
||
data() { | ||
return { | ||
value: true | ||
}; | ||
} | ||
}, true); | ||
|
||
const core = vm.$el.querySelector('.el-switch__core'); | ||
const input = vm.$el.querySelector('input'); | ||
const button = vm.$el.querySelector('.el-switch__button'); | ||
core.click(); | ||
Vue.nextTick(() => { | ||
expect(vm.value).to.equal(false); | ||
expect(getComputedStyle(core).backgroundColor).to.equal('rgb(192, 204, 218)'); | ||
expect(button.style.transform).to.equal('translate3d(2px, 2px, 0)'); | ||
core.click(); | ||
expect(vm.value).to.equal(true); | ||
done(); | ||
}); | ||
}); | ||
|
||
it ('disabled switch should not respond to user click', done => { | ||
const vm = createVue({ | ||
template: ` | ||
<div> | ||
<el-switch disabled v-model="value"></el-switch> | ||
</div> | ||
`, | ||
|
||
data() { | ||
return { | ||
value: true | ||
}; | ||
} | ||
}, true); | ||
|
||
vm.$el.querySelector('.el-switch__core').click(); | ||
Vue.nextTick(() => { | ||
expect(vm.value).to.true; | ||
done(); | ||
}); | ||
}); | ||
}); |