diff options
Diffstat (limited to 'tests/plot.rs')
| -rw-r--r-- | tests/plot.rs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/plot.rs b/tests/plot.rs index 848ae49..0788ce9 100644 --- a/tests/plot.rs +++ b/tests/plot.rs @@ -193,3 +193,101 @@ async fn a_body_that_is_not_a_mapping_result_is_a_422() { .await; assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY); } + +/// Two responses for two traits, differing only in their LOD values, must +/// draw two different pictures -- and say which trait each is. +/// +/// The trace is the point: a plot that reused anything between requests +/// (a cached SVG, a stale scratch file) would draw the first trait's shape +/// for the second, and the only thing giving it away would be the title. +/// This pins both: the drawings differ, and each names its own trait from +/// the response's own `Trait:` note rather than falling back to a title +/// that says nothing. +#[tokio::test] +async fn two_traits_draw_two_different_plots() { + if !plotter_present("rqtl") { + eprintln!("skipping two_traits_draw_two_different_plots: needs the plotter script (RQTL_PLOTTER) and PLOT_PYTHON"); + return; + } + let Some(token) = auth_token().await else { + eprintln!("skipping two_traits_draw_two_different_plots: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)"); + return; + }; + + let canned = |name: &str, lods: [f64; 5]| { + serde_json::json!({ + "data": { + "markers": [ + ["rs1", "1", 3.1, lods[0]], + ["rs2", "1", 8.2, lods[1]], + ["rs3", "2", 12.0, lods[2]], + ["rs4", "2", 19.5, lods[3]], + ["rs5", "X", 30.0, lods[4]] + ], + "permutation": null + }, + // What /compute/rqtl writes first, and what /plot/rqtl reads + // its title from. + "notes": [ + format!("Trait: BXD::{name}"), + "Genotype: prepared panel subset x (version BXD.4, 93 individuals, 0 parents/F1s dropped); 5 of 5 supplied values aligned onto it by name." + ] + }) + }; + let mut svgs: Vec<(String, String, String)> = Vec::new(); + for (name, lods) in [ + ("10001", [0.2, 0.3, 2.9, 0.1, 0.4]), + ("10002", [1.8, 0.4, 0.2, 4.7, 0.9]), + ] { + let response = post_json_with_token( + "POST /plot/rqtl (two traits)", + "/plot/rqtl", + &token, + &canned(name, lods), + ) + .await; + assert_eq!(response.status(), StatusCode::OK); + let summary = response + .headers() + .get("x-plot-summary") + .expect("x-plot-summary") + .to_str() + .unwrap() + .to_string(); + let bytes = response.into_body().collect().await.unwrap().to_bytes(); + let text = String::from_utf8_lossy(&bytes).to_string(); + // The title names the trait, taken from the posted notes. + assert!( + text.contains(&format!("BXD::{name}")), + "the title carries the trait from the response's own note: {name}" + ); + svgs.push((name.to_string(), summary, text)); + } + let (first_name, first_summary, first) = &svgs[0]; + let (second_name, second_summary, second) = &svgs[1]; + assert_ne!(first, second, "{first_name} and {second_name} must not draw the same SVG"); + // And each draw its own peak, not the other's. + assert!(first_summary.contains("peak rs3"), "{first_summary}"); + assert!(second_summary.contains("peak rs4"), "{second_summary}"); + assert!( + first.contains("chr2 12 Mb, LOD 2.90") && !first.contains("LOD 4.70"), + "{first_name}'s own annotation only" + ); + assert!( + second.contains("chr2 20 Mb, LOD 4.70"), + "{second_name}'s own annotation: {second_summary}" + ); + // The traces themselves: no polyline point set should coincide. + let traces = |svg: &str| -> Vec<String> { + svg.split("<polyline points=\"") + .skip(1) + .map(|rest| rest.split('"').next().unwrap_or_default().to_string()) + .collect() + }; + let (a, b) = (traces(first), traces(second)); + assert_eq!(a.len(), b.len(), "same chromosomes in both"); + assert!( + a.iter().zip(&b).all(|(left, right)| left != right), + "every chromosome's trace differs between the two traits" + ); +} |
