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 @@ -1283,6 +1283,48 @@ mod tests {
12831283 } ) ;
12841284 }
12851285
1286+ // Ensure that if there are more than a given number of targets, it will not generate them in
1287+ // the HTML directly (they will be loaded by AJAX if the user opens the menu).
1288+ #[ test]
1289+ #[ allow( clippy:: assertions_on_constants) ]
1290+ fn platform_menu_ajax ( ) {
1291+ assert ! ( crate :: DEFAULT_MAX_TARGETS > 2 ) ;
1292+
1293+ fn check_count ( nb_targets : usize , expected : usize ) {
1294+ wrapper ( |env| {
1295+ let mut rel = env
1296+ . fake_release ( )
1297+ . name ( "dummy" )
1298+ . version ( "0.4.0" )
1299+ . rustdoc_file ( "dummy/index.html" )
1300+ . rustdoc_file ( "x86_64-pc-windows-msvc/dummy/index.html" )
1301+ . default_target ( "x86_64-unknown-linux-gnu" ) ;
1302+
1303+ for nb in 0 ..nb_targets - 1 {
1304+ rel = rel. add_target ( & format ! ( "x86_64-pc-windows-msvc{nb}" ) ) ;
1305+ }
1306+ rel. create ( ) ?;
1307+
1308+ let response = env. frontend ( ) . get ( "/crate/dummy/0.4.0" ) . send ( ) ?;
1309+ assert ! ( response. status( ) . is_success( ) ) ;
1310+
1311+ let nb_li = kuchikiki:: parse_html ( )
1312+ . one ( response. text ( ) ?)
1313+ . select ( r#"#platforms li a"# )
1314+ . expect ( "invalid selector" )
1315+ . count ( ) ;
1316+ assert_eq ! ( nb_li, expected) ;
1317+ Ok ( ( ) )
1318+ } ) ;
1319+ }
1320+
1321+ // First we check that with 2 releases, the platforms list should be in the HTML.
1322+ check_count ( 2 , 2 ) ;
1323+ // Then we check the same thing but with number of targets equal
1324+ // to `DEFAULT_MAX_TARGETS`.
1325+ check_count ( crate :: DEFAULT_MAX_TARGETS , 0 ) ;
1326+ }
1327+
12861328 #[ test]
12871329 fn latest_url ( ) {
12881330 wrapper ( |env| {
You can’t perform that action at this time.
0 commit comments