gpui-box-kit 0.1.0

GPUI Box Kit design-system components and interaction primitives
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
//! `DataGrid` holds a viewport, not a data set, and applies nothing. It
//! reports what was operated and renders exactly what the caller says is true.

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

use gpui::{IntoElement, Modifiers, ParentElement, SharedString, TestAppContext, px};
use gpui_kit::prelude::*;
use gpui_kit_semantics::{Node, Role};
use gpui_kit_testkit::harness::Harness;

type Calls<T> = Rc<RefCell<Vec<T>>>;

/// One synthetic job. The identity is a fixture key, never a position.
fn job(index: usize) -> (SharedString, SharedString, SharedString) {
    (
        SharedString::from(format!("job-{index:04}")),
        SharedString::from(format!("Fixture job {index:04}")),
        SharedString::from(format!("owner-{}", index % 3)),
    )
}

fn columns() -> Vec<GridColumn> {
    vec![
        GridColumn::new("name", "Job")
            .flex(2.0)
            .min_width(120.0)
            .pinned(true)
            .sortable(true),
        GridColumn::new("owner", "Owner")
            .fixed(140.0)
            .reorderable(true)
            .editable(true),
        GridColumn::new("duration", "Duration")
            .fixed(120.0)
            .min_width(60.0)
            .sortable(true)
            .resizable(true),
    ]
}

fn row(index: usize) -> GridRow {
    let (id, name, owner) = job(index);
    GridRow::new(id)
        .text(name.clone())
        .cell("name", Cell::new(name.clone()).text(name).published(true))
        .cell("owner", Cell::new(owner.clone()).text(owner))
        .cell("duration", format!("{}m", index % 9 + 1))
}

/// Everything a test hands the grid, so a single builder covers every case.
#[derive(Clone, Default)]
struct Given {
    count: usize,
    total: Option<usize>,
    sort: Option<(SharedString, SortDirection)>,
    selected: Vec<SharedString>,
    mode: SelectionMode,
    failure: Option<SharedString>,
    editing: Option<EditingCell>,
    expanded: Vec<Expanded>,
}

impl Given {
    fn rows(count: usize) -> Self {
        Self {
            count,
            mode: SelectionMode::Multiple,
            ..Self::default()
        }
    }
}

#[derive(Default)]
struct Reports {
    sorts: Calls<(String, String)>,
    selections: Calls<String>,
    widths: Calls<(String, f32)>,
    fits: Calls<String>,
    orders: Calls<String>,
    expansions: Calls<(String, bool)>,
    edit_requests: Calls<(String, String)>,
    edits: Calls<(String, String, String, String)>,
}

