-
Notifications
You must be signed in to change notification settings - Fork 0
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
c639d76
commit b731203
Showing
6 changed files
with
162 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Vitest unit test spec file | ||
|
||
import { describe, it, expect } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import { h } from 'vue' | ||
import ToolbarButton from './ToolbarButton.vue' | ||
|
||
describe('<ToolbarButton />', () => { | ||
it('renders the default button', async () => { | ||
const slotContent = 'This is the button text' | ||
|
||
const wrapper = await mount(ToolbarButton, { | ||
slots: { | ||
default: () => h('button', {}, slotContent), | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('button.toolbar-button').isVisible()).toBe(true) | ||
expect(wrapper.find('button.toolbar-button').attributes('tabindex')).toEqual('0') | ||
expect(wrapper.find('button.toolbar-button').attributes('type')).toEqual('button') | ||
expect(wrapper.find('button.toolbar-button').attributes('class')).not.toContain('primary') | ||
expect(wrapper.find('button.toolbar-button').attributes('class')).toContain('secondary') | ||
expect(wrapper.find('button.toolbar-button').attributes('class')).not.toContain('has-text') | ||
expect(wrapper.find('button').text()).toEqual(slotContent) | ||
}) | ||
|
||
describe('props', () => { | ||
it('renders the non-icon button', async () => { | ||
const slotContent = 'This is the button text' | ||
|
||
const wrapper = await mount(ToolbarButton, { | ||
props: { | ||
icon: false, | ||
}, | ||
slots: { | ||
default: () => h('button', {}, slotContent), | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('button.toolbar-button').isVisible()).toBe(true) | ||
expect(wrapper.find('button.toolbar-button').attributes('tabindex')).toEqual('0') | ||
expect(wrapper.find('button.toolbar-button').attributes('type')).toEqual('button') | ||
expect(wrapper.find('button.toolbar-button').attributes('class')).toContain('has-text') | ||
expect(wrapper.find('button').text()).toEqual(slotContent) | ||
}) | ||
|
||
it('renders the `primary` appearance', async () => { | ||
const slotContent = 'This is the button text' | ||
|
||
const wrapper = await mount(ToolbarButton, { | ||
props: { | ||
icon: false, | ||
appearance: 'primary', | ||
}, | ||
slots: { | ||
default: () => h('button', {}, slotContent), | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('button.toolbar-button').isVisible()).toBe(true) | ||
expect(wrapper.find('button.toolbar-button').attributes('tabindex')).toEqual('0') | ||
expect(wrapper.find('button.toolbar-button').attributes('type')).toEqual('button') | ||
expect(wrapper.find('button.toolbar-button').attributes('class')).toContain('primary') | ||
expect(wrapper.find('button.toolbar-button').attributes('class')).not.toContain('secondary') | ||
expect(wrapper.find('button.toolbar-button').attributes('class')).toContain('has-text') | ||
expect(wrapper.find('button').text()).toEqual(slotContent) | ||
}) | ||
}) | ||
}) |
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,65 @@ | ||
// Vitest unit test spec file | ||
|
||
import { describe, it, expect } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import TooltipShortcut from './TooltipShortcut.vue' | ||
|
||
describe('<TooltipShortcut />', () => { | ||
it('renders the shortcut with no keys', async () => { | ||
const text = 'Shortcut name' | ||
|
||
const wrapper = await mount(TooltipShortcut, { | ||
props: { | ||
text, | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('.tooltip-shortcut').isVisible()).toBe(true) | ||
expect(wrapper.findTestId('shortcut-text').text()).toContain(text) | ||
expect(wrapper.findTestId('keys').exists()).toBe(false) | ||
}) | ||
|
||
it('does not render the shortcut if the `text` prop does not have a value', async () => { | ||
const wrapper = await mount(TooltipShortcut, { | ||
props: { | ||
text: '', | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('.tooltip-shortcut').exists()).toBe(false) | ||
}) | ||
|
||
it('displays the shortcut text along with a single key', async () => { | ||
const text = 'Bold' | ||
const keys = ['B'] | ||
|
||
const wrapper = await mount(TooltipShortcut, { | ||
props: { | ||
text, | ||
keys, | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('.tooltip-shortcut').exists()).toBe(true) | ||
expect(wrapper.findTestId('shortcut-text').text()).toContain(text) | ||
expect(wrapper.findAll('.meta-key').length).toEqual(1) | ||
expect(wrapper.findAll('kbd').length).toEqual(keys.length + 1) | ||
}) | ||
|
||
it('displays the shortcut text along with multiple keys', async () => { | ||
const text = 'Strikethrough' | ||
const keys = ['Shift', 'X'] | ||
|
||
const wrapper = await mount(TooltipShortcut, { | ||
props: { | ||
text, | ||
keys, | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('.tooltip-shortcut').exists()).toBe(true) | ||
expect(wrapper.findTestId('shortcut-text').text()).toContain(text) | ||
expect(wrapper.findAll('.meta-key').length).toEqual(1) | ||
expect(wrapper.findAll('kbd').length).toEqual(keys.length + 1) | ||
}) | ||
}) |
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,7 @@ | ||
import type { DOMWrapper } from '@vue/test-utils' | ||
|
||
declare module '@vue/test-utils' { | ||
export class VueWrapper { | ||
findTestId(dataTestid: string): DOMWrapper; | ||
} | ||
} |
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,15 @@ | ||
import { config, DOMWrapper } from '@vue/test-utils' | ||
|
||
const DataTestIdPlugin = (wrapper: any) => { | ||
const findTestId = (dataTestid: string): any => { | ||
const dataSelector = `[data-testid='${dataTestid}']` | ||
const element = wrapper.element.querySelector(dataSelector) | ||
return new DOMWrapper(element) | ||
} | ||
|
||
return { | ||
findTestId, | ||
} | ||
} | ||
|
||
config.plugins.VueWrapper.install(DataTestIdPlugin) |