Repository navigation
fix(engine): say which presentation map pages lose their map #3190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jgregoriorincon
merged 3 commits into
opengeos:main
from
jgregoriorincon:fix/3047-map-page-deleted-map
Nov 28, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| //! A presentation map page whose map the project doesn't have is drawn over the active map: | ||
| //! deleting the map, or importing such a presentation, says which pages (#3047). All keep the name. | ||
|
|
||
| use super::*; | ||
| use rustgis_map::presentation::{Page, PageKind, Presentation}; | ||
|
|
||
| /// The notices `command` gives about map pages that show a map the project doesn't have. | ||
| fn missing(s: &mut Session, command: &str, params: Value) -> Vec<String> { | ||
| let mark = s.notice_mark(); | ||
| s.run(command, ¶ms).unwrap(); | ||
| s.notices_since(mark).iter().map(|n| n.text.clone()).filter(|t| t.contains("which the project doesn't have")).collect() | ||
| } | ||
|
|
||
| /// The sample world with a map `Other`, the world in view, and a presentation `Tour`. | ||
| fn with_tour() -> Session { | ||
| let mut s = world(); | ||
| let home = s.map().name.clone(); | ||
| s.run("map.new", &json!({"name": "Other"})).unwrap(); | ||
| s.run("map.activate", &json!({"name": home})).unwrap(); | ||
| s.run("presentation.new", &json!({"name": "Tour"})).unwrap(); | ||
| s | ||
| } | ||
|
|
||
| fn page(s: &mut Session, map: &str) { | ||
| s.run("presentation.mapPage", &json!({"map": map, "title": "Sites"})).unwrap(); | ||
| } | ||
|
|
||
| /// The map the frame of page `k` of the first presentation is drawn over. | ||
| fn drawn_over(s: &Session, k: usize) -> String { | ||
| let pres = &s.project.presentations[0]; | ||
| let layout = crate::cmd::presentation::page_layout(s, pres, &pres.pages[k]); | ||
| layout | ||
| .elements | ||
| .iter() | ||
| .find_map(|e| match &e.kind { | ||
| rustgis_map::layout::ElementKind::MapFrame { map, .. } => Some(map.clone()), | ||
| _ => None, | ||
| }) | ||
| .unwrap() | ||
| } | ||
|
|
||
| /// A presentation file with one map page for each of `maps`. | ||
| fn file_showing(maps: &[&str]) -> Value { | ||
| let pages = maps | ||
| .iter() | ||
| .map(|map| Page { | ||
| title: "Sites".into(), | ||
| kind: PageKind::Map { map: (*map).into(), center: rustgis_geom::Coord::new(0.0, 0.0), width_m: 1000.0 }, | ||
| notes: String::new(), | ||
| seconds: 5.0, | ||
| }) | ||
| .collect(); | ||
| let pres = Presentation { name: "Filed".into(), pages, ..Presentation::default() }; | ||
| json!({"text": serde_json::to_string(&pres).unwrap()}) | ||
| } | ||
|
|
||
| #[test] | ||
| fn deleting_a_map_a_page_shows_says_so_and_the_page_keeps_the_name() { | ||
| let mut s = with_tour(); | ||
| page(&mut s, "Other"); | ||
| assert_eq!( | ||
| missing(&mut s, "map.remove", json!({"name": "Other"})), | ||
| [ | ||
| "1 map page shows 'Other', which the project doesn't have, so it is drawn over the active map until a map of that name comes back: presentation 'Tour', page 2" | ||
| ] | ||
| ); | ||
| assert_eq!(drawn_over(&s, 1), s.map().name); | ||
| // Exporting draws it as before, with nothing more said. | ||
| let mark = s.notice_mark(); | ||
| crate::cmd::presentation::export_bytes(&mut s, 0, "html", 120.0).unwrap(); | ||
| assert!(s.notices_since(mark).iter().all(|n| !n.text.contains("which the project doesn't have"))); | ||
| // A map of that name brings the page back to it. | ||
| s.run("map.new", &json!({"name": "Other"})).unwrap(); | ||
| assert_eq!(drawn_over(&s, 1), "Other"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn undoing_the_deletion_draws_the_page_over_its_map_again() { | ||
| let mut s = with_tour(); | ||
| page(&mut s, "Other"); | ||
| s.run("map.remove", &json!({"name": "Other"})).unwrap(); | ||
| assert_eq!(missing(&mut s, "edit.undo", Value::Null), Vec::<String>::new()); | ||
| assert_eq!(drawn_over(&s, 1), "Other"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn pages_of_two_presentations_are_said_once() { | ||
| let mut s = with_tour(); | ||
| page(&mut s, "Other"); | ||
| s.run("presentation.new", &json!({"name": "Second"})).unwrap(); | ||
| page(&mut s, "Other"); | ||
| assert_eq!( | ||
| missing(&mut s, "map.remove", json!({"name": "Other"})), | ||
| [ | ||
| "2 map pages show 'Other', which the project doesn't have, so they are drawn over the active map until a map of that name comes back: presentation 'Tour', page 2; presentation 'Second', page 2" | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_page_that_spells_its_map_in_another_case_is_counted() { | ||
| let mut s = with_tour(); | ||
| page(&mut s, "Other"); | ||
| let PageKind::Map { map, .. } = &mut s.project.presentations[0].pages[1].kind else { panic!("a map page") }; | ||
| *map = "oTHER".into(); | ||
| assert_eq!( | ||
| missing(&mut s, "map.remove", json!({"name": "Other"})), | ||
| [ | ||
| "1 map page shows 'oTHER', which the project doesn't have, so it is drawn over the active map until a map of that name comes back: presentation 'Tour', page 2" | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deleting_a_map_no_page_shows_says_nothing() { | ||
| let mut s = with_tour(); | ||
| s.run("map.new", &json!({"name": "Spare"})).unwrap(); | ||
| page(&mut s, "Other"); | ||
| // A page already without its map isn't said again when another map goes. | ||
| let PageKind::Map { map, .. } = &mut s.project.presentations[0].pages[1].kind else { panic!("a map page") }; | ||
| *map = "Gone".into(); | ||
| assert_eq!(missing(&mut s, "map.remove", json!({"name": "Spare"})), Vec::<String>::new()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deleting_a_map_with_no_presentation_says_nothing() { | ||
| let mut s = world(); | ||
| s.run("map.new", &json!({"name": "Other"})).unwrap(); | ||
| assert_eq!(missing(&mut s, "map.remove", json!({"name": "Other"})), Vec::<String>::new()); | ||
| } | ||
|
|
||
| /// Adds the offline area `Crew`, made from the map `source`. | ||
| fn offline_area(s: &mut Session, source: &str) { | ||
| let extent = rustgis_geom::Extent::new(0.0, 0.0, 1.0, 1.0); | ||
| let area = json!({"name": "Crew", "map": source, "extent": extent, "created": 0.0, "data": s.project.maps[0]}); | ||
| s.project.offline_areas.push(serde_json::from_value(area).unwrap()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn removing_an_offline_area_says_the_pages_that_showed_its_map() { | ||
| let mut s = with_tour(); | ||
| let home = s.map().name.clone(); | ||
| s.run("map.new", &json!({"name": "Crew (offline)"})).unwrap(); | ||
| offline_area(&mut s, &home); | ||
| page(&mut s, "Crew (offline)"); | ||
| assert_eq!( | ||
| missing(&mut s, "offline.remove", json!({"name": "Crew"})), | ||
| [ | ||
| "1 map page shows 'Crew (offline)', which the project doesn't have, so it is drawn over the active map until a map of that name comes back: presentation 'Tour', page 2" | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn removing_an_offline_area_whose_map_is_kept_says_nothing() { | ||
| let mut s = world(); | ||
| s.run("map.rename", &json!({"name": "Crew (offline)"})).unwrap(); | ||
| s.run("presentation.new", &json!({"name": "Tour"})).unwrap(); | ||
| page(&mut s, "Crew (offline)"); | ||
| offline_area(&mut s, "Source"); | ||
| assert_eq!(missing(&mut s, "offline.remove", json!({"name": "Crew"})), Vec::<String>::new()); | ||
| assert_eq!(drawn_over(&s, 1), "Crew (kept)"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn importing_a_presentation_says_the_pages_whose_map_is_missing() { | ||
| let mut s = world(); | ||
| let home = s.map().name.clone(); | ||
| assert_eq!( | ||
| missing(&mut s, "presentation.import", file_showing(&["Missing", &home, "missing"])), | ||
| [ | ||
| "2 map pages show 'Missing', which the project doesn't have, so they are drawn over the active map until a map of that name comes back: presentation 'Filed', pages 1, 3" | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn importing_a_presentation_whose_maps_are_all_there_says_nothing() { | ||
| let mut s = world(); | ||
| let home = s.map().name.clone(); | ||
| assert_eq!(missing(&mut s, "presentation.import", file_showing(&[&home])), Vec::<String>::new()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn many_missing_maps_are_named_up_to_three() { | ||
| let mut s = world(); | ||
| assert_eq!( | ||
| missing(&mut s, "presentation.import", file_showing(&["A", "B", "A", "C", "D", "E"])), | ||
| [ | ||
| "6 map pages show 'A', 'B', 'C', …, which the project doesn't have, so they are drawn over the active map until maps of those names come back: presentation 'Filed', pages 1, 2, 3, 4, 5, …" | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn pages_past_three_presentations_are_counted_and_not_listed() { | ||
| let mut s = with_tour(); | ||
| // Five pages in the first presentation, all listed; one in each of three more. | ||
| for _ in 0..5 { | ||
| page(&mut s, "Other"); | ||
| } | ||
| for name in ["Second", "Third", "Fourth"] { | ||
| s.run("presentation.new", &json!({"name": name})).unwrap(); | ||
| page(&mut s, "Other"); | ||
| } | ||
| assert_eq!( | ||
| missing(&mut s, "map.remove", json!({"name": "Other"})), | ||
| [ | ||
| "8 map pages show 'Other', which the project doesn't have, so they are drawn over the active map until a map of that name comes back: presentation 'Tour', pages 2, 3, 4, 5, 6; presentation 'Second', page 2; presentation 'Third', page 2; …" | ||
| ] | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.