fn grid(cx: &mut TestAppContext, given: Given) -> (Harness, Rc<Reports>) {
    let reports = Rc::new(Reports::default());
    let sinks = Rc::clone(&reports);
    let harness = Harness::new(cx, gpui_kit::install, move |_, _| {
        let sinks = Rc::clone(&sinks);
        let given = given.clone();
        let mut element = DataGrid::new("data.grid", given.count, |index, _, _| row(index))
            .columns(columns())
            .sort(given.sort.clone())
            .selection_mode(given.mode)
            .selected(given.selected.clone())
            .expanded(given.expanded.clone())
            .detail_rows(2)
            .detail(|id, _, _| {
                gpui::div()
                    .child(SharedString::from(format!("Detail for {id}")))
                    .into_any_element()
            })
            .editing(given.editing.clone())
            .visible_rows(8)
            .on_sort({
                let sink = Rc::clone(&sinks);
                move |key, direction, _, _| {
                    sink.sorts
                        .borrow_mut()
                        .push((key.to_string(), direction.as_str().to_string()));
                }
            })
            .on_select({
                let sink = Rc::clone(&sinks);
                move |change, _, _| {
                    let described = match change {
                        SelectionChange::Replace(id) => format!("replace:{id}"),
                        SelectionChange::Toggle(id) => format!("toggle:{id}"),
                        SelectionChange::Range { anchor, to } => format!("range:{anchor}..{to}"),
                        SelectionChange::Loaded => "loaded".to_string(),
                        SelectionChange::Everything => "everything".to_string(),
                        SelectionChange::Clear => "clear".to_string(),
                    };
                    sink.selections.borrow_mut().push(described);
                }
            })
            .on_resize({
                let sink = Rc::clone(&sinks);
                move |key, width, _, _| sink.widths.borrow_mut().push((key.to_string(), width))
            })
            .on_fit({
                let sink = Rc::clone(&sinks);
                move |key, _, _| sink.fits.borrow_mut().push(key.to_string())
            })
            .on_reorder({
                let sink = Rc::clone(&sinks);
                move |intent, _, _| {
                    sink.orders
                        .borrow_mut()
                        .push(format!("{} {}", intent.item.id, intent.position));
                }
            })
            .on_expand({
                let sink = Rc::clone(&sinks);
                move |id, open, _, _| sink.expansions.borrow_mut().push((id.to_string(), open))
            })
            .on_edit_request({
                let sink = Rc::clone(&sinks);
                move |row, column, _, _| {
                    sink.edit_requests
                        .borrow_mut()
                        .push((row.to_string(), column.to_string()));
                }
            })
            .on_edit({
                let sink = Rc::clone(&sinks);
                move |intent, _, _| {
                    sink.edits.borrow_mut().push((
                        intent.row.to_string(),
                        intent.column.to_string(),
                        intent.value.to_string(),
                        intent.outcome.as_str().to_string(),
                    ));
                }
            });
        if let Some(total) = given.total {
            element = element.total(total);
        }
        if let Some(failure) = given.failure.clone() {
            element = element.failure(failure);
        }
        element.into_any_element()
    });
    (harness, reports)
}

/// A real double click, which `simulate_click` cannot produce: it always
/// reports a click count of one.
fn double_click(harness: &mut Harness, id: &str) {
    let position = harness.point_in(id);
    harness.context().simulate_event(gpui::MouseDownEvent {
        position,
        button: gpui::MouseButton::Left,
        modifiers: Modifiers::none(),
        click_count: 2,
        first_mouse: false,
    });
    harness.context().simulate_event(gpui::MouseUpEvent {
        position,
        button: gpui::MouseButton::Left,
        modifiers: Modifiers::none(),
        click_count: 2,
    });
    harness.context().run_until_parked();
}

fn rows_of(harness: &mut Harness) -> Vec<Node> {
    harness
        .snapshot()
        .children_of("data.grid")
        .into_iter()
        .filter(|node| node.role == Role::Row)
        .cloned()
        .collect()
}

#[gpui::test]
fn a_virtualized_grid_publishes_its_total_and_only_the_rows_it_drew(cx: &mut TestAppContext) {
    let (mut harness, _reports) = grid(cx, Given::rows(1000));

    let node = harness.node("data.grid").expect("published");
    assert_eq!(node.role, Role::Table);
    assert_eq!(
        node.value.as_deref(),
        Some("1000"),
        "the grid must report the size of the data set it was given"
    );

    let drawn = rows_of(&mut harness);
    assert!(
        (1..24).contains(&drawn.len()),
        "a viewport of eight rows must not publish a thousand nodes, drew {}",
        drawn.len()
    );
    assert!(harness.node("data.grid.job-0000").is_some());
    assert!(
        harness.node("data.grid.job-0900").is_none(),
        "a row outside the viewport must not be addressable"
    );
    assert!(
        harness.node("data.grid.job-0000.name").is_some(),
        "a published cell is an assertion target"
    );
    assert!(
        harness.node("data.grid.job-0000.duration").is_none(),
        "an unmarked cell must not add a node to the tree"
    );
}

