Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(NcButton): Add
pressed
state for stateful buttons, like the `N…
…cAppSidebar` star button Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
- Loading branch information
Showing
3 changed files
with
131 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,23 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import NcButton from '../../../../src/components/NcButton/NcButton.vue' | ||
|
||
describe('NcButton', () => { | ||
it('emits update:pressed', async () => { | ||
const wrapper = shallowMount(NcButton, { propsData: { pressed: true, ariaLabel: 'button' } }) | ||
wrapper.findComponent('button').trigger('click') | ||
expect(wrapper.emitted('update:pressed')?.length).toBe(1) | ||
expect(wrapper.emitted('update:pressed')[0]).toEqual([false]) | ||
|
||
// Now the same but when pressed was false | ||
await wrapper.setProps({ pressed: false }) | ||
wrapper.findComponent('button').trigger('click') | ||
expect(wrapper.emitted('update:pressed')?.length).toBe(2) | ||
expect(wrapper.emitted('update:pressed')[1]).toEqual([true]) | ||
}) | ||
|
||
it('does not emit update:pressed when not configured', async () => { | ||
const wrapper = shallowMount(NcButton, { propsData: { ariaLabel: 'button' } }) | ||
wrapper.findComponent('button').trigger('click') | ||
expect(wrapper.emitted('update:pressed')).toBe(undefined) | ||
}) | ||
}) |