BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / layout_guard.rs

layout_guard.rs

layout_guard.rs 28.1 KiB Download Raw
1use std::collections::HashSet;
2use std::fs;
3use std::path::{Path, PathBuf};
4
5use regex::Regex;
6
7const WIDGETS_FILE: &str = "views/widgets.rs";
8const SCAN_ALLOWLIST: &[(&str, &str)] = &[
9 ("views/toolbar_placement.rs", ".top(px(-SLOT_HEIGHT))"),
10 ("views/conversation.rs", ".bottom(px(-1.))"),
11];
12
13fn source_files(directory: &Path, files: &mut Vec<PathBuf>) {
14 for entry in fs::read_dir(directory).expect("read source directory") {
15 let path = entry.expect("directory entry").path();
16 if path.is_dir() {
17 source_files(&path, files);
18 } else if path.extension().is_some_and(|extension| extension == "rs") {
19 files.push(path);
20 }
21 }
22}
23
24fn negative_offsets(
25 pattern: &Regex,
26 source: &str,
27 relative: &str,
28) -> Vec<(usize, Option<usize>, String)> {
29 pattern
30 .find_iter(source)
31 .map(|found| {
32 let line_number = source[..found.start()].matches('\n').count() + 1;
33 let from_match = &source[found.start()..];
34 let allowed = SCAN_ALLOWLIST.iter().position(|(allowed_file, snippet)| {
35 *allowed_file == relative && from_match.starts_with(snippet)
36 });
37 let line_end = from_match.find('\n').unwrap_or(from_match.len());
38 (
39 line_number,
40 allowed,
41 from_match[..line_end].trim().to_owned(),
42 )
43 })
44 .collect()
45}
46
47fn offset_pattern() -> Regex {
48 Regex::new(r"\.(top|right|bottom|left|inset)\(\s*(px\(\s*)?-").expect("pattern")
49}
50
51#[test]
52fn matcher_catches_wrapped_offsets() {
53 let source = "let a = 1;\nlet b = div()\n .top(\n px(-4.))\n .left(px(2.));\n";
54 let found = negative_offsets(&offset_pattern(), source, "views/other.rs");
55 assert_eq!(found, [(3, None, ".top(".to_owned())]);
56}
57
58#[test]
59fn matcher_matches_allowlist_from_match_start() {
60 let source = "x\n .bottom(px(-1.))\n";
61 let found = negative_offsets(&offset_pattern(), source, "views/conversation.rs");
62 assert_eq!(found, [(2, Some(1), ".bottom(px(-1.))".to_owned())]);
63}
64
65#[test]
66fn negative_offsets_go_through_corner_badge() {
67 let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
68 let pattern = offset_pattern();
69 let mut files = Vec::new();
70 source_files(&root, &mut files);
71 let mut matched_allowlist = HashSet::new();
72 let mut violations = Vec::new();
73 for file in files {
74 let relative = file
75 .strip_prefix(&root)
76 .expect("inside src")
77 .to_string_lossy()
78 .replace('\\', "/");
79 if relative == WIDGETS_FILE || relative == "layout_guard.rs" {
80 continue;
81 }
82 let source = fs::read_to_string(&file).expect("read source file");
83 for (line_number, position, text) in negative_offsets(&pattern, &source, &relative) {
84 match position {
85 Some(position) => {
86 matched_allowlist.insert(position);
87 }
88 None => violations.push(format!(
89 "{relative}:{line_number}: negative absolute offset, use widgets::corner_badge: {text}"
90 )),
91 }
92 }
93 }
94 let stale: Vec<String> = SCAN_ALLOWLIST
95 .iter()
96 .enumerate()
97 .filter(|(position, _)| !matched_allowlist.contains(position))
98 .map(|(_, (file, snippet))| format!("stale allowlist entry, remove it: {file} {snippet}"))
99 .collect();
100 assert!(
101 violations.is_empty() && stale.is_empty(),
102 "{}",
103 violations
104 .into_iter()
105 .chain(stale)
106 .collect::<Vec<_>>()
107 .join("\n")
108 );
109}
110
111mod frames {
112 use std::collections::HashSet;
113 use std::sync::Arc;
114 use std::time::Duration;
115
116 use gpui_kit::test::TestWindowExt as _;
117 use gpui_kit::{
118 AppContext as _, Bounds, Pixels, TestAppContext, VisualTestContext, WindowOptions, point,
119 px, size,
120 };
121 use store::Store;
122
123 use std::time::Instant;
124
125 use calling::{CallState, CallUpdate, CaptionEntry, CaptionState, RosterEntry, call_channel};
126 use gpui_kit::Entity;
127
128 use crate::app_state::{AppHandle, AppState, Mode, Selection};
129 use crate::call::{ActiveCall, CallModel};
130 use crate::demo;
131 use crate::user_activity::UserInput;
132 use crate::views::call_transcript::TranscriptPanel;
133 use crate::views::proposal_card::{PROPOSAL_BUTTONS, PROPOSAL_CARD, PROPOSAL_THUMBNAILS};
134 use crate::views::reaction_proposal_pill::REACTION_PILL;
135 use crate::views::recap_tab::RECAP_REGION;
136 use crate::views::shell::{AppShell, Startup, bind_keys, install_globals, sidebar_hidden_in_call};
137 use crate::views::shortcuts::{OpenActivity, OpenCallsTab, OpenChannelsTab, OpenSaved};
138
139 const GUARDED: &[&str] = &[
140 "shell",
141 "shell/title-bar",
142 "shell/title-bar/search",
143 "shell/title-bar/own-status",
144 "shell/title-bar/own-status/avatar",
145 "shell/islands",
146 "shell/islands/rail",
147 "shell/islands/sidebar",
148 "shell/islands/main",
149 "shell/status-bar",
150 ];
151 const CALL_GUARDED: &[&str] = &[
152 "shell/islands/main/call-header",
153 "shell/islands/main/call-stage",
154 "shell/islands/main/call-controls",
155 "shell/islands/main/call-controls/mic",
156 "shell/islands/main/call-controls/leave",
157 ];
158 const CALLS_TAGS: &[&str] = &[
159 "shell/islands/sidebar/calls-actions",
160 "shell/islands/sidebar/calls-actions/meet-now",
161 "shell/islands/sidebar/calls-actions/new-meeting",
162 ];
163 const PREJOIN_TAGS: &[&str] = &[
164 "shell/islands/main/prejoin",
165 "shell/islands/main/prejoin/preview",
166 "shell/islands/main/prejoin/controls",
167 "shell/islands/main/prejoin/devices",
168 "shell/islands/main/prejoin/audio",
169 "shell/islands/main/prejoin/actions",
170 ];
171 const PREJOIN_LINK: &str = "https://teams.microsoft.com/l/meetup-join/19%3ameeting_guard%40thread.v2/0?context=%7b%22Tid%22%3a%22t%22%2c%22Oid%22%3a%22o%22%7d";
172 const CALL_TRANSCRIPT: &str = "shell/islands/main/call-transcript";
173 const PEOPLE_PANEL: &str = "shell/islands/main/call-people";
174 const SHARE_GUARDED: &[&str] = &[
175 "shell/islands/main/call-stage/share-content",
176 "shell/islands/main/call-stage/share-content/zoom-chip",
177 "shell/islands/main/call-stage/share-divider",
178 "shell/islands/main/call-stage/share-strip",
179 ];
180 const OVERLAY_PANELS: &[&str] = &[CALL_TRANSCRIPT, PEOPLE_PANEL];
181 const OVERLAY_CHROME: &[&str] = &[
182 "shell/islands/main/call-header",
183 "shell/islands/main/call-stage",
184 ];
185 const MENU: &str = "popup-menu";
186 const OWN_STATUS: &str = "shell/title-bar/own-status";
187 const RECAP_TAB: &str = "shell/islands/main/recap-tab";
188 const RECAP_MEETING_CHAT: &str = "demo-chat-meeting-standup";
189 const PROPOSAL_CHAT: &str = "demo-chat-release";
190 const REACTION_CHAT: &str = "demo-chat-mara";
191 const AGENT_TAGS: [&str; 4] = [
192 PROPOSAL_CARD,
193 PROPOSAL_THUMBNAILS,
194 PROPOSAL_BUTTONS,
195 REACTION_PILL,
196 ];
197 const SIZES: [(f32, f32); 3] = [(640., 480.), (1280., 800.), (1920., 1080.)];
198 const TOLERANCE: f32 = 0.5;
199 const KNOWN_VIOLATIONS: &[&str] = &[];
200
201 type Tag = (&'static str, Bounds<Pixels>);
202
203 enum Screen {
204 Tab(&'static str, Option<fn(&mut VisualTestContext)>),
205 StatusMenu,
206 Call,
207 Prejoin,
208 CallTranscript,
209 CallPeople,
210 CallShare,
211 }
212
213 fn parent_of(path: &str) -> Option<&str> {
214 path.rsplit_once('/').map(|(parent, _)| parent)
215 }
216
217 fn contains(outer: Bounds<Pixels>, inner: Bounds<Pixels>) -> bool {
218 let tolerance = px(TOLERANCE);
219 inner.left() >= outer.left() - tolerance
220 && inner.top() >= outer.top() - tolerance
221 && inner.right() <= outer.right() + tolerance
222 && inner.bottom() <= outer.bottom() + tolerance
223 }
224
225 fn overlaps(first: Bounds<Pixels>, second: Bounds<Pixels>) -> bool {
226 let tolerance = px(TOLERANCE);
227 first.left() < second.right() - tolerance
228 && second.left() < first.right() - tolerance
229 && first.top() < second.bottom() - tolerance
230 && second.top() < first.bottom() - tolerance
231 }
232
233 fn describe(bounds: Bounds<Pixels>) -> String {
234 format!(
235 "[{:.1},{:.1} {:.1}x{:.1}]",
236 f32::from(bounds.origin.x),
237 f32::from(bounds.origin.y),
238 f32::from(bounds.size.width),
239 f32::from(bounds.size.height)
240 )
241 }
242
243 fn violations(
244 tags: &[Tag],
245 window: Bounds<Pixels>,
246 expected: &[&str],
247 ) -> Vec<(String, String)> {
248 let mut found = Vec::new();
249 let bounds_of = |path: &str| {
250 tags.iter()
251 .find(|(tag, _)| *tag == path)
252 .map(|(_, bounds)| *bounds)
253 };
254 for path in expected {
255 if bounds_of(path).is_none() {
256 found.push((
257 format!("{path}:missing"),
258 format!("{path} was not rendered"),
259 ));
260 }
261 }
262 for (path, bounds) in tags {
263 if !contains(window, *bounds) {
264 found.push((
265 format!("{path}:outside-window"),
266 format!(
267 "{path} {} leaves the window {}",
268 describe(*bounds),
269 describe(window)
270 ),
271 ));
272 }
273 if let Some(parent) =
274 parent_of(path).and_then(|parent| bounds_of(parent).map(|bounds| (parent, bounds)))
275 {
276 if !contains(parent.1, *bounds) {
277 found.push((
278 format!("{path}:outside-parent"),
279 format!(
280 "{path} {} leaves {} {}",
281 describe(*bounds),
282 parent.0,
283 describe(parent.1)
284 ),
285 ));
286 }
287 }
288 for (other, other_bounds) in tags {
289 let overlays = |first: &str, second: &str| {
290 OVERLAY_PANELS.contains(&first) && OVERLAY_CHROME.contains(&second)
291 };
292 let siblings = path < other
293 && parent_of(path).is_some()
294 && parent_of(path) == parent_of(other)
295 && !overlays(path, other)
296 && !overlays(other, path);
297 if siblings && overlaps(*bounds, *other_bounds) {
298 found.push((
299 format!("{path}:overlaps:{other}"),
300 format!(
301 "{path} {} overlaps {other} {}",
302 describe(*bounds),
303 describe(*other_bounds)
304 ),
305 ));
306 }
307 }
308 }
309 found
310 }
311
312 const SETTLE_FRAMES: usize = 2;
313 const SETTLE_LIMIT: usize = 60;
314 const SETTLE_STEP: Duration = Duration::from_millis(50);
315
316 fn collect(visual: &mut VisualTestContext, awaited: Option<&'static str>) -> Vec<Tag> {
317 let mut frames = 0;
318 while frames < SETTLE_FRAMES
319 || awaited.is_some_and(|path| visual.debug_bounds(path).is_none())
320 {
321 assert!(frames < SETTLE_LIMIT, "{awaited:?} never rendered");
322 visual.executor().advance_clock(SETTLE_STEP);
323 std::thread::sleep(SETTLE_STEP);
324 visual.run_until_parked();
325 visual.update(|window, cx| window.render_frame(cx));
326 frames += 1;
327 }
328 GUARDED
329 .iter()
330 .chain(CALL_GUARDED)
331 .chain(CALLS_TAGS)
332 .chain(PREJOIN_TAGS)
333 .chain(SHARE_GUARDED)
334 .chain([
335 &CALL_TRANSCRIPT,
336 &MENU,
337 &RECAP_TAB,
338 &RECAP_REGION,
339 &PEOPLE_PANEL,
340 ])
341 .chain(&AGENT_TAGS)
342 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
343 .collect()
344 }
345
346 fn sharing_call() -> ActiveCall {
347 let mut call = gallery_call();
348 call.model.apply(CallUpdate::ScreenShare(Some("8:orgid:guard-1".to_owned())));
349 call.share_stage.view.step_in((800., 450.));
350 call
351 }
352
353 fn gallery_call() -> ActiveCall {
354 let (handle, _control) = call_channel();
355 let mut model = CallModel::meeting("Standup", false);
356 model.apply(CallUpdate::State(CallState::Connected {
357 since: Instant::now(),
358 }));
359 model.apply(CallUpdate::Roster(
360 (0..11)
361 .map(|index| RosterEntry {
362 mri: format!("8:orgid:guard-{index}"),
363 display_name: format!("Guest {index}"),
364 muted: false,
365 in_lobby: false,
366 has_video: false,
367 sharing: false,
368 hand: None,
369 spotlight: None,
370 organizer: false,
371 ..Default::default()
372 })
373 .collect(),
374 ));
375 ActiveCall::new(1, model, handle.commands, None, handle.video)
376 }
377
378 fn mount(cx: &mut TestAppContext) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {
379 mount_with(cx, false)
380 }
381
382 fn mount_with(
383 cx: &mut TestAppContext,
384 agent_api: bool,
385 ) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {
386 cx.update(gpui_kit::init);
387 cx.update(|cx| {
388 crate::theme::apply(cx);
389 bind_keys(cx);
390 let store = Store::open_in_memory().expect("in-memory store");
391 demo::seed(&store);
392 let store = Arc::new(store);
393 if agent_api {
394 crate::agent_api::init(store.clone(), true, cx);
395 }
396 let mode = Mode {
397 demo: true,
398 read_only: false,
399 demo_sync: None,
400 };
401 let state = cx.new(|_| AppState::new(store, mode));
402 install_globals(&state, UserInput::new(), cx);
403 demo::start_session(&state, cx);
404 let shared_state = state.clone();
405 let startup = Startup {
406 switcher_query: None,
407 composer_text: None,
408 reply_to_last: false,
409 };
410 let window = gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
411 cx.new(|cx| AppShell::new(state, None, startup, window, cx))
412 })
413 .expect("open test window")
414 .0;
415 (window, shared_state)
416 })
417 }
418
419 fn rectangle(left: f32, top: f32, width: f32, height: f32) -> Bounds<Pixels> {
420 Bounds {
421 origin: point(px(left), px(top)),
422 size: size(px(width), px(height)),
423 }
424 }
425
426 #[test]
427 fn rules_flag_overlap_and_overflow() {
428 let window = rectangle(0., 0., 100., 100.);
429 let tags: Vec<Tag> = vec![
430 ("shell", rectangle(0., 0., 100., 100.)),
431 ("shell/islands", rectangle(0., 0., 100., 50.)),
432 ("shell/islands/rail", rectangle(0., 0., 60., 50.)),
433 ("shell/islands/sidebar", rectangle(50., 0., 60., 50.)),
434 ];
435 let keys: Vec<String> = violations(&tags, window, &["shell/status-bar"])
436 .into_iter()
437 .map(|(key, _)| key)
438 .collect();
439 assert_eq!(
440 keys,
441 [
442 "shell/status-bar:missing",
443 "shell/islands/rail:overlaps:shell/islands/sidebar",
444 "shell/islands/sidebar:outside-window",
445 "shell/islands/sidebar:outside-parent",
446 ]
447 );
448 }
449
450 #[gpui_kit::test]
451 fn no_element_overlaps_or_leaves_its_container(cx: &mut TestAppContext) {
452 let (handle, app) = mount(cx);
453 let mut visual = VisualTestContext::from_window(handle, cx);
454 let mut seen_known = HashSet::new();
455 let mut unexpected = Vec::new();
456 for (width, height) in SIZES {
457 visual.simulate_resize(size(px(width), px(height)));
458 let window = Bounds {
459 origin: point(px(0.), px(0.)),
460 size: size(px(width), px(height)),
461 };
462 let screens = [
463 Screen::Tab("chats", None),
464 Screen::Tab(
465 "activity",
466 Some(|visual| visual.dispatch_action(OpenActivity)),
467 ),
468 Screen::Tab(
469 "channels",
470 Some(|visual| visual.dispatch_action(OpenChannelsTab)),
471 ),
472 Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),
473 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
474 Screen::Prejoin,
475 Screen::StatusMenu,
476 Screen::Call,
477 Screen::CallTranscript,
478 Screen::CallPeople,
479 Screen::CallShare,
480 ];
481 for screen in screens {
482 let (screen_name, status_menu) = match screen {
483 Screen::Tab(name, open) => {
484 if let Some(open) = open {
485 open(&mut visual);
486 }
487 (name, false)
488 }
489 Screen::Call | Screen::CallPeople => {
490 let people_open = matches!(screen, Screen::CallPeople);
491 visual.update(|_, cx| {
492 app.update(cx, |state, cx| {
493 let mut call = gallery_call();
494 call.people_open = people_open;
495 state.call = Some(call);
496 cx.notify();
497 })
498 });
499 (if people_open { "call-people" } else { "call" }, false)
500 }
501 Screen::Prejoin => {
502 let state = visual.update(|_, cx| cx.global::<AppHandle>().0.clone());
503 visual.update(|_, cx| {
504 state.update(cx, |state, cx| state.join_meeting_link(PREJOIN_LINK, cx))
505 });
506 ("prejoin", false)
507 }
508 Screen::CallTranscript => {
509 visual.update(|window, cx| {
510 app.update(cx, |state, cx| {
511 let mut call = gallery_call();
512 call.model.apply(CallUpdate::Captions(CaptionState::On));
513 for index in 0..40 {
514 call.model.note_caption(
515 CaptionEntry {
516 id: format!("guard-{index}"),
517 user_id: "8:orgid:guard-0".into(),
518 display_name: "Guest 0".into(),
519 text: "A long guarded sentence that has to wrap inside the panel".into(),
520 is_final: true,
521 },
522 Instant::now(),
523 );
524 }
525 call.transcript_open = true;
526 state.call = Some(call);
527 let app_entity = cx.entity();
528 state.transcript_panel = Some(cx.new(|cx| TranscriptPanel::new(app_entity, window, cx)));
529 cx.notify();
530 })
531 });
532 ("call-transcript", false)
533 }
534 Screen::CallShare => {
535 visual.update(|_, cx| {
536 app.update(cx, |state, cx| {
537 state.call = Some(sharing_call());
538 cx.notify();
539 })
540 });
541 ("call-share", false)
542 }
543 Screen::StatusMenu => {
544 let tags = collect(&mut visual, None);
545 let button = tags
546 .iter()
547 .find(|(path, _)| *path == OWN_STATUS)
548 .map(|(_, bounds)| *bounds)
549 .expect("own status button rendered");
550 visual.simulate_click(button.center(), Default::default());
551 ("status-menu", true)
552 }
553 };
554 let is_call = matches!(screen_name, "call" | "call-people" | "call-transcript" | "call-share");
555 let tags = collect(&mut visual, status_menu.then_some(MENU));
556 let mut expected = GUARDED.to_vec();
557 if is_call {
558 expected.extend(CALL_GUARDED);
559 let panel_open = matches!(screen_name, "call-people" | "call-transcript");
560 if sidebar_hidden_in_call(width, panel_open) {
561 expected.retain(|path| *path != "shell/islands/sidebar");
562 }
563 }
564 if screen_name == "call-transcript" {
565 expected.push(CALL_TRANSCRIPT);
566 }
567 if screen_name == "call-people" {
568 expected.push(PEOPLE_PANEL);
569 }
570 if screen_name == "call-share" {
571 expected.extend(SHARE_GUARDED);
572 }
573 if status_menu {
574 expected.push(MENU);
575 }
576 match screen_name {
577 "calls" => expected.extend(CALLS_TAGS),
578 "prejoin" => expected.extend(PREJOIN_TAGS),
579 _ => {}
580 }
581 let mut found = violations(&tags, window, &expected);
582 if status_menu {
583 let menu = tags
584 .iter()
585 .find(|(path, _)| *path == MENU)
586 .map(|(_, bounds)| *bounds);
587 let button = tags
588 .iter()
589 .find(|(path, _)| *path == OWN_STATUS)
590 .map(|(_, bounds)| *bounds);
591 if let (Some(menu), Some(button)) = (menu, button) {
592 if overlaps(menu, button) {
593 found.push((
594 format!("{MENU}:covers:{OWN_STATUS}"),
595 format!(
596 "{MENU} {} covers {OWN_STATUS} {}",
597 describe(menu),
598 describe(button)
599 ),
600 ));
601 }
602 }
603 visual.simulate_keystrokes("escape");
604 visual.run_until_parked();
605 }
606 if is_call {
607 visual.update(|_, cx| {
608 app.update(cx, |state, cx| {
609 state.call = None;
610 cx.notify();
611 })
612 });
613 }
614 if screen_name == "prejoin" {
615 let state = visual.update(|_, cx| cx.global::<AppHandle>().0.clone());
616 visual.update(|_, cx| state.update(cx, |state, cx| state.cancel_prejoin(cx)));
617 }
618 for (key, message) in found {
619 let full_key = format!("{screen_name}@{width}x{height}:{key}");
620 if KNOWN_VIOLATIONS.contains(&full_key.as_str()) {
621 seen_known.insert(full_key);
622 } else {
623 unexpected.push(format!("{full_key}: {message}"));
624 }
625 }
626 }
627 }
628 let stale: Vec<String> = KNOWN_VIOLATIONS
629 .iter()
630 .filter(|key| !seen_known.contains(**key))
631 .map(|key| format!("stale known violation, remove it: {key}"))
632 .collect();
633 assert!(
634 unexpected.is_empty() && stale.is_empty(),
635 "{}",
636 unexpected
637 .into_iter()
638 .chain(stale)
639 .collect::<Vec<_>>()
640 .join("\n")
641 );
642 }
643 #[gpui_kit::test]
644 fn recap_tab_stays_inside_the_main_island(cx: &mut TestAppContext) {
645 let (handle, state) = mount(cx);
646 let mut visual = VisualTestContext::from_window(handle, cx);
647 for (width, height) in SIZES {
648 visual.simulate_resize(size(px(width), px(height)));
649 let window = Bounds {
650 origin: point(px(0.), px(0.)),
651 size: size(px(width), px(height)),
652 };
653 visual.update(|_, cx| {
654 state.update(cx, |state, cx| {
655 state.select(Selection::Chat(RECAP_MEETING_CHAT.to_owned()), cx)
656 })
657 });
658 collect(&mut visual, Some(RECAP_TAB));
659 let tab = visual.debug_bounds(RECAP_TAB).expect("recap tab rendered");
660 visual.simulate_click(tab.center(), Default::default());
661 let tags = collect(&mut visual, Some(RECAP_REGION));
662 let mut expected = GUARDED.to_vec();
663 expected.extend([RECAP_TAB, RECAP_REGION]);
664 let found: Vec<String> = violations(&tags, window, &expected)
665 .into_iter()
666 .map(|(key, message)| format!("recap@{width}x{height}:{key}: {message}"))
667 .collect();
668 assert!(found.is_empty(), "{}", found.join("\n"));
669 }
670 }
671
672 #[gpui_kit::test]
673 fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {
674 let (handle, state) = mount_with(cx, true);
675 let mut visual = VisualTestContext::from_window(handle, cx);
676 for (width, height) in SIZES {
677 visual.simulate_resize(size(px(width), px(height)));
678 let window = Bounds {
679 origin: point(px(0.), px(0.)),
680 size: size(px(width), px(height)),
681 };
682 for (chat, expected_tags) in [
683 (PROPOSAL_CHAT, &AGENT_TAGS[..3]),
684 (REACTION_CHAT, &AGENT_TAGS[3..]),
685 ] {
686 visual.update(|_, cx| {
687 state.update(cx, |state, cx| {
688 state.select(Selection::Chat(chat.to_owned()), cx)
689 })
690 });
691 let tags = collect(&mut visual, Some(expected_tags[0]));
692 let mut expected = GUARDED.to_vec();
693 expected.extend(expected_tags);
694 let found: Vec<String> = violations(&tags, window, &expected)
695 .into_iter()
696 .map(|(key, message)| format!("{chat}@{width}x{height}:{key}: {message}"))
697 .collect();
698 assert!(found.is_empty(), "{}", found.join("\n"));
699 }
700 }
701 }
702}
703
704#[test]
705fn lines_are_solid() {
706 let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
707 let mut files = Vec::new();
708 source_files(&root, &mut files);
709 let violations: Vec<String> = files
710 .iter()
711 .filter(|file| !file.ends_with("layout_guard.rs"))
712 .flat_map(|file| {
713 let source = fs::read_to_string(file).expect("read source file");
714 source
715 .lines()
716 .enumerate()
717 .filter(|(_, line)| {
718 line.contains(".border_dashed(") || line.contains(".border_dotted(")
719 })
720 .map(|(index, line)| {
721 format!(
722 "{}:{}: lines are always solid: {}",
723 file.display(),
724 index + 1,
725 line.trim()
726 )
727 })
728 .collect::<Vec<_>>()
729 })
730 .collect();
731 assert!(violations.is_empty(), "{}", violations.join("\n"));
732}