|
1 | 1 | import { beforeEach, describe, expect, it } from "./suite.ts"; |
2 | 2 | import { createTerm, type Term } from "../term.ts"; |
3 | | -import { close, grow, open, rgba, text } from "../ops.ts"; |
| 3 | +import { close, fixed, grow, open, rgba, text } from "../ops.ts"; |
4 | 4 | import { print } from "./print.ts"; |
5 | 5 |
|
6 | 6 | const decode = (bytes: Uint8Array) => new TextDecoder().decode(bytes); |
@@ -151,6 +151,46 @@ describe("term", () => { |
151 | 151 | }); |
152 | 152 | }); |
153 | 153 |
|
| 154 | + describe("info", () => { |
| 155 | + it("returns bounds for named elements", async () => { |
| 156 | + let term = await createTerm({ width: 40, height: 10 }); |
| 157 | + let result = term.render([ |
| 158 | + open("root", { |
| 159 | + layout: { width: grow(), height: grow(), direction: "ttb" }, |
| 160 | + }), |
| 161 | + open("child", { |
| 162 | + layout: { width: fixed(20), height: fixed(5) }, |
| 163 | + }), |
| 164 | + close(), |
| 165 | + close(), |
| 166 | + ]); |
| 167 | + |
| 168 | + let root = result.info.get("root"); |
| 169 | + expect(root).toBeDefined(); |
| 170 | + expect(root!.bounds).toEqual({ x: 0, y: 0, width: 40, height: 10 }); |
| 171 | + |
| 172 | + let child = result.info.get("child"); |
| 173 | + expect(child).toBeDefined(); |
| 174 | + expect(child!.bounds).toEqual({ x: 0, y: 0, width: 20, height: 5 }); |
| 175 | + }); |
| 176 | + |
| 177 | + it("returns undefined for unknown ids", async () => { |
| 178 | + let term = await createTerm({ width: 20, height: 5 }); |
| 179 | + term.render([ |
| 180 | + open("root", { layout: { width: grow(), height: grow() } }), |
| 181 | + close(), |
| 182 | + ]); |
| 183 | + |
| 184 | + let result = term.render([ |
| 185 | + open("root", { layout: { width: grow(), height: grow() } }), |
| 186 | + close(), |
| 187 | + ]); |
| 188 | + |
| 189 | + expect(result.info.get("nonexistent")).toBeUndefined(); |
| 190 | + expect(result.info.get("")).toBeUndefined(); |
| 191 | + }); |
| 192 | + }); |
| 193 | + |
154 | 194 | describe("row offset", () => { |
155 | 195 | it("renders two frames at the offset position", async () => { |
156 | 196 | let term = await createTerm({ width: 20, height: 5 }); |
|
0 commit comments