Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-coderoom-view/tests/graph_split.rs

//! **The connections graph gets the bulk of the tab, under a drag bar** — rendered at
//! a typical window (1 400 × 900) with the header a real room carries (identity lines,
//! four layers with their evidence): the graph canvas covers ≥ 60 % of the pane, and
//! dragging the bar between the header and the graph changes it.
//!
//! The owner (loki): "Coderoom connections: the graph works but is only visible in the
//! lower part of the window, and no drag bar exists". RED before: the header took what
//! it needed and the graph got the rest, with nothing to drag.

use std::cell::RefCell;
use std::rc::Rc;

use egui_kittest::Harness;
use facett_coderoom_view::*;

/// The stub room, with the header a real host feeds.
struct RoomWithHeader(StubCoderoomData);

impl CoderoomDataSeam for RoomWithHeader {
    fn source(&self) -> &str {
        "the room (test)"
    }
    fn crates(&self) -> Vec<CrateNode> {
        self.0.crates()
    }
    fn compat_edges(&self) -> Vec<CompatEdge> {
        self.0.compat_edges()
    }
    fn what_breaks(&self, target: &str) -> Option<WhatBreaks> {
        self.0.what_breaks(target)
    }
    fn links(&self) -> Vec<CrateLink> {
        self.0.links()
    }
    fn layers(&self) -> Vec<LayerState> {
        let ev = "the room answered from the log of 21 repos read at their consumed commits; calls through closures are not recorded, so this is a lower bound; a crate the reader never planned has no node and is named as missing rather than drawn as empty";
        ["graph", "verdicts", "what-breaks", "diff"].iter().map(|l| LayerState::new(*l, "complete", true, ev)).collect()
    }
    fn identity(&self) -> Vec<String> {
        (0..6).map(|i| format!("workspace nordisk · repo {i} at its consumed commit · 4210 nodes · 9877 edges")).collect()
    }
}

#[test]
fn the_connections_graph_gets_most_of_the_tab_and_the_bar_drags() {
    let pane = Rc::new(RefCell::new(CoderoomPane::new(Box::new(RoomWithHeader(StubCoderoomData)))));
    let p2 = pane.clone();
    let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui(move |ui| {
        egui::CentralPanel::default().show_inside(ui, |ui| p2.borrow_mut().ui(ui));
    });
    for _ in 0..3 {
        h.step();
    }
    let g = pane.borrow().graph_rect().expect("the graph painted");
    let share = g.height() / 900.0;
    assert!(share >= 0.6, "the graph covers {:.0} % of the tab's height: {g:?}", share * 100.0);

    // find the bar between the header and the graph: where the pointer turns into the
    // vertical-resize cursor, just above the graph pane
    let bar = (0..120)
        .map(|d| egui::pos2(700.0, g.min.y - d as f32))
        .find(|p| {
            h.hover_at(*p);
            h.step();
            h.output().platform_output.cursor_icon == egui::CursorIcon::ResizeVertical
        })
        .expect("a drag bar above the graph");
    h.hover_at(bar);
    h.step();
    h.drag_at(bar);
    h.step();
    h.hover_at(bar + egui::vec2(0.0, 150.0));
    h.step();
    h.drop_at(bar + egui::vec2(0.0, 150.0));
    for _ in 0..3 {
        h.step();
    }
    let g2 = pane.borrow().graph_rect().unwrap();
    assert!(g2.min.y > g.min.y + 100.0, "dragging the bar moved the graph's top: {g:?} → {g2:?}");
}