File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -1274,6 +1274,48 @@ mod tests {
12741274 } ) ;
12751275 }
12761276
1277+ // Ensure that if there are more than a given number of targets, it will not generate them in
1278+ // the HTML directly (they will be loaded by AJAX if the user opens the menu).
1279+ #[ test]
1280+ #[ allow( clippy:: assertions_on_constants) ]
1281+ fn platform_menu_ajax ( ) {
1282+ assert ! ( crate :: DEFAULT_MAX_TARGETS > 2 ) ;
1283+
1284+ fn check_count ( nb_targets : usize , expected : usize ) {
1285+ wrapper ( |env| {
1286+ let mut rel = env
1287+ . fake_release ( )
1288+ . name ( "dummy" )
1289+ . version ( "0.4.0" )
1290+ . rustdoc_file ( "dummy/index.html" )
1291+ . rustdoc_file ( "x86_64-pc-windows-msvc/dummy/index.html" )
1292+ . default_target ( "x86_64-unknown-linux-gnu" ) ;
1293+
1294+ for nb in 0 ..nb_targets - 1 {
1295+ rel = rel. add_target ( & format ! ( "x86_64-pc-windows-msvc{nb}" ) ) ;
1296+ }
1297+ rel. create ( ) ?;
1298+
1299+ let response = env. frontend ( ) . get ( "/crate/dummy/0.4.0" ) . send ( ) ?;
1300+ assert ! ( response. status( ) . is_success( ) ) ;
1301+
1302+ let nb_li = kuchikiki:: parse_html ( )
1303+ . one ( response. text ( ) ?)
1304+ . select ( r#"#platforms li a"# )
1305+ . expect ( "invalid selector" )
1306+ . count ( ) ;
1307+ assert_eq ! ( nb_li, expected) ;
1308+ Ok ( ( ) )
1309+ } ) ;
1310+ }
1311+
1312+ // First we check that with 2 releases, the platforms list should be in the HTML.
1313+ check_count ( 2 , 2 ) ;
1314+ // Then we check the same thing but with number of targets equal
1315+ // to `DEFAULT_MAX_TARGETS`.
1316+ check_count ( crate :: DEFAULT_MAX_TARGETS , 0 ) ;
1317+ }
1318+
12771319 #[ test]
12781320 fn latest_url ( ) {
12791321 wrapper ( |env| {
You can’t perform that action at this time.
0 commit comments