Debian Codegraph @

tests/unit/visit.test.ts

raw
1 import { beforeEach, describe, expect, it } from 'vitest';
2 import Swup from '../../src/Swup.js';
3 import { Visit, createVisit } from '../../src/modules/Visit.js';
4
5 class SwupWithPublicVisitMethods extends Swup {
6 public createVisit = createVisit;
7 }
8
9 const swup = new SwupWithPublicVisitMethods();
10 let visit: Visit;
11
12 describe('Visit', () => {
13 beforeEach(() => {
14 visit = swup.createVisit({ to: '' });
15 });
16
17 it('is an object', () => {
18 expect(visit).to.be.an('object');
19 });
20
21 it('is a Visit instance', () => {
22 expect(visit).to.be.instanceof(Visit);
23 });
24
25 it('has an id', () => {
26 expect(visit.id).to.be.a('number');
27 });
28
29 it('generates unique ids', () => {
30 let id = visit.id;
31 visit = swup.createVisit({ to: '' });
32 expect(visit.id).to.not.equal(id);
33 });
34
35 it('has a from object with the current URL', () => {
36 expect(visit.from).to.be.an('object');
37 expect(visit.from.url).to.be.a('string');
38 visit = swup.createVisit({ to: '', from: '/from' });
39 expect(visit.from).toMatchObject({ url: '/from' });
40 });
41
42 it('has a to object with the next URL', () => {
43 expect(visit.to).to.be.an('object');
44 expect(visit.to.url).to.be.a('string');
45 visit = swup.createVisit({ to: '/to' });
46 expect(visit.to).toMatchObject({ url: '/to' });
47 });
48
49 it('has an animation object', () => {
50 expect(visit.animation).to.be.an('object');
51 expect(visit.animation).toMatchObject({
52 animate: true,
53 name: undefined,
54 scope: swup.options.animationScope,
55 selector: swup.options.animationSelector
56 });
57 });
58
59 it('has a container array', () => {
60 expect(visit.containers).to.be.an('array');
61 expect(visit.containers).toEqual(swup.options.containers);
62 });
63
64 it('has a trigger object', () => {
65 expect(visit.trigger).to.be.an('object');
66 expect(visit.trigger).toMatchObject({
67 el: undefined,
68 event: undefined
69 });
70 });
71
72 it('has a cache object', () => {
73 expect(visit.cache).to.be.an('object');
74 expect(visit.cache).toEqual({
75 read: swup.options.cache,
76 write: swup.options.cache
77 });
78 });
79
80 it('has a history object', () => {
81 expect(visit.history).to.be.an('object');
82 expect(visit.history).toEqual({
83 action: 'push',
84 popstate: false,
85 direction: undefined
86 });
87 });
88
89 it('has a scroll object', () => {
90 expect(visit.scroll).to.be.an('object');
91 expect(visit.scroll).toEqual({
92 reset: true,
93 target: undefined
94 });
95 });
96
97 it('has a meta object', () => {
98 expect(visit.meta).to.be.an('object');
99 expect(visit.meta).toEqual({});
100 });
101 });