|
| 1 | +// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| 2 | +// ░░░░░░░░▄▀░█▀▄░█▀▀░█▀▀░█░█░█░░░█▀█░█▀▄░░░░░█░░░█▀█░█░█░█▀█░█░█░▀█▀░▀▄░░░░░░░░ |
| 3 | +// ░░░░░░░▀▄░░█▀▄░█▀▀░█░█░█░█░█░░░█▀█░█▀▄░▀▀▀░█░░░█▀█░░█░░█░█░█░█░░█░░░▄▀░░░░░░░ |
| 4 | +// ░░░░░░░░░▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀░▀░▀░▀░░░░░▀▀▀░▀░▀░░▀░░▀▀▀░▀▀▀░░▀░░▀░░░░░░░░░ |
| 5 | +// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| 6 | +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 7 | +// ┃ * Copyright (c) 2026, the Regular Layout Authors. This file is part * ┃ |
| 8 | +// ┃ * of the Regular Layout library, distributed under the terms of the * ┃ |
| 9 | +// ┃ * [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). * ┃ |
| 10 | +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 11 | + |
| 12 | +import { expect, test } from "@playwright/test"; |
| 13 | +import { calculate_path } from "../../src/layout/calculate_path.ts"; |
| 14 | +import { LAYOUTS } from "../helpers/fixtures.ts"; |
| 15 | + |
| 16 | +test("returns null for a name not in the layout", () => { |
| 17 | + const result = calculate_path("ZZZ", LAYOUTS.SINGLE_AAA); |
| 18 | + expect(result).toBeNull(); |
| 19 | +}); |
| 20 | + |
| 21 | +test("returns null for an empty layout", () => { |
| 22 | + const result = calculate_path("AAA", { |
| 23 | + type: "split-panel", |
| 24 | + orientation: "horizontal", |
| 25 | + sizes: [], |
| 26 | + children: [], |
| 27 | + }); |
| 28 | + expect(result).toBeNull(); |
| 29 | +}); |
| 30 | + |
| 31 | +test("finds a single panel", () => { |
| 32 | + const result = calculate_path("AAA", LAYOUTS.SINGLE_AAA); |
| 33 | + expect(result).toStrictEqual([]); |
| 34 | +}); |
| 35 | + |
| 36 | +test("finds left panel in horizontal split", () => { |
| 37 | + const result = calculate_path("AAA", LAYOUTS.TWO_HORIZONTAL); |
| 38 | + expect(result).toStrictEqual([0]); |
| 39 | +}); |
| 40 | + |
| 41 | +test("finds right panel in horizontal split", () => { |
| 42 | + const result = calculate_path("BBB", LAYOUTS.TWO_HORIZONTAL); |
| 43 | + expect(result).toStrictEqual([1]); |
| 44 | +}); |
| 45 | + |
| 46 | +test("finds top panel in vertical split", () => { |
| 47 | + const result = calculate_path("AAA", LAYOUTS.TWO_VERTICAL); |
| 48 | + expect(result).toStrictEqual([0]); |
| 49 | +}); |
| 50 | + |
| 51 | +test("finds panel in nested layout", () => { |
| 52 | + const result = calculate_path("AAA", LAYOUTS.NESTED_BASIC); |
| 53 | + expect(result).toStrictEqual([0, 0]); |
| 54 | +}); |
| 55 | + |
| 56 | +test("finds deeply nested panel", () => { |
| 57 | + const result = calculate_path("BBB", LAYOUTS.DEEPLY_NESTED); |
| 58 | + expect(result).toStrictEqual([0, 1]); |
| 59 | +}); |
| 60 | + |
| 61 | +test("finds non-selected tab by name", () => { |
| 62 | + const result = calculate_path("BBB", LAYOUTS.SINGLE_TABS); |
| 63 | + expect(result).toStrictEqual([]); |
| 64 | +}); |
| 65 | + |
| 66 | +test("finds leaf panel in deeply nested alt layout", () => { |
| 67 | + const result = calculate_path("DDD", LAYOUTS.DEEPLY_NESTED_ALT); |
| 68 | + expect(result).toStrictEqual([1]); |
| 69 | +}); |
0 commit comments