Lines
100 %
Functions
Branches
//! A press on the `─┘` corner of the front window and the motion after it size it; a lost
//! release ends the drag on Esc or the next press, and a closed window ends it.
use super::overlap::{FRONT_AT, REAR_AT, left_click, left_drag, left_release, overlapped};
use super::report_chart::{call_for, chart_requests, echoed, show, with_table};
use super::title_drag::{front_id, mouse_at, place_of};
use crate::app::App;
use crate::hits::Target;
use crate::test_support::{area_of, draw_into, key, press};
use crate::window::WindowId;
use ratatui::crossterm::event::{KeyCode, MouseButton, MouseEventKind};
use rpc::chart::ChartBackend;
use std::time::{Duration, Instant};
use tvui::{FrameMode, Place};
fn corner_of(place: Place) -> (u16, u16) {
let x = u16::try_from(place.x + i32::from(place.width) - 1).unwrap_or_default();
let y = u16::try_from(place.y + i32::from(place.height) - 1).unwrap_or_default();
(x, y)
}
fn size_of(app: &App, id: WindowId) -> (u16, u16) {
let place = place_of(app, id);
(place.width, place.height)
#[test]
fn the_front_window_has_a_grow_target_on_its_corner_and_a_rear_one_has_none() {
let (app, ..) = overlapped();
let grow = area_of(&app, Target::Grow);
let corner = corner_of(FRONT_AT);
assert!(grow.contains(ratatui::layout::Position::new(corner.0, corner.1)));
assert_eq!((grow.width, grow.height), (2, 1));
let grows = app
.hits
.entries()
.iter()
.filter(|(_, target)| *target == Target::Grow)
.count();
assert_eq!(grows, 1);
fn a_corner_drag_sizes_the_window_to_the_pointer() {
let (mut app, _, front) = overlapped();
let (corner, now) = (corner_of(FRONT_AT), Instant::now());
left_click(&mut app, corner, now);
assert_eq!(app.frame_state(front).mode, FrameMode::Dragging);
left_drag(&mut app, (corner.0 + 5, corner.1 + 2), now);
assert_eq!(size_of(&app, front), (45, 14));
left_drag(&mut app, (40, 12), now);
left_release(&mut app, (40, 12), now);
assert_eq!(size_of(&app, front), (21, 8));
let place = place_of(&app, front);
assert_eq!((place.x, place.y), (FRONT_AT.x, FRONT_AT.y));
assert!(!app.dragging());
fn a_corner_drag_stops_at_the_minimum_size() {
left_click(&mut app, corner_of(FRONT_AT), Instant::now());
left_drag(&mut app, (21, 6), Instant::now());
assert_eq!(size_of(&app, front), (16, 6));
fn a_corner_drag_stops_at_the_desktop_size() {
let hung = Place {
x: -10,
y: 2,
..FRONT_AT
};
super::overlap::place_window(&mut app, front, hung);
draw_into(&mut app, 80, 24);
left_click(&mut app, corner_of(hung), Instant::now());
left_drag(&mut app, (79, 23), Instant::now());
let area = app.desktop_rect();
assert_eq!(size_of(&app, front), (area.width, area.height));
fn a_press_on_the_corner_of_a_rear_window_raises_it_and_does_not_size_it() {
let (mut app, rear, _) = overlapped();
let clear = Place {
width: 16,
height: 6,
..REAR_AT
super::overlap::place_window(&mut app, rear, clear);
left_click(&mut app, corner_of(clear), Instant::now());
assert_eq!(app.front_window(), Some(rear));
#[tokio::test]
async fn the_release_of_a_corner_drag_fetches_the_chart_at_the_new_size() {
let (mut app, sent) = with_table(60, 24, ChartBackend::Halfblocks);
show(&mut app);
let id = front_id(&app);
let start = Place {
x: 10,
y: 5,
width: 30,
height: 10,
super::overlap::place_window(&mut app, id, start);
draw_into(&mut app, 60, 24);
let before = chart_requests(&app).len();
let (left, now) = (MouseButton::Left, Instant::now());
let at = corner_of(start);
mouse_at(&mut app, MouseEventKind::Down(left), at, ((60, 24), now));
mouse_at(
&mut app,
MouseEventKind::Drag(left),
(41, 15),
((60, 24), now),
);
assert_eq!(chart_requests(&app).len(), before);
MouseEventKind::Up(left),
assert_eq!(chart_requests(&app).len(), before + 1);
assert!(echoed(&mut app, &sent).await.contains(&call_for(300, 180)));
fn a_lost_release_ends_on_esc_with_the_window_put_back() {
left_drag(&mut app, (50, 14), Instant::now());
assert_ne!(place_of(&app, front), FRONT_AT);
press(&mut app, key(KeyCode::Esc));
assert_eq!(place_of(&app, front), FRONT_AT);
left_drag(&mut app, (60, 20), Instant::now());
fn a_lost_release_ends_on_the_next_press_which_keeps_the_window_and_acts() {
let now = Instant::now();
left_click(&mut app, corner_of(FRONT_AT), now);
left_drag(&mut app, (50, 14), now);
let sized = place_of(&app, front);
assert_ne!(sized, FRONT_AT);
let title = (u16::try_from(sized.x).unwrap_or_default() + 10, 5);
left_click(&mut app, title, now + Duration::from_secs(2));
assert_eq!(place_of(&app, front), sized);
assert!(app.pointer_dragging());
left_drag(&mut app, (title.0 + 1, 7), now);
assert_eq!(place_of(&app, front).x, sized.x + 1);
fn closing_the_window_mid_drag_ends_the_drag() {
let (mut app, rear, front) = overlapped();
app.close_window(front);
let before = place_of(&app, rear);
left_drag(&mut app, (70, 20), Instant::now());
left_release(&mut app, (70, 20), Instant::now());
assert_eq!(place_of(&app, rear), before);
fn a_press_on_the_dash_of_the_corner_keeps_the_width_on_a_vertical_drag() {
let (x, y) = corner_of(FRONT_AT);
left_click(&mut app, (x - 1, y), Instant::now());
left_drag(&mut app, (x - 1, y + 2), Instant::now());
assert_eq!(size_of(&app, front), (FRONT_AT.width, FRONT_AT.height + 2));
fn the_one_visible_corner_cell_of_a_window_hung_off_the_left_sizes_it() {
x: 1 - i32::from(FRONT_AT.width),
let y = corner_of(hung).1;
left_click(&mut app, (0, y), Instant::now());
left_drag(&mut app, (0, y + 2), Instant::now());
assert_eq!(size_of(&app, front), (hung.width, hung.height + 2));
left_drag(&mut app, (9, y + 2), Instant::now());
assert_eq!(size_of(&app, front), (hung.width + 9, hung.height + 2));