#[gpui::test]
fn the_keyboard_reports_a_row_the_viewport_has_never_drawn(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(cx, Given::rows(1000));

    harness.click("data.grid.job-0000");
    reports.selections.borrow_mut().clear();
    harness.keystrokes("end");

    assert_eq!(*reports.selections.borrow(), vec!["replace:job-0999"]);
    // The grid scrolled to what it reported, so the row is now on screen.
    assert!(harness.node("data.grid.job-0999").is_some());
    assert!(harness.node("data.grid.job-0000").is_none());
}

#[gpui::test]
fn a_sortable_header_reports_the_next_direction_and_sorts_nothing(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(
        cx,
        Given {
            sort: Some((SharedString::from("duration"), SortDirection::Ascending)),
            ..Given::rows(40)
        },
    );

    let header = harness
        .node("data.grid.header.duration")
        .expect("published");
    assert_eq!(header.role, Role::Button);
    assert_eq!(header.value.as_deref(), Some("ascending"));
    assert_eq!(
        harness
            .node("data.grid.header.name")
            .expect("published")
            .value
            .as_deref(),
        Some("unsorted")
    );
    assert_eq!(
        harness
            .node("data.grid.header.owner")
            .expect("published")
            .role,
        Role::Cell,
        "a header that does not sort is not a button"
    );

    let before: Vec<String> = rows_of(&mut harness)
        .into_iter()
        .map(|row| row.id)
        .collect();
    harness.click("data.grid.header.duration");

    assert_eq!(
        *reports.sorts.borrow(),
        vec![("duration".to_string(), "descending".to_string())]
    );
    let after: Vec<String> = rows_of(&mut harness)
        .into_iter()
        .map(|row| row.id)
        .collect();
    assert_eq!(before, after, "the grid renders the order it was given");
}

#[gpui::test]
fn dragging_a_column_edge_reports_a_width_and_resizes_nothing(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(cx, Given::rows(40));

    let handle = harness
        .node("data.grid.header.duration.resize")
        .expect("a resizable column publishes its handle");
    assert_eq!(handle.role, Role::Separator);
    let before = harness
        .bounds("data.grid.header.duration")
        .expect("measured");

    harness.drag_start("data.grid.header.duration.resize");
    let anchor = harness.pointer();
    harness.drag_to(anchor - gpui::point(px(20.0), px(0.0)));
    let near = reports.widths.borrow().last().cloned();
    harness.drag_to(anchor - gpui::point(px(50.0), px(0.0)));
    let far = reports.widths.borrow().last().cloned();
    harness.drop_here();

    let (key, near_width) = near.expect("a drag reports a width");
    let (_, far_width) = far.expect("a drag reports a width");
    assert_eq!(key, "duration");
    assert!(
        far_width < near_width,
        "dragging further left must ask for a narrower column, {near_width} then {far_width}"
    );

    let after = harness
        .bounds("data.grid.header.duration")
        .expect("measured");
    assert!(
        (after.size.width - before.size.width).abs() < px(0.5),
        "the caller owns the width, so nothing moved"
    );
}

#[gpui::test]
fn a_column_edge_dragged_past_its_minimum_reports_the_minimum(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(cx, Given::rows(40));

    harness.drag_start("data.grid.header.duration.resize");
    let anchor = harness.pointer();
    harness.drag_to(anchor - gpui::point(px(400.0), px(0.0)));
    harness.drop_here();

    let (_, width) = reports
        .widths
        .borrow()
        .last()
        .cloned()
        .expect("a drag reports a width");
    assert_eq!(width, 60.0, "a column stops at the minimum it declared");
}

#[gpui::test]
fn dropping_a_column_reports_where_it_should_go(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(cx, Given::rows(40));

    let before: Vec<String> = harness
        .snapshot()
        .under("data.grid.header.")
        .into_iter()
        .map(|node| node.id.clone())
        .collect();

    harness.drag("data.grid.header.owner", "data.grid.header.duration");

    assert_eq!(*reports.orders.borrow(), vec!["owner after:duration"]);
    let after: Vec<String> = harness
        .snapshot()
        .under("data.grid.header.")
        .into_iter()
        .map(|node| node.id.clone())
        .collect();
    assert_eq!(before, after, "the grid renders the order it was given");
}

