@@ -66,7 +66,7 @@ use crate::{
6666 icons:: { Icon , icon} ,
6767 layout:: {
6868 Crumb , Destination , Health , Label , NavGroup , NavItem , Policies , Preferences , Search ,
69- SearchPage , Searchable , Shell , Shortcut , Spot , Who , page_head, shell,
69+ SearchPage , Searchable , Shell , Shortcut , Spot , Who , alert_notice , page_head, shell,
7070 } ,
7171 settings:: { Tab as SettingsTab , settings_tabs} ,
7272} ;
@@ -443,7 +443,7 @@ pub async fn dashboard_frame<'a>(
443443 // What the change is, and what it acts on, which the dashboard's
444444 // script writes from the link or form that opened the dialog.
445445 <p data-confirming="" data-default =( confirmation. target. map( Target :: text) ) hidden="" ><strong></strong></p>
446- <p class= "notice error" role= "alert" data- passkey-error= "" hidden= "" ></p>
446+ alert_notice ( passkey: true )
447447 <div class="row actions" >
448448 <button type ="button" data-passkey-confirm="" autofocus="" >"Confirm with a passkey" </button>
449449 <button type ="button" class="secondary" popovertarget="passkey-confirmation" popovertargetaction="hide" >"Cancel" </button>
@@ -931,9 +931,7 @@ pub async fn dashboard_change<'a>(
931931 let confirming = change. confirming ( named. as_deref ( ) ) ;
932932 Ok ( view ! {
933933 page_head( title: change. title( ) , lead: change. description( ) . to_owned( ) )
934- if let Some ( refusal) = refusal {
935- <p class="notice error" role="alert" >( refusal) </p>
936- }
934+ alert_notice( message: refusal)
937935 <section class="card" >
938936 <form class="stack" method="post" data-submit-once="" data-unconfirmed=( !change. confirms( ) ) data-confirming=( confirming. as_str( ) ) >
939937 ( child)
@@ -1067,9 +1065,7 @@ pub async fn account_settings<'a>(
10671065 lead: account. and_then( |account| account. id) . map( str :: to_owned) ,
10681066 )
10691067 settings_tabs( tabs: tabs, current: current)
1070- if let Some ( refusal) = refusal {
1071- <p class="notice error" role="alert" >( refusal) </p>
1072- }
1068+ alert_notice( message: refusal)
10731069 ( child)
10741070 } )
10751071}
@@ -1170,9 +1166,7 @@ pub async fn handoff_proof<'a>(
11701166 <h1>"Confirm it's you" </h1>
11711167 <p class="lead" >"The admin dashboard needs your passkey to sign you in or make a change. It counts for the dashboard only." </p>
11721168 </div>
1173- if let Some ( alert) = alert {
1174- <p class="notice error" role="alert" >( alert) </p>
1175- }
1169+ alert_notice( message: alert)
11761170 <form
11771171 class="stack"
11781172 method="post"
@@ -1182,9 +1176,52 @@ pub async fn handoff_proof<'a>(
11821176 <input type ="hidden" name="state" value=( query. state. as_str( ) ) >
11831177 <input type ="hidden" name="return_to" value=( query. return_to. as_str( ) ) >
11841178 <input type ="hidden" name="assertion" value="" >
1185- <p class= "notice error" role= "alert" data- passkey-error= "" hidden= "" ></p>
1179+ alert_notice ( passkey: true )
11861180 <p class="help" data-unavailable="" >"Confirming needs a browser that supports passkeys, with scripts allowed." </p>
11871181 <button disabled="" >"Confirm with a passkey" </button>
11881182 </form>
11891183 } )
11901184}
1185+
1186+ #[ cfg( test) ]
1187+ mod tests {
1188+ use super :: { HandoffQuery , handoff_proof} ;
1189+ use topcoat:: {
1190+ context:: Cx ,
1191+ view:: { ViewExt , view} ,
1192+ } ;
1193+
1194+ /// A refused proof, and the placeholder the passkey script says a failed
1195+ /// ceremony in, are error notices with their warning icon and text.
1196+ #[ tokio:: test]
1197+ async fn the_handoff_says_errors_with_their_icon ( ) {
1198+ let query = HandoffQuery {
1199+ state : "state" . to_owned ( ) ,
1200+ return_to : "/" . to_owned ( ) ,
1201+ } ;
1202+ let cx = Cx :: default ( ) ;
1203+ let page = view ! { cx =>
1204+ handoff_proof( action: "/proof" , proof: "/ceremony" , query: & query, alert: "The passkey was refused." )
1205+ }
1206+ . single ( )
1207+ . await
1208+ . expect ( "the handoff" )
1209+ . render ( & cx) ;
1210+ let notices = page
1211+ . split ( r#"<p class="notice error""# )
1212+ . skip ( 1 )
1213+ . collect :: < Vec < _ > > ( ) ;
1214+ assert_eq ! ( notices. len( ) , 2 , "{page}" ) ;
1215+ for notice in notices
1216+ . into_iter ( )
1217+ . filter_map ( |notice| notice. split ( "</p>" ) . next ( ) )
1218+ {
1219+ assert ! ( notice. contains( r#"<svg class="icon""# ) , "{page}" ) ;
1220+ assert ! ( notice. contains( r#"<span class="text">"# ) , "{page}" ) ;
1221+ }
1222+ assert ! (
1223+ page. contains( r#"<span class="text">The passkey was refused.</span>"# ) ,
1224+ "{page}"
1225+ ) ;
1226+ }
1227+ }
0 commit comments