-
Notifications
You must be signed in to change notification settings - Fork 838
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
Showing
15 changed files
with
542 additions
and
500 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/nutui-taro-demo/src/exhibition/pages/popover/index.vue
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<Demo> | ||
<Demo style="padding-bottom: 200px"> | ||
<h2>{{ t('basic') }}</h2> | ||
<Basic /> | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<Demo> | ||
<Demo style="padding-bottom: 50px"> | ||
<h2>{{ t('basic') }}</h2> | ||
<Basic /> | ||
|
||
|
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import Popover from '../index.vue'; | ||
import { ref, nextTick } from 'vue'; | ||
import { sleep } from '@/packages/utils/unit'; | ||
|
||
const list = [{ name: 'option1' }, { name: 'option2' }, { name: 'option3' }]; | ||
|
||
const listDisabled = [{ name: 'option1', disabled: true }, { name: 'option2', disabled: true }, { name: 'option3' }]; | ||
|
||
test('Popover: first render', async () => { | ||
const wrapper = mount( | ||
() => { | ||
return <Popover visible={true} list={list} />; | ||
}, | ||
{ | ||
global: { | ||
stubs: { | ||
teleport: true | ||
} | ||
} | ||
} | ||
); | ||
expect(wrapper.find('.nut-popover-menu-item').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('Popover: theme=dark', async () => { | ||
const wrapper = mount( | ||
() => { | ||
return <Popover visible={true} list={list} theme="dark" />; | ||
}, | ||
{ | ||
global: { | ||
stubs: { | ||
teleport: true | ||
} | ||
} | ||
} | ||
); | ||
expect(wrapper.find('.nut-popover--dark').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('Popover: disabled', async () => { | ||
const wrapper = mount( | ||
() => { | ||
return <Popover visible={true} list={listDisabled} theme="dark" />; | ||
}, | ||
{ | ||
global: { | ||
stubs: { | ||
teleport: true | ||
} | ||
} | ||
} | ||
); | ||
expect(wrapper.findAll('.nut-popover-menu-disabled').length).toEqual(2); | ||
|
||
wrapper.find('.nut-popover-menu-item').trigger('click'); | ||
expect(wrapper.emitted('choose')).toBeFalsy(); | ||
}); | ||
|
||
test('Popover: should close popover when clicking the action', async () => { | ||
const show = ref(true); | ||
const close = ref(true); | ||
const wrapper = mount( | ||
() => { | ||
return <Popover v-model:visible={show.value} list={list} closeOnClickAction={close.value} />; | ||
}, | ||
{ | ||
global: { | ||
stubs: { | ||
teleport: true | ||
} | ||
} | ||
} | ||
); | ||
const items = wrapper.findAll('.nut-popover-menu-item'); | ||
await items[0].trigger('click'); | ||
expect(show.value).toEqual(false); | ||
|
||
show.value = true; | ||
close.value = false; | ||
await nextTick(); | ||
expect(show.value).toEqual(true); | ||
const item = wrapper.find('.nut-popover-menu-item'); | ||
await item.trigger('click'); | ||
expect(show.value).toEqual(true); | ||
}); | ||
|
||
test('Popover: position=top-start', async () => { | ||
const wrapper = mount( | ||
() => { | ||
return <Popover visible={true} list={list} location="top-start" />; | ||
}, | ||
{ | ||
global: { | ||
stubs: { | ||
teleport: true | ||
} | ||
} | ||
} | ||
); | ||
expect(wrapper.find('.nut-popover-arrow--top-start').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('Popover: position=left-end', async () => { | ||
const wrapper = mount( | ||
() => { | ||
return <Popover visible={true} list={list} location="left-end" />; | ||
}, | ||
{ | ||
global: { | ||
stubs: { | ||
teleport: true | ||
} | ||
} | ||
} | ||
); | ||
expect(wrapper.find('.nut-popover-arrow--left-end').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('Popover: target', async () => { | ||
const p = document.createElement('div'); | ||
p.id = 'popover-target'; | ||
p.getBoundingClientRect = vi.fn(() => { | ||
return { | ||
width: 300, | ||
height: 100, | ||
left: 0, | ||
top: 0, | ||
right: 300 | ||
} as DOMRect; | ||
}); | ||
document.body.appendChild(p); | ||
const show = ref(false); | ||
const wrapper = mount( | ||
() => { | ||
return ( | ||
<Popover v-model:visible={show.value} duration={0} targetId="popover-target" list={list} arrowOffset={16} /> | ||
); | ||
}, | ||
{ | ||
global: { | ||
stubs: { | ||
teleport: true | ||
} | ||
} | ||
} | ||
); | ||
show.value = true; | ||
await sleep(200); | ||
const popoverWrapper = wrapper.find('.nut-popover'); | ||
expect(popoverWrapper.attributes('style')).contain('top: 112px;'); | ||
expect(popoverWrapper.attributes('style')).contain('left: 150px;'); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<Demo> | ||
<Demo style="padding-bottom: 200px"> | ||
<h2>{{ t('basic') }}</h2> | ||
<Basic /> | ||
|
||
|
Oops, something went wrong.