mirror of
https://gitee.com/vant-contrib/vant.git
synced 2026-07-11 08:41:05 +08:00
Compare commits
2 Commits
2f9f961bd8
...
2cc4ca63b5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cc4ca63b5 | ||
|
|
329cfcd703 |
@ -171,8 +171,9 @@ test('should free direction move when axis is "xy" ', async () => {
|
||||
});
|
||||
|
||||
test('should free direction move and magnetic to x axios when magnetic is "x" ', async () => {
|
||||
const restore = mockGetBoundingClientRect({ width: 48, height: 48 });
|
||||
vi.useFakeTimers();
|
||||
|
||||
const restore = mockGetBoundingClientRect({ width: 48, height: 48 });
|
||||
const root = document.createElement('div');
|
||||
mount(FloatingBubble, {
|
||||
props: {
|
||||
@ -187,8 +188,7 @@ test('should free direction move and magnetic to x axios when magnetic is "x" '
|
||||
)!;
|
||||
|
||||
await triggerDrag(floatingBubbleEl, -100, -100);
|
||||
|
||||
await later(400);
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
|
||||
expect(floatingBubbleEl.style.transform).toEqual(
|
||||
`translate3d(${window.innerWidth - 48 - 24}px, ${
|
||||
@ -197,19 +197,20 @@ test('should free direction move and magnetic to x axios when magnetic is "x" '
|
||||
);
|
||||
|
||||
await triggerDrag(floatingBubbleEl, -600, -100);
|
||||
|
||||
await later(400);
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
|
||||
expect(floatingBubbleEl.style.transform).toEqual(
|
||||
`translate3d(${24}px, ${window.innerHeight - 48 - 24 - 200}px, 0)`,
|
||||
);
|
||||
|
||||
restore();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test('should offset control positioning when use v-model:offset ', async () => {
|
||||
const restore = mockGetBoundingClientRect({ width: 48, height: 48 });
|
||||
vi.useFakeTimers();
|
||||
|
||||
const restore = mockGetBoundingClientRect({ width: 48, height: 48 });
|
||||
const root = document.createElement('div');
|
||||
const wrapper = mount(FloatingBubble, {
|
||||
props: {
|
||||
@ -227,8 +228,7 @@ test('should offset control positioning when use v-model:offset ', async () => {
|
||||
)!;
|
||||
|
||||
await triggerDrag(floatingBubbleEl, 100, 100);
|
||||
|
||||
await later(400);
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
|
||||
expect(floatingBubbleEl.style.transform).toEqual(
|
||||
`translate3d(${300}px, ${300}px, 0)`,
|
||||
@ -241,6 +241,7 @@ test('should offset control positioning when use v-model:offset ', async () => {
|
||||
});
|
||||
|
||||
restore();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test('should emit click when click wrapper', async () => {
|
||||
|
||||
@ -10,15 +10,17 @@ import {
|
||||
} from '../function-call';
|
||||
|
||||
test('toast disappeared after duration', async () => {
|
||||
vi.useFakeTimers();
|
||||
const onClose = vi.fn();
|
||||
showToast({
|
||||
duration: 10,
|
||||
onClose,
|
||||
});
|
||||
|
||||
expect(onClose).toHaveBeenCalledTimes(0);
|
||||
await later(50);
|
||||
expect(onClose).not.toHaveBeenCalled();
|
||||
await vi.advanceTimersByTimeAsync(100);
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test('show loading toast', async () => {
|
||||
@ -31,17 +33,19 @@ test('show loading toast', async () => {
|
||||
});
|
||||
|
||||
test('show html toast', async () => {
|
||||
vi.useFakeTimers();
|
||||
showToast({
|
||||
type: 'html',
|
||||
className: 'html-toast',
|
||||
message: '<div>Message</div>',
|
||||
});
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
await later(1000);
|
||||
const toastText = document.querySelector(
|
||||
'.html-toast .van-toast__text',
|
||||
) as HTMLDivElement;
|
||||
expect(toastText.innerHTML).toEqual('<div>Message</div>');
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test('icon prop', async () => {
|
||||
@ -108,15 +112,15 @@ test('clear multiple toast', async () => {
|
||||
});
|
||||
|
||||
test('remove toast DOM when cleared in multiple mode', async () => {
|
||||
vi.useFakeTimers();
|
||||
allowMultipleToast();
|
||||
closeToast(true);
|
||||
const toast = showToast({ className: 'remove-toast' });
|
||||
await later();
|
||||
|
||||
await toast.close();
|
||||
await later(100);
|
||||
toast.close();
|
||||
await vi.advanceTimersByTimeAsync(100);
|
||||
expect(document.querySelector('.remove-toast')).toBeNull();
|
||||
allowMultipleToast(false);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test('set default options', async () => {
|
||||
@ -151,13 +155,15 @@ test('set default options by type', async () => {
|
||||
});
|
||||
|
||||
test('toast duration 0', async () => {
|
||||
vi.useFakeTimers();
|
||||
allowMultipleToast();
|
||||
const onClose = vi.fn();
|
||||
showToast({ duration: 0, onClose });
|
||||
|
||||
await later(2100);
|
||||
expect(onClose).toHaveBeenCalledTimes(0);
|
||||
await vi.advanceTimersByTimeAsync(100);
|
||||
expect(onClose).not.toHaveBeenCalled();
|
||||
allowMultipleToast(false);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test('should trigger onClose callback after closed', async () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user