File size: 3,278 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {
  extractInterceptionRouteInformation,
  isInterceptionRouteAppPath,
} from './interception-routes'

describe('Interception Route helper', () => {
  describe('isInterceptionRouteAppPath', () => {
    it('should validate correct paths', () => {
      expect(isInterceptionRouteAppPath('/foo/(..)/bar')).toBe(true)
      expect(isInterceptionRouteAppPath('/foo/(...)/bar')).toBe(true)
      expect(isInterceptionRouteAppPath('/foo/(..)(..)/bar')).toBe(true)
      expect(isInterceptionRouteAppPath('/foo/(.)bar')).toBe(true)
    })
    it('should not validate incorrect paths', () => {
      expect(isInterceptionRouteAppPath('/foo/(..')).toBe(false)
      expect(isInterceptionRouteAppPath('/foo/..)/bar')).toBe(false)
      expect(isInterceptionRouteAppPath('/foo')).toBe(false)
    })
  })
  describe('extractInterceptionRouteInformation', () => {
    it('should extract correct information', () => {
      expect(extractInterceptionRouteInformation('/foo/(..)bar')).toEqual({
        interceptingRoute: '/foo',
        interceptedRoute: '/bar',
      })

      expect(extractInterceptionRouteInformation('/foo/(...)bar')).toEqual({
        interceptingRoute: '/foo',
        interceptedRoute: '/bar',
      })

      expect(
        extractInterceptionRouteInformation('/foo/bar/(..)(..)baz')
      ).toEqual({ interceptingRoute: '/foo/bar', interceptedRoute: '/baz' })

      expect(
        extractInterceptionRouteInformation('/foo/(group)/bar/(..)(..)baz')
      ).toEqual({ interceptingRoute: '/foo/bar', interceptedRoute: '/baz' })

      expect(
        extractInterceptionRouteInformation('/foo/bar/@modal/(..)(..)baz')
      ).toEqual({ interceptingRoute: '/foo/bar', interceptedRoute: '/baz' })

      expect(extractInterceptionRouteInformation('/foo/bar/(.)baz')).toEqual({
        interceptingRoute: '/foo/bar',
        interceptedRoute: '/foo/bar/baz',
      })
    })
    it('should not extract incorrect information', () => {
      expect(() =>
        extractInterceptionRouteInformation('/foo/(..')
      ).toThrowErrorMatchingInlineSnapshot(
        `"Invalid interception route: /foo/(... Must be in the format /<intercepting route>/(..|...|..)(..)/<intercepted route>"`
      )
      expect(() =>
        extractInterceptionRouteInformation('/foo/..)/bar')
      ).toThrowErrorMatchingInlineSnapshot(
        `"Invalid interception route: /foo/..)/bar. Must be in the format /<intercepting route>/(..|...|..)(..)/<intercepted route>"`
      )
      expect(() =>
        extractInterceptionRouteInformation('/foo')
      ).toThrowErrorMatchingInlineSnapshot(
        `"Invalid interception route: /foo. Must be in the format /<intercepting route>/(..|...|..)(..)/<intercepted route>"`
      )
    })
    it('should check the segment length', () => {
      expect(() =>
        extractInterceptionRouteInformation('/(..)bar')
      ).toThrowErrorMatchingInlineSnapshot(
        `"Invalid interception route: /(..)bar. Cannot use (..) marker at the root level, use (.) instead."`
      )
      expect(() =>
        extractInterceptionRouteInformation('/(..)(..)bar')
      ).toThrowErrorMatchingInlineSnapshot(
        `"Invalid interception route: /(..)(..)bar. Cannot use (..)(..) marker at the root level or one level up."`
      )
    })
  })
})