| 1 |
import { DelegateEvent } from 'delegate-it'; |
| 2 |
import { describe, expect, it, vi } from 'vitest'; |
| 3 |
|
| 4 |
import Swup from '../../src/index.js'; |
| 5 |
|
| 6 |
const baseUrl = window.location.origin; |
| 7 |
|
| 8 |
describe('ignoreVisit', () => { |
| 9 |
it('should be called with relative URL', () => { |
| 10 |
const ignoreVisit = vi.fn(() => true); |
| 11 |
const swup = new Swup({ ignoreVisit }); |
| 12 |
swup.shouldIgnoreVisit(`${baseUrl}/path/?query#hash`); |
| 13 |
|
| 14 |
expect(ignoreVisit.mock.calls).toHaveLength(1); |
| 15 |
expect((ignoreVisit.mock.lastCall as any)[0]).toEqual('/path/?query#hash'); |
| 16 |
}); |
| 17 |
|
| 18 |
it('should have access to element and event params', () => { |
| 19 |
const el = document.createElement('a'); |
| 20 |
el.href = `${baseUrl}/path/?query#hash`; |
| 21 |
const event = new MouseEvent('click') as DelegateEvent<MouseEvent>; |
| 22 |
event.delegateTarget = el; |
| 23 |
|
| 24 |
const ignoreVisit = vi.fn(() => true); |
| 25 |
const swup = new Swup({ ignoreVisit }); |
| 26 |
swup.navigate(el.href, {}, { el, event }); |
| 27 |
|
| 28 |
expect(ignoreVisit.mock.calls).toHaveLength(1); |
| 29 |
expect((ignoreVisit.mock.lastCall as any)[1]).toEqual( |
| 30 |
expect.objectContaining({ el, event }) |
| 31 |
); |
| 32 |
}); |
| 33 |
|
| 34 |
it('should be called from visit method', () => { |
| 35 |
const ignoreVisit = vi.fn(() => true); |
| 36 |
const swup = new Swup({ ignoreVisit }); |
| 37 |
swup.navigate('/path/'); |
| 38 |
|
| 39 |
expect(ignoreVisit.mock.calls).toHaveLength(1); |
| 40 |
}); |
| 41 |
}); |