|  | 
|  | 1 | +import {getUrlData} from '../getUrlData'; | 
|  | 2 | + | 
|  | 3 | +describe('getUrlData', () => { | 
|  | 4 | +    const windowSpy = jest.spyOn(window, 'window', 'get'); | 
|  | 5 | + | 
|  | 6 | +    afterEach(() => { | 
|  | 7 | +        windowSpy.mockClear(); | 
|  | 8 | +    }); | 
|  | 9 | +    afterAll(() => { | 
|  | 10 | +        windowSpy.mockRestore(); | 
|  | 11 | +    }); | 
|  | 12 | + | 
|  | 13 | +    describe('multi-cluster version', () => { | 
|  | 14 | +        test('should parse pathname with folder', () => { | 
|  | 15 | +            windowSpy.mockImplementation(() => { | 
|  | 16 | +                return { | 
|  | 17 | +                    location: { | 
|  | 18 | +                        href: 'http://ydb-ui/ui/cluster?clusterName=my_cluster&backend=http://my-node:8765', | 
|  | 19 | +                        pathname: '/ui/cluster?clusterName=my_cluster&backend=http://my-node:8765', | 
|  | 20 | +                    }, | 
|  | 21 | +                } as Window & typeof globalThis; | 
|  | 22 | +            }); | 
|  | 23 | +            const result = getUrlData({singleClusterMode: false, customBackend: undefined}); | 
|  | 24 | +            expect(result).toEqual({ | 
|  | 25 | +                basename: '/ui', | 
|  | 26 | +                backend: 'http://my-node:8765', | 
|  | 27 | +                clusterName: 'my_cluster', | 
|  | 28 | +            }); | 
|  | 29 | +        }); | 
|  | 30 | +        test('should parse pathname with folder and some prefix', () => { | 
|  | 31 | +            windowSpy.mockImplementation(() => { | 
|  | 32 | +                return { | 
|  | 33 | +                    location: { | 
|  | 34 | +                        href: 'http://ydb-ui/monitoring/ui/cluster?clusterName=my_cluster&backend=http://my-node:8765', | 
|  | 35 | +                        pathname: | 
|  | 36 | +                            '/monitoring/ui/cluster?clusterName=my_cluster&backend=http://my-node:8765', | 
|  | 37 | +                    }, | 
|  | 38 | +                } as Window & typeof globalThis; | 
|  | 39 | +            }); | 
|  | 40 | +            const result = getUrlData({singleClusterMode: false, customBackend: undefined}); | 
|  | 41 | +            expect(result).toEqual({ | 
|  | 42 | +                basename: '/monitoring/ui', | 
|  | 43 | +                backend: 'http://my-node:8765', | 
|  | 44 | +                clusterName: 'my_cluster', | 
|  | 45 | +            }); | 
|  | 46 | +        }); | 
|  | 47 | +        test('should parse pathname with folder and some prefix', () => { | 
|  | 48 | +            windowSpy.mockImplementation(() => { | 
|  | 49 | +                return { | 
|  | 50 | +                    location: { | 
|  | 51 | +                        href: 'http://ydb-ui/cluster?clusterName=my_cluster&backend=http://my-node:8765', | 
|  | 52 | +                        pathname: '/cluster?clusterName=my_cluster&backend=http://my-node:8765', | 
|  | 53 | +                    }, | 
|  | 54 | +                } as Window & typeof globalThis; | 
|  | 55 | +            }); | 
|  | 56 | +            const result = getUrlData({singleClusterMode: false, customBackend: undefined}); | 
|  | 57 | +            expect(result).toEqual({ | 
|  | 58 | +                basename: '', | 
|  | 59 | +                backend: 'http://my-node:8765', | 
|  | 60 | +                clusterName: 'my_cluster', | 
|  | 61 | +            }); | 
|  | 62 | +        }); | 
|  | 63 | +    }); | 
|  | 64 | +    describe('single-cluster version with custom backend', () => { | 
|  | 65 | +        test('should parse correclty parse pathname', () => { | 
|  | 66 | +            windowSpy.mockImplementation(() => { | 
|  | 67 | +                return { | 
|  | 68 | +                    location: { | 
|  | 69 | +                        href: 'http://localhost:3000/cluster', | 
|  | 70 | +                        pathname: '/cluster', | 
|  | 71 | +                    }, | 
|  | 72 | +                } as Window & typeof globalThis; | 
|  | 73 | +            }); | 
|  | 74 | +            const result = getUrlData({ | 
|  | 75 | +                singleClusterMode: true, | 
|  | 76 | +                customBackend: 'http://my-node:8765', | 
|  | 77 | +            }); | 
|  | 78 | +            expect(result).toEqual({ | 
|  | 79 | +                basename: '', | 
|  | 80 | +                backend: 'http://my-node:8765', | 
|  | 81 | +            }); | 
|  | 82 | +        }); | 
|  | 83 | +    }); | 
|  | 84 | +    describe('single-cluster embedded version', () => { | 
|  | 85 | +        test('should parse pathname with folder', () => { | 
|  | 86 | +            windowSpy.mockImplementation(() => { | 
|  | 87 | +                return { | 
|  | 88 | +                    location: { | 
|  | 89 | +                        href: 'http://my-node:8765/monitoring/cluster', | 
|  | 90 | +                        pathname: '/monitoring/cluster', | 
|  | 91 | +                    }, | 
|  | 92 | +                } as Window & typeof globalThis; | 
|  | 93 | +            }); | 
|  | 94 | +            const result = getUrlData({singleClusterMode: true, customBackend: undefined}); | 
|  | 95 | +            expect(result).toEqual({ | 
|  | 96 | +                basename: '/monitoring', | 
|  | 97 | +                backend: '', | 
|  | 98 | +            }); | 
|  | 99 | +        }); | 
|  | 100 | +        test('should parse pathname with folder and some prefix', () => { | 
|  | 101 | +            windowSpy.mockImplementation(() => { | 
|  | 102 | +                return { | 
|  | 103 | +                    location: { | 
|  | 104 | +                        href: 'http://my-node:8765/node/12/monitoring/cluster', | 
|  | 105 | +                        pathname: '/node/12/monitoring/cluster', | 
|  | 106 | +                    }, | 
|  | 107 | +                } as Window & typeof globalThis; | 
|  | 108 | +            }); | 
|  | 109 | +            const result = getUrlData({singleClusterMode: true, customBackend: undefined}); | 
|  | 110 | +            expect(result).toEqual({ | 
|  | 111 | +                basename: '/node/12/monitoring', | 
|  | 112 | +                backend: '/node/12', | 
|  | 113 | +            }); | 
|  | 114 | +        }); | 
|  | 115 | +    }); | 
|  | 116 | +}); | 
0 commit comments