Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Commit

Permalink
fix(radio): missing watcher for value (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
tychenjiajun authored and matsp committed May 23, 2019
1 parent ad51fea commit cb6bd2d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 deletions.
23 changes: 3 additions & 20 deletions components/radio/Radio.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<template>
<div class="mdc-radio">
<input
:id="id"
:checked="checked"
:class="classes"
:disabled="disabled"
:name="name"
class="mdc-radio__native-control"
type="radio"
v-bind="$attrs"
Expand Down Expand Up @@ -41,34 +36,22 @@ export default {
value: {
type: String,
default: ''
},
name: {
type: String,
default: ''
},
id: {
type: String,
default: ''
}
},
data () {
return {
mdcRadio: undefined
}
},
computed: {
classes () {
return {
'mdc-radio--disabled': this.disabled
}
}
},
watch: {
checked () {
this.mdcRadio.checked = this.checked
},
disabled () {
this.mdcRadio.disabled = this.disabled
},
value () {
this.mdcRadio.value = this.value
}
},
mounted () {
Expand Down
42 changes: 42 additions & 0 deletions components/radio/__test__/Radio.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'mutationobserver-shim'
import { mount } from '@vue/test-utils'
import Radio from '../Radio.vue'

describe('Checkbox', () => {
it('should mount', () => {
let wrapper = mount(Radio)
expect(wrapper.isVueInstance()).toBeTruthy()
expect(wrapper.vm.$data.mdcRadio).toBeDefined()
})

it('should render with no prop', () => {
let wrapper = mount(Radio)
expect(wrapper).toMatchSnapshot()
expect(wrapper.classes()).toContain('mdc-radio')
expect(wrapper.find('input').attributes('disabled')).toBeUndefined()
})

it('should render as disabled', () => {
let wrapper = mount(Radio, {
propsData: {
disabled: true
}
})
expect(wrapper).toMatchSnapshot()
expect(wrapper.classes()).toContain('mdc-radio--disabled')
expect(wrapper.find('input').attributes('disabled')).toBeDefined()
})

it('should render and emit', () => {
let wrapper = mount(Radio, {
propsData: {
value: 'val'
}
})

const radio = wrapper.find('input')
radio.setChecked(true)
expect(wrapper.emitted().change.length).toBe(1)
expect(wrapper.emitted().change[0]).toEqual(['val'])
})
})
19 changes: 19 additions & 0 deletions components/radio/__test__/__snapshots__/Radio.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Checkbox should render as disabled 1`] = `
<div class="mdc-radio mdc-radio--disabled"><input type="radio" class="mdc-radio__native-control" disabled="" value="">
<div class="mdc-radio__background">
<div class="mdc-radio__outer-circle"></div>
<div class="mdc-radio__inner-circle"></div>
</div>
</div>
`;
exports[`Checkbox should render with no prop 1`] = `
<div class="mdc-radio"><input type="radio" class="mdc-radio__native-control" value="">
<div class="mdc-radio__background">
<div class="mdc-radio__outer-circle"></div>
<div class="mdc-radio__inner-circle"></div>
</div>
</div>
`;

0 comments on commit cb6bd2d

Please sign in to comment.