-
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
b4c375f
commit b29ef86
Showing
14 changed files
with
504 additions
and
101 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -134,4 +134,4 @@ | |
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} | ||
} |
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,89 @@ | ||
import { describe, it, expect, beforeEach } from 'vitest'; | ||
import { shallowMount } from '@vue/test-utils'; | ||
import PdapDropdown from './PdapDropdown.vue'; | ||
import { PdapDropdownTriggerType } from './types'; | ||
|
||
let wrapper; | ||
let trigger; | ||
let content; | ||
|
||
describe('PdapDropdown', () => { | ||
beforeEach(() => { | ||
wrapper = shallowMount(PdapDropdown, { | ||
slots: { | ||
trigger: 'Toggle Dropdown', | ||
content: '<ul><li>Option 1</li><li>Option 2</li><li>Option 3</li></ul>', | ||
}, | ||
attachTo: document.body, | ||
}); | ||
|
||
trigger = wrapper.find('[data-test="dropdown-trigger"]'); | ||
content = wrapper.find('[data-test="dropdown-content"]'); | ||
}); | ||
|
||
it('should open and close dropdown correctly', async () => { | ||
expect(content.isVisible()).toBe(false); | ||
|
||
await trigger.trigger('click'); | ||
expect(content.isVisible()).toBe(true); | ||
|
||
await trigger.trigger('click'); | ||
expect(content.isVisible()).toBe(false); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should be accessible with keyboard', async () => { | ||
expect(content.isVisible()).toBe(false); | ||
|
||
await trigger.trigger('keydown.enter'); | ||
expect(content.isVisible()).toBe(true); | ||
|
||
await trigger.trigger('keydown.escape'); | ||
expect(content.isVisible()).toBe(false); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should respect disabled prop', async () => { | ||
wrapper = shallowMount(PdapDropdown, { | ||
props: { | ||
disabled: true, | ||
}, | ||
slots: { | ||
trigger: 'Toggle Dropdown', | ||
content: '<ul><li>Option 1</li><li>Option 2</li><li>Option 3</li></ul>', | ||
}, | ||
attachTo: document.body, | ||
}); | ||
trigger = wrapper.find('[data-test="dropdown-trigger"]'); | ||
content = wrapper.find('[data-test="dropdown-content"]'); | ||
|
||
await trigger.trigger('click'); | ||
expect(content.isVisible()).toBe(false); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should respect the triggerOn prop', async () => { | ||
wrapper = shallowMount(PdapDropdown, { | ||
props: { | ||
triggerOn: PdapDropdownTriggerType.HOVER, | ||
}, | ||
slots: { | ||
trigger: 'Toggle Dropdown', | ||
content: '<ul><li>Option 1</li><li>Option 2</li><li>Option 3</li></ul>', | ||
}, | ||
attachTo: document.body, | ||
}); | ||
trigger = wrapper.find('[data-test="dropdown-trigger"]'); | ||
content = wrapper.find('[data-test="dropdown-content"]'); | ||
|
||
await trigger.trigger('focusin'); | ||
expect(content.isVisible()).toBe(true); | ||
|
||
await trigger.trigger('focusout'); | ||
expect(content.isVisible()).toBe(false); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.