╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const ui = @import("../ui.zig"); 3 const Commits = @import("../ui/Repo/Commits.zig"); 4 5 // the "next" row at the bottom of the commits list must be recognized as a 6 // cross-page link (so a click navigates), exactly like the diff pane's "next". 7 test "commits list next row is a cross-page link" { 8 const allocator = std.testing.allocator; 9 10 var arena = std.heap.ArenaAllocator.init(allocator); 11 defer arena.deinit(); 12 const identity = "alice/ziglings"; 13 const oid0 = "1111111111111111111111111111111111111111"; 14 const next_oid = "2222222222222222222222222222222222222222"; 15 16 const data = Commits{ 17 .identity = identity, 18 .ref_or_oid = .object, 19 .ref_or_oid_value = oid0, 20 .commits = &.{ 21 .{ .oid = oid0, .date = "2024-01-01", .message = "first", .hunks = &.{}, .window_start = 0, .has_prev = false, .has_more = false }, 22 }, 23 .next_start = next_oid, 24 .header = try Commits.Header.init(arena.allocator(), .object, oid0), 25 }; 26 27 var session = ui.Session{ .arena = &arena, .page_arena = &arena, .is_terminal = true }; 28 session.data.current_page = ui.RoutablePage.repoCommitsRoute(identity, .object, oid0, 0, "").?; 29 30 var view = try Commits.View.init(allocator, &data, &session); 31 defer view.deinit(allocator); 32 33 const root_focus = view.getFocus(); 34 try view.build(allocator, .{ 35 .min_size = .{ .width = null, .height = null }, 36 .max_size = .{ .width = 120, .height = 60 }, 37 }, root_focus); 38 39 // the "next" row is the last child of the list box: the view's outer box 40 // holds the sub-header then the list/diff split, whose first child is the 41 // list scroll. 42 const content = &view.box.children.values()[1].widget.box; 43 const lb = &content.children.values()[0].widget.scroll.child.box; 44 const next_id = lb.children.keys()[lb.children.count() - 1]; 45 46 const route = ui.crossPageLink(root_focus, next_id, session.data); 47 try std.testing.expect(route != null); 48 } 49 50 // a ref name with a '/' is url-encoded in the route, so it survives the 51 // '/'-delimited url round-trip as a single segment (kind + value) rather than 52 // being mis-parsed as extra path. 53 test "encoded ref name survives the commits url round-trip" { 54 var arena = std.heap.ArenaAllocator.init(std.testing.allocator); 55 defer arena.deinit(); 56 const RP = ui.RoutablePage; 57 58 // the route layer holds the value already url-encoded ("feature%2Ffoo"). 59 const route = RP.repoCommitsRoute("alice/ziglings", .branch, "feature%2Ffoo", 0, "").?; 60 const url = try route.toUrl(&arena); 61 try std.testing.expectEqualStrings("/repo/alice/ziglings/commits/branch:feature%2Ffoo", url); 62 63 // parsing it back yields the same route, and the ref splits out intact. 64 const parsed = RP.fromUrl(url); 65 try std.testing.expect(parsed != null); 66 const parsed_route = parsed.?.repo_commits; 67 try std.testing.expectEqual(RP.RefOrOid.branch, parsed_route.ref_or_oid.?); 68 try std.testing.expectEqualStrings("feature%2Ffoo", parsed_route.value.slice()); 69 } 70 71