|
| 1 | +/** |
| 2 | + * Copyright 2026 Redpanda Data, Inc. |
| 3 | + * |
| 4 | + * Use of this software is governed by the Business Source License |
| 5 | + * included in the file https://github.com/redpanda-data/redpanda/blob/dev/licenses/bsl.md |
| 6 | + * |
| 7 | + * As of the Change Date specified in that file, in accordance with |
| 8 | + * the Business Source License, use of this software will be governed |
| 9 | + * by the Apache License, Version 2.0 |
| 10 | + */ |
| 11 | + |
| 12 | +import { describe, expect, test } from 'vitest'; |
| 13 | + |
| 14 | +import { collectFullscreenPaths, isFullscreenPath, matchesFullscreenPath } from './fullscreen-routes'; |
| 15 | +import { routeTree } from '../routeTree.gen'; |
| 16 | + |
| 17 | +describe('collectFullscreenPaths', () => { |
| 18 | + test('collects paths from built route nodes (path/staticData under options)', () => { |
| 19 | + const tree = { |
| 20 | + children: { |
| 21 | + SqlRoute: { options: { path: '/sql', staticData: { fullscreen: true } } }, |
| 22 | + TopicsRoute: { options: { path: '/topics', staticData: { fullscreen: false } } }, |
| 23 | + QuotasRoute: { options: { path: '/quotas' } }, |
| 24 | + }, |
| 25 | + }; |
| 26 | + expect(collectFullscreenPaths(tree)).toEqual(['/sql']); |
| 27 | + }); |
| 28 | + |
| 29 | + test('collects paths from raw route nodes (path/staticData at top level)', () => { |
| 30 | + const tree = { |
| 31 | + children: { |
| 32 | + SqlRoute: { path: '/sql', staticData: { fullscreen: true } }, |
| 33 | + }, |
| 34 | + }; |
| 35 | + expect(collectFullscreenPaths(tree)).toEqual(['/sql']); |
| 36 | + }); |
| 37 | + |
| 38 | + test('recurses into nested children', () => { |
| 39 | + const tree = { |
| 40 | + children: { |
| 41 | + Parent: { |
| 42 | + options: { path: '/parent' }, |
| 43 | + children: { |
| 44 | + Child: { options: { path: '/parent/studio', staticData: { fullscreen: true } } }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }; |
| 49 | + expect(collectFullscreenPaths(tree)).toEqual(['/parent/studio']); |
| 50 | + }); |
| 51 | + |
| 52 | + test('ignores a fullscreen route with no path', () => { |
| 53 | + const tree = { children: { Bad: { options: { staticData: { fullscreen: true } } } } }; |
| 54 | + expect(collectFullscreenPaths(tree)).toEqual([]); |
| 55 | + }); |
| 56 | + |
| 57 | + test('tolerates non-object input', () => { |
| 58 | + expect(collectFullscreenPaths(null)).toEqual([]); |
| 59 | + expect(collectFullscreenPaths(undefined)).toEqual([]); |
| 60 | + }); |
| 61 | + |
| 62 | + test('derives /sql from the real route tree', () => { |
| 63 | + // Guards against route-tree shape changes and against the SQL route losing |
| 64 | + // its staticData.fullscreen flag. |
| 65 | + expect(collectFullscreenPaths(routeTree)).toContain('/sql'); |
| 66 | + }); |
| 67 | +}); |
| 68 | + |
| 69 | +describe('matchesFullscreenPath', () => { |
| 70 | + const paths = ['/sql']; |
| 71 | + |
| 72 | + test('matches the exact path', () => { |
| 73 | + expect(matchesFullscreenPath('/sql', paths)).toBe(true); |
| 74 | + }); |
| 75 | + |
| 76 | + test('matches a nested path', () => { |
| 77 | + expect(matchesFullscreenPath('/sql/query/123', paths)).toBe(true); |
| 78 | + }); |
| 79 | + |
| 80 | + test('matches an embedded path with a host cluster prefix', () => { |
| 81 | + expect(matchesFullscreenPath('/clusters/abc123/sql', paths)).toBe(true); |
| 82 | + }); |
| 83 | + |
| 84 | + test('does not match a path that merely starts with the segment text', () => { |
| 85 | + expect(matchesFullscreenPath('/sqlx', paths)).toBe(false); |
| 86 | + expect(matchesFullscreenPath('/mysql', paths)).toBe(false); |
| 87 | + }); |
| 88 | + |
| 89 | + test('does not match unrelated paths', () => { |
| 90 | + expect(matchesFullscreenPath('/topics', paths)).toBe(false); |
| 91 | + }); |
| 92 | + |
| 93 | + test('returns false when there are no fullscreen paths', () => { |
| 94 | + expect(matchesFullscreenPath('/sql', [])).toBe(false); |
| 95 | + }); |
| 96 | +}); |
| 97 | + |
| 98 | +describe('isFullscreenPath (wired to the real route tree)', () => { |
| 99 | + test('recognizes the SQL studio, standalone and embedded', () => { |
| 100 | + expect(isFullscreenPath('/sql')).toBe(true); |
| 101 | + expect(isFullscreenPath('/clusters/abc123/sql')).toBe(true); |
| 102 | + }); |
| 103 | + |
| 104 | + test('rejects non-fullscreen routes', () => { |
| 105 | + expect(isFullscreenPath('/topics')).toBe(false); |
| 106 | + expect(isFullscreenPath('/overview')).toBe(false); |
| 107 | + }); |
| 108 | +}); |
0 commit comments