on master help sign in
bridge/src/lib/useImpliedTicket.test.ts
77 lines 2.2 kB history raw
1import useImpliedTicket from './useImpliedTicket';
3describe('#useImpliedTicket', () => {
4 const { location } = window;
6 beforeAll(() => {
7 delete window.location;
8 });
10 afterAll(() => {
11 window.location = location;
12 });
14 describe('when hash is not present in URL', () => {
15 it('returns null', () => {
16 const input = '';
17 window.location = { hash: input };
19 const {
20 impliedAzimuthPoint,
21 impliedPatp,
22 impliedTicket,
23 } = useImpliedTicket();
24 expect(impliedAzimuthPoint).toEqual(null);
25 expect(impliedPatp).toEqual(null);
26 expect(impliedTicket).toEqual(null);
27 });
28 });
30 describe('when hash is just a ticket', () => {
31 it('parses the ticket, returns null point', () => {
32 const input = '#widweb-tipfep-sabnux-nispec';
33 window.location = { hash: input };
35 const {
36 impliedAzimuthPoint,
37 impliedPatp,
38 impliedTicket,
39 } = useImpliedTicket();
40 expect(impliedAzimuthPoint).toEqual(null);
41 expect(impliedPatp).toEqual(null);
42 expect(impliedTicket).toEqual('~widweb-tipfep-sabnux-nispec');
43 });
44 });
46 describe('when hash has both ticket and star point', () => {
47 it('parses the ticket, returns null point', () => {
48 const input = '#widweb-tipfep-sabnux-nispec-sampel';
49 window.location = { hash: input };
51 const {
52 impliedAzimuthPoint,
53 impliedPatp,
54 impliedTicket,
55 } = useImpliedTicket();
56 expect(impliedAzimuthPoint).toEqual(1135);
57 expect(impliedPatp).toBe('~sampel');
58 expect(impliedTicket).toEqual('~widweb-tipfep-sabnux-nispec');
59 });
60 });
62 describe('when hash has both ticket and planet point', () => {
63 it('parses both ticket and point', () => {
64 const input = '#widweb-tipfep-sabnux-nispec-sampel-palnet';
65 window.location = { hash: input };
67 const {
68 impliedAzimuthPoint,
69 impliedPatp,
70 impliedTicket,
71 } = useImpliedTicket();
72 expect(impliedAzimuthPoint).toEqual(1624961343);
73 expect(impliedPatp).toBe('~sampel-palnet');
74 expect(impliedTicket).toEqual('~widweb-tipfep-sabnux-nispec');
75 });
76 });
77});