composants.rs
87 lignes · 2962 octets
//! OI-011 — bibliothèque de composants, présentée sur /dev/composants (build debug). //! Le contrôle d'accessibilité axe-core et le comportement réel (HTMX, Alpine, CSP) sont //! vérifiés dans un navigateur par tests/navigateur/verifier.mjs. use axum::{body::Body, http::Request, http::StatusCode}; use http_body_util::BodyExt; mod commun; use tower::ServiceExt; async fn page() -> String { let res = commun::banc() .router .oneshot(Request::get("/dev/composants").body(Body::empty()).unwrap()) .await .unwrap(); assert_eq!(res.status(), StatusCode::OK); String::from_utf8(res.into_body().collect().await.unwrap().to_bytes().to_vec()).unwrap() } #[tokio::test] async fn chaque_composant_a_sa_section_de_demonstration() { let html = page().await; for id in [ "bouton", "champ", "secret", "option-card", "modal", "confirmation", "toast", "badge", "code", "stepper", ] { assert!(html.contains(&format!(r#"id="composant-{id}""#)), "section {id} absente"); } } #[tokio::test] async fn les_boutons_couvrent_toutes_les_variantes_de_la_charte() { let html = page().await; for variante in ["bg-primary", "border-ink", "bg-destructive", "rounded-full"] { assert!(html.contains(variante), "variante {variante} absente"); } } #[tokio::test] async fn le_champ_secret_est_masque_et_jamais_auto_complete() { let html = page().await; let secret = &html[html.find(r#"id="composant-secret""#).unwrap()..]; assert!(secret.contains(r#"type="password""#)); assert!(secret.contains(r#"autocomplete="new-password""#)); assert!(secret.contains(r#"aria-label="Afficher le mot de passe""#)); } #[tokio::test] async fn les_cartes_d_option_sont_de_vrais_boutons_radio() { let html = page().await; let cartes = &html[html.find(r#"id="composant-option-card""#).unwrap()..]; assert!(cartes.contains(r#"type="radio""#)); assert!(cartes.contains(" disabled"), "variante indisponible absente"); } #[tokio::test] async fn les_modals_sont_des_dialog_natifs() { let html = page().await; assert!(html.contains(r#"<dialog id="modal-demo""#)); assert!(html.contains(r#"role="alertdialog""#)); assert!(html.contains(r#"method="dialog""#), "fermeture sans JavaScript"); } #[tokio::test] async fn les_badges_ne_reposent_jamais_sur_la_couleur_seule() { let html = page().await; for libelle in ["Validée", "Avertissement", "Échec", "En cours", "Inactif"] { assert!(html.contains(libelle), "badge {libelle} sans texte"); } } #[tokio::test] async fn le_stepper_signale_l_etape_courante() { let html = page().await; let stepper = &html[html.find(r#"id="composant-stepper""#).unwrap()..]; assert_eq!(stepper.matches(r#"aria-current="step""#).count(), 2, "liste mobile + liste desktop"); assert!(stepper.contains("Étape 3 / 5")); }
GitRust