╭ changed ──────╮ │src/test/ui.zig│ ╰───────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 4 const Commits = @import("../ui/Repo/Commits.zig"); │ │ 5 const Events = @import("../ui/Repo/Events.zig"); │ │ 6 const xit = @import("xit"); │ │ 7 + │ │ 8 +test "web controls omit hidden inputs but retain off-screen inputs" { │ │ 9 + const wgt = xit.xitui.widget; │ │10 + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); │ │11 + defer arena.deinit(); │ │12 + const allocator = arena.allocator(); │ │13 + var session = ui.Session{ .arena = &arena, .page_arena = &arena, .is_terminal = false }; │ │14 + var root = ui.Widget{ .box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }) }; │ │15 + defer root.deinit(allocator); │ │16 + var scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }) }, .{ .web_native = true });│ │17 + for ([_][]const u8{ "visible", "hidden", "offscreen" }, 0..) |name, i| { │ │18 + var input = try wgt.TextInput.init(allocator, .{ .name = name, .render_content = false }); │ │19 + input.getFocus().mode = .all; │ │20 + try scroll.child.box.children.put(allocator, input.getFocus().id, .{ │ │21 + .widget = .{ .text_input = input }, │ │22 + .rect = null, │ │23 + .min_size = .{ .width = 20, .height = 3 }, │ │24 + .hidden = i == 1, │ │25 + }); │ │26 + } │ │27 + for (scroll.child.box.children.values()) |*child| { │ │28 + const input = &child.widget.text_input; │ │29 + try session.text_inputs.put(allocator, input.getFocus().id, input); │ │30 + } │ │31 + try root.box.children.put(allocator, scroll.getFocus().id, .{ .widget = .{ .scroll = scroll }, .rect = null, .min_size = null }); │ │32 + const focus = root.getFocus(); │ │33 + try root.build(allocator, .{ .min_size = .{ .width = null, .height = null }, .max_size = .{ .width = 30, .height = 3 } }, focus); │ │34 │ │35 + const children = &root.box.children.values()[0].widget.scroll.child.box.children; │ │36 + const offscreen = children.values()[2].rect orelse return error.MissingRect; │ │37 + try std.testing.expect(offscreen.y >= 3); │ │38 + const html = try @import("../web.zig").generateHtml(allocator, &root, &session); │ │39 + try std.testing.expect(std.mem.indexOf(u8, html, "name=\"visible\"") != null); │ │40 + try std.testing.expect(std.mem.indexOf(u8, html, "name=\"hidden\"") == null); │ │41 + try std.testing.expect(std.mem.indexOf(u8, html, "name=\"offscreen\"") != null); │ │42 +} │ │43 + │ │44 test "diff windows span the net changes across commits" { │ │45 const io = std.testing.io; │ │46 const allocator = std.testing.allocator; │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