#[gpui::test]
fn a_pinned_column_cannot_be_carried_out_of_the_left_edge(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(cx, Given::rows(40));

    harness.drag("data.grid.header.owner", "data.grid.header.name");

    assert!(
        reports.orders.borrow().is_empty(),
        "nothing may be dropped across a pinned column"
    );
}

#[gpui::test]
fn shift_clicking_reports_the_span_from_the_row_last_operated(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(cx, Given::rows(40));

    harness.click("data.grid.job-0001");
    assert_eq!(*reports.selections.borrow(), vec!["replace:job-0001"]);
    reports.selections.borrow_mut().clear();

    let target = harness.point_in("data.grid.job-0004");
    harness.context().simulate_click(
        target,
        Modifiers {
            shift: true,
            ..Modifiers::none()
        },
    );
    harness.context().run_until_parked();

    assert_eq!(
        *reports.selections.borrow(),
        vec!["range:job-0001..job-0004"]
    );
    assert!(
        !harness
            .node("data.grid.job-0004")
            .expect("published")
            .selected,
        "the caller owns the selection, so nothing moved"
    );
}

#[gpui::test]
fn a_modified_click_reports_a_toggle_rather_than_a_replacement(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(cx, Given::rows(40));

    let target = harness.point_in("data.grid.job-0002");
    harness.context().simulate_click(
        target,
        Modifiers {
            control: true,
            ..Modifiers::none()
        },
    );
    harness.context().run_until_parked();

    assert_eq!(*reports.selections.borrow(), vec!["toggle:job-0002"]);
}

#[gpui::test]
fn the_header_box_says_what_it_can_speak_for(cx: &mut TestAppContext) {
    let loaded = 40;
    let (mut harness, reports) = grid(
        cx,
        Given {
            total: Some(12_000),
            ..Given::rows(loaded)
        },
    );

    let box_node = harness.node("data.grid.select-all").expect("published");
    assert_eq!(box_node.role, Role::Checkbox);
    assert_eq!(box_node.checked, Some(false));
    assert_eq!(
        box_node.value.as_deref(),
        Some("0 of 40 loaded, 12000 total"),
        "a box in a virtualized grid must not read as though it speaks for the whole data set"
    );

    harness.click("data.grid.select-all");
    assert_eq!(
        *reports.selections.borrow(),
        vec!["loaded"],
        "the box asks for the loaded rows and nothing wider"
    );

    // Two of the loaded rows selected is neither all nor none.
    let (mut harness, _reports) = grid(
        cx,
        Given {
            total: Some(12_000),
            selected: vec!["job-0000".into(), "job-0001".into()],
            ..Given::rows(loaded)
        },
    );
    let box_node = harness.node("data.grid.select-all").expect("published");
    assert_eq!(box_node.checked, None, "a partial selection is mixed");
    assert_eq!(
        box_node.value.as_deref(),
        Some("2 of 40 loaded, 12000 total")
    );

    let all: Vec<SharedString> = (0..loaded).map(|index| job(index).0).collect();
    let (mut harness, reports) = grid(
        cx,
        Given {
            total: Some(12_000),
            selected: all,
            ..Given::rows(loaded)
        },
    );
    let box_node = harness.node("data.grid.select-all").expect("published");
    assert_eq!(box_node.checked, Some(true));
    assert_eq!(
        box_node.value.as_deref(),
        Some("40 of 40 loaded, 12000 total"),
        "every loaded row is selected, and eleven thousand nine hundred and sixty are not"
    );
    harness.click("data.grid.select-all");
    assert_eq!(*reports.selections.borrow(), vec!["clear"]);
}

