mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-11-06 01:50:42 +00:00
test: 修复 Popconfirm 浮层断言在多浮层场景下定位错误
侧栏删除图标外层新增 Tooltip 后,querySelector('.el-popper') 可能命中 Tooltip 浮层。
改为按文案定位 Popconfirm 浮层,table 用例改为取最后挂载的 popper。
This commit is contained in:
parent
39ca916b88
commit
86fe545e8f
@ -52,12 +52,16 @@ const clickConfirm = async () => {
|
||||
confirmBtn?.click();
|
||||
};
|
||||
|
||||
/** 删除图标外层还有 Tooltip,需按文案定位 Popconfirm 自己的浮层 */
|
||||
const getPopconfirmPopper = (text: string) =>
|
||||
Array.from(document.querySelectorAll('.el-popper')).find((el) => (el.textContent || '').includes(text));
|
||||
|
||||
/** 浮层需挂载到 body,且 placement 真正作用到 popper 上 */
|
||||
const expectRightPlacement = async (wrapper: { element: Element }) => {
|
||||
const expectRightPlacement = async (wrapper: { element: Element }, text: string) => {
|
||||
await vi.waitFor(() => {
|
||||
expect(document.querySelector('.el-popper')?.getAttribute('data-popper-placement')).toBe('right');
|
||||
expect(getPopconfirmPopper(text)?.getAttribute('data-popper-placement')).toBe('right');
|
||||
});
|
||||
const popper = document.querySelector('.el-popper');
|
||||
const popper = getPopconfirmPopper(text);
|
||||
expect(popper).toBeTruthy();
|
||||
expect(wrapper.element.contains(popper!)).toBe(false);
|
||||
};
|
||||
@ -70,7 +74,7 @@ describe('侧栏删除 Popconfirm(真实 element-plus)', () => {
|
||||
await vi.waitFor(() => {
|
||||
expect(document.body.textContent).toContain('确定删除?');
|
||||
});
|
||||
await expectRightPlacement(wrapper);
|
||||
await expectRightPlacement(wrapper, '确定删除?');
|
||||
expect(wrapper.emitted('remove')).toBeFalsy();
|
||||
|
||||
await clickConfirm();
|
||||
@ -88,7 +92,7 @@ describe('侧栏删除 Popconfirm(真实 element-plus)', () => {
|
||||
await vi.waitFor(() => {
|
||||
expect(document.body.textContent).toContain('确定删除该代码块吗?');
|
||||
});
|
||||
await expectRightPlacement(wrapper);
|
||||
await expectRightPlacement(wrapper, '确定删除该代码块吗?');
|
||||
expect(wrapper.emitted('remove')).toBeFalsy();
|
||||
|
||||
await clickConfirm();
|
||||
|
||||
@ -124,8 +124,10 @@ describe('TMagicPopconfirm placement(真实 element-plus)', () => {
|
||||
])('placement=%s 作用到 popper 的 %s', async (placement, expected) => {
|
||||
const wrapper = mountPopconfirm(placement);
|
||||
await wrapper.find('.ref').trigger('click');
|
||||
// 取最后挂载的 popper,避免命中此前用例残留的浮层
|
||||
const popper = () => Array.from(document.querySelectorAll('.el-popper')).at(-1);
|
||||
await vi.waitFor(() => {
|
||||
expect(document.querySelector('.el-popper')?.getAttribute('data-popper-placement')).toBe(expected);
|
||||
expect(popper()?.getAttribute('data-popper-placement')).toBe(expected);
|
||||
});
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user