// SPDX-License-Identifier: Apache-2.0 // Copyright Scienting // Source: https://git.scient.ing/education/coursebank //! What 2.1 renders: the lecture page, the glossary page, and the student //! reports, and what it must never render for a student. mod common; use std::path::Path; use common::{design, v21_course}; use coursebank::assessment::{AssessmentFile, Form}; use coursebank::catalog::Catalog; use coursebank::lecture::{PageOptions, Style, glossary_markdown, page_markdown}; use coursebank::responses::{Response, ResponseSet}; use coursebank::typst::config::{RenderConfig, Variant}; /// The example lecture page in the Plain style, which is the style the /// preview was written in. fn plain_page(catalog: &Catalog) -> String { let options = PageOptions { style: Style::Plain, ..PageOptions::default() }; page_markdown(&catalog.course, "l09", &options).expect("renders") } /// A page line with its link targets removed: `[gap](glossary.html#x)` /// becomes `[gap]`, which is how the prototype's preview writes a link. fn unlinked(line: &str) -> String { let mut out = String::new(); let mut rest = line; while let Some(at) = rest.find("](") { out.push_str(&rest[..=at]); let after = &rest[at + 2..]; match after.find(')') { Some(close) => rest = &after[close + 1..], None => { rest = after; break; } } } out.push_str(rest); out } #[test] fn the_lecture_page_has_the_content_and_order_of_the_preview() { let catalog = Catalog::load(&v21_course("page-snapshot")).unwrap(); let rendered: Vec = plain_page(&catalog) .lines() .map(unlinked) .filter(|l| !l.trim().is_empty()) .collect(); let preview_text = std::fs::read_to_string(design().join("examples/v21/lecture-page-preview.md")).unwrap(); // The prototype prints a target reference as the raw id; coursebank prints // its number on the page, as the 2.0 readings page always has. let preview_text = preview_text.replace("(T t-align-fill-matrix)", "(T 3)"); let preview: Vec<&str> = preview_text .lines() .filter(|l| !l.trim().is_empty() && !l.starts_with("