fn bulk_bar(cx: &mut TestAppContext, count: usize, total: usize) -> (Harness, Rc<Reports>) {
    let reports = Rc::new(Reports::default());
    let sinks = Rc::clone(&reports);
    let harness = Harness::new(cx, gpui_kit::install, move |_, _| {
        let widen = Rc::clone(&sinks);
        let clear = Rc::clone(&sinks);
        BulkBar::new("data.bulk", count)
            .total(total)
            .action(
                Button::new("data.bulk.archive")
                    .label("Archive")
                    .secondary()
                    .on_click(|_, _| {}),
            )
            .on_select_all(move |_, _| widen.selections.borrow_mut().push("everything".into()))
            .on_dismiss(move |_, _| clear.selections.borrow_mut().push("clear".into()))
            .into_any_element()
    });
    (harness, reports)
}

#[gpui::test]
fn the_bulk_bar_states_the_selection_it_actually_has(cx: &mut TestAppContext) {
    let (mut harness, reports) = bulk_bar(cx, 40, 12_000);

    let bar = harness.node("data.bulk").expect("published");
    assert_eq!(bar.role, Role::Toolbar);
    assert_eq!(bar.value.as_deref(), Some("40"));
    assert_eq!(bar.text.as_deref(), Some("40 selected"));

    let wider = harness
        .node("data.bulk.select-all")
        .expect("a selection narrower than the data set offers the wider intent");
    assert_eq!(wider.text.as_deref(), Some("Select all 12000"));

    harness.click("data.bulk.select-all");
    assert_eq!(*reports.selections.borrow(), vec!["everything"]);

    harness.click("data.bulk.dismiss");
    assert_eq!(*reports.selections.borrow(), vec!["everything", "clear"]);
}

#[gpui::test]
fn a_bulk_bar_over_the_whole_data_set_offers_nothing_wider(cx: &mut TestAppContext) {
    let (mut harness, _reports) = bulk_bar(cx, 12_000, 12_000);

    assert_eq!(
        harness
            .node("data.bulk")
            .expect("published")
            .text
            .as_deref(),
        Some("12000 selected")
    );
    assert!(
        harness.node("data.bulk.select-all").is_none(),
        "there is nothing left to widen to"
    );
}

#[gpui::test]
fn an_empty_selection_shows_no_bulk_bar(cx: &mut TestAppContext) {
    let (mut harness, _reports) = bulk_bar(cx, 0, 12_000);

    assert!(harness.node("data.bulk").is_none());
}

#[gpui::test]
fn an_open_row_is_the_only_one_that_builds_a_detail(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(
        cx,
        Given {
            expanded: vec![Expanded::new("job-0002", 2)],
            ..Given::rows(40)
        },
    );

    assert!(harness.node("data.grid.job-0002.detail").is_some());
    assert!(harness.node("data.grid.job-0001.detail").is_none());
    assert_eq!(
        harness
            .node("data.grid.job-0002")
            .expect("published")
            .expanded,
        Some(true)
    );

    harness.click("data.grid.job-0001.expand");
    assert_eq!(
        *reports.expansions.borrow(),
        vec![("job-0001".into(), true)]
    );
    assert!(
        harness.node("data.grid.job-0001.detail").is_none(),
        "nothing was applied, so nothing opened"
    );
}

fn editing(cx: &mut TestAppContext, cell: EditingCell) -> (Harness, Rc<Reports>) {
    grid(
        cx,
        Given {
            editing: Some(cell),
            ..Given::rows(20)
        },
    )
}

#[gpui::test]
fn a_cell_asks_to_be_opened_and_opens_nothing_itself(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(cx, Given::rows(20));

    double_click(&mut harness, "data.grid.job-0001.owner");

    assert_eq!(
        *reports.edit_requests.borrow(),
        vec![("job-0001".to_string(), "owner".to_string())]
    );
    assert!(
        harness.node("data.grid.edit").is_none(),
        "the caller owns which cell is open, so nothing opened"
    );
}

