This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(switch): bind all attributes to inner input (#426)
* feat(switch): bind attributes to inner input element Previously only id bind to it using `id` prop, which may be a limitation in a11y. * test(switch): add snapshots * test(switch): add snapshots
- Loading branch information
1 parent
ff6379c
commit 3f649a7
Showing
5 changed files
with
96 additions
and
14 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,55 @@ | ||
import { mount } from '@vue/test-utils' | ||
import Switch from '../Switch.vue' | ||
|
||
describe('Switch', () => { | ||
it('should mount', () => { | ||
const wrapper = mount(Switch) | ||
expect(wrapper.isVueInstance()).toBeTruthy() | ||
expect(wrapper.vm.$data.mdcSwitch).toBeDefined() | ||
}) | ||
|
||
it('should render with no prop', () => { | ||
const wrapper = mount(Switch) | ||
expect(wrapper).toMatchSnapshot() | ||
expect(wrapper.classes()).toContain('mdc-switch') | ||
expect(wrapper.find('input').attributes('disabled')).toBeUndefined() | ||
}) | ||
|
||
it('should render as disabled', () => { | ||
const wrapper = mount(Switch, { | ||
propsData: { | ||
disabled: true | ||
} | ||
}) | ||
expect(wrapper).toMatchSnapshot() | ||
expect(wrapper.classes()).toContain('mdc-switch--disabled') | ||
expect(wrapper.find('input').attributes('disabled')).toBeDefined() | ||
}) | ||
|
||
it('should render as checked', () => { | ||
const wrapper = mount(Switch, { | ||
propsData: { | ||
checked: true | ||
} | ||
}) | ||
expect(wrapper).toMatchSnapshot() | ||
expect(wrapper.vm.$data.mdcSwitch.checked).toBeTruthy() | ||
expect(wrapper.find('input').element.checked).toBeTruthy() | ||
}) | ||
|
||
it('should render and emit', () => { | ||
const wrapper = mount(Switch) | ||
|
||
const input = wrapper.find('input') | ||
|
||
input.setChecked() | ||
expect(wrapper.emitted().change).toBeTruthy() | ||
expect(wrapper.vm.$data.mdcSwitch.checked).toBeTruthy() | ||
expect(wrapper.find('input').element.checked).toBeTruthy() | ||
|
||
input.setChecked(false) | ||
expect(wrapper.emitted().change).toBeTruthy() | ||
expect(wrapper.vm.$data.mdcSwitch.checked).toBeFalsy() | ||
expect(wrapper.find('input').element.checked).toBeFalsy() | ||
}) | ||
}) |
28 changes: 28 additions & 0 deletions
28
components/switch/__test__/__snapshots__/Switch.spec.js.snap
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,28 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Switch should render as checked 1`] = ` | ||
<div class="mdc-switch mdc-switch--checked"> | ||
<div class="mdc-switch__track"></div> | ||
<div class="mdc-switch__thumb-underlay"> | ||
<div class="mdc-switch__thumb"><input role="switch" type="checkbox" class="mdc-switch__native-control"></div> | ||
</div> | ||
</div> | ||
`; | ||
exports[`Switch should render as disabled 1`] = ` | ||
<div class="mdc-switch mdc-switch--disabled"> | ||
<div class="mdc-switch__track"></div> | ||
<div class="mdc-switch__thumb-underlay"> | ||
<div class="mdc-switch__thumb"><input disabled="" role="switch" type="checkbox" class="mdc-switch__native-control"></div> | ||
</div> | ||
</div> | ||
`; | ||
exports[`Switch should render with no prop 1`] = ` | ||
<div class="mdc-switch"> | ||
<div class="mdc-switch__track"></div> | ||
<div class="mdc-switch__thumb-underlay"> | ||
<div class="mdc-switch__thumb"><input role="switch" type="checkbox" class="mdc-switch__native-control"></div> | ||
</div> | ||
</div> | ||
`; |
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