#[gpui::test]
fn enter_commits_an_edit_once_and_writes_nothing(cx: &mut TestAppContext) {
    let (mut harness, reports) = editing(cx, EditingCell::new("job-0001", "owner", "owner-1"));

    let field = harness.node("data.grid.edit").expect("the cell is a field");
    assert_eq!(field.role, Role::Input);

    harness.keystrokes("x");
    harness.keystrokes("enter");

    let edits = reports.edits.borrow().clone();
    assert_eq!(edits.len(), 1, "an edit reports once, not once per frame");
    assert_eq!(edits[0].0, "job-0001");
    assert_eq!(edits[0].1, "owner");
    assert_eq!(edits[0].3, "commit");
    assert_eq!(
        edits[0].2, "owner-1x",
        "the value reported is what the field held"
    );
    assert_eq!(
        harness
            .node("data.grid.job-0001")
            .expect("published")
            .text
            .as_deref(),
        Some("Fixture job 0001"),
        "the grid never writes the value"
    );
}

#[gpui::test]
fn escape_reverts_an_edit_to_the_value_the_grid_was_given(cx: &mut TestAppContext) {
    let (mut harness, reports) = editing(cx, EditingCell::new("job-0001", "owner", "owner-1"));

    harness.keystrokes("z");
    harness.keystrokes("escape");

    let edits = reports.edits.borrow().clone();
    assert_eq!(edits.len(), 1);
    assert_eq!(edits[0].3, "revert");
    assert_eq!(
        edits[0].2, "owner-1",
        "a revert reports the value that still holds, not the one abandoned"
    );
}

#[gpui::test]
fn tab_commits_and_names_the_cell_it_moves_to(cx: &mut TestAppContext) {
    let (mut harness, reports) = editing(cx, EditingCell::new("job-0001", "owner", "owner-1"));

    harness.keystrokes("tab");

    let edits = reports.edits.borrow().clone();
    assert_eq!(edits.len(), 1);
    assert_eq!(edits[0].3, "commit");
}

#[gpui::test]
fn a_failed_refresh_keeps_the_rows_that_are_still_true(cx: &mut TestAppContext) {
    let (mut harness, _reports) = grid(
        cx,
        Given {
            failure: Some("The host refused the refresh".into()),
            ..Given::rows(40)
        },
    );

    let drawn = rows_of(&mut harness);
    assert!(
        !drawn.is_empty(),
        "a refresh that failed must not take the last verified rows away"
    );
    assert!(harness.node("data.grid.job-0000").is_some());

    let banner = harness.node("data.grid.failure").expect("published");
    assert_eq!(banner.role, Role::Status);
    assert_eq!(banner.value.as_deref(), Some("stale"));
    assert_eq!(banner.text.as_deref(), Some("The host refused the refresh"));
    assert!(banner.invalid);
    assert!(
        harness.node("data.grid.empty").is_none(),
        "a failure over real rows is not an empty state"
    );
}

#[gpui::test]
fn a_failure_with_nothing_behind_it_takes_the_surface(cx: &mut TestAppContext) {
    let (mut harness, _reports) = grid(
        cx,
        Given {
            failure: Some("The host refused the refresh".into()),
            ..Given::rows(0)
        },
    );

    let empty = harness.node("data.grid.empty").expect("published");
    assert_eq!(empty.value.as_deref(), Some("failed"));
    assert!(rows_of(&mut harness).is_empty());
}

#[gpui::test]
fn a_double_click_on_a_column_edge_asks_for_a_fit_and_measures_nothing(cx: &mut TestAppContext) {
    let (mut harness, reports) = grid(cx, Given::rows(1000));

    double_click(&mut harness, "data.grid.header.duration.resize");

    assert_eq!(
        *reports.fits.borrow(),
        vec!["duration".to_string()],
        "the grid cannot measure the rows it never drew, so it reports the request"
    );
}