The signed-in theme e2e test reads the profile corner's pressed theme, now that the topbar has no cycle button for signed-in users
Browse files at this commita8c97c4359bdc497e0a70008cd4f8153d0a46db5Parent: 324720c- test
- the signed-in theme e2e test reads the profile corner's pressed theme, now that the topbar has no cycle button for signed-in users
1 changed file +17 -19
crates/forge-web/tests/e2e/ui_prefs_e2e.rsmodified+17 -19
| @@ -92,6 +92,18 @@ fn theme_button(body: &str) -> (String, String) { | |||
| 92 | (value, label) | 92 | (value, label) |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | +/// The theme the profile corner's three-way choice shows as pressed, for signed-in users. | ||
| 96 | +fn pressed_theme(body: &str) -> Option<String> { | ||
| 97 | + let doc = scraper::Html::parse_document(body); | ||
| 98 | + let selector = | ||
| 99 | + scraper::Selector::parse("form.corner-theme-set button[aria-pressed=\"true\"]") | ||
| 100 | + .expect("selector"); | ||
| 101 | + doc.select(&selector) | ||
| 102 | + .next() | ||
| 103 | + .and_then(|el| el.value().attr("value")) | ||
| 104 | + .map(str::to_owned) | ||
| 105 | +} | ||
| 106 | + | ||
| 95 | /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. | 107 | /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. |
| 96 | fn admin(config: &Path, args: &[&str]) { | 108 | fn admin(config: &Path, args: &[&str]) { |
| 97 | let out = Command::new(BIN) | 109 | let out = Command::new(BIN) |
| @@ -627,14 +639,11 @@ async fn theme_button_cycles_light_dark_auto_light_for_signed_in_users() { | |||
| 627 | let session = login(&env.http, "tahinli", PW).await; | 639 | let session = login(&env.http, "tahinli", PW).await; |
| 628 | let back = "/settings/appearance"; | 640 | let back = "/settings/appearance"; |
| 629 | 641 | ||
| 630 | - // A new user starts on light, the default, so the button offers dark next. | 642 | + // A new user starts on light, the default. |
| 631 | let page = env.http.get(back, Some(&session)).await; | 643 | let page = env.http.get(back, Some(&session)).await; |
| 632 | let csrf = input_value(&page.body, "csrf"); | 644 | let csrf = input_value(&page.body, "csrf"); |
| 633 | assert_eq!(html_theme(&page.body).as_deref(), Some("light")); | 645 | assert_eq!(html_theme(&page.body).as_deref(), Some("light")); |
| 634 | - assert_eq!( | 646 | + assert_eq!(pressed_theme(&page.body).as_deref(), Some("light")); |
| 635 | - theme_button(&page.body), | ||
| 636 | - ("dark".into(), "Theme: Light. Switch to Dark".into()) | ||
| 637 | - ); | ||
| 638 | 647 | ||
| 639 | let step = env | 648 | let step = env |
| 640 | .http | 649 | .http |
| @@ -647,13 +656,7 @@ async fn theme_button_cycles_light_dark_auto_light_for_signed_in_users() { | |||
| 647 | assert_eq!(step.status, 303, "light to dark: {}", step.body); | 656 | assert_eq!(step.status, 303, "light to dark: {}", step.body); |
| 648 | let page = env.http.get(back, Some(&session)).await; | 657 | let page = env.http.get(back, Some(&session)).await; |
| 649 | assert_eq!(html_theme(&page.body).as_deref(), Some("dark")); | 658 | assert_eq!(html_theme(&page.body).as_deref(), Some("dark")); |
| 650 | - assert_eq!( | 659 | + assert_eq!(pressed_theme(&page.body).as_deref(), Some("dark")); |
| 651 | - theme_button(&page.body), | ||
| 652 | - ( | ||
| 653 | - "auto".into(), | ||
| 654 | - "Theme: Dark. Switch to match the system".into() | ||
| 655 | - ) | ||
| 656 | - ); | ||
| 657 | 660 | ||
| 658 | let step = env | 661 | let step = env |
| 659 | .http | 662 | .http |
| @@ -671,13 +674,7 @@ async fn theme_button_cycles_light_dark_auto_light_for_signed_in_users() { | |||
| 671 | "signed-in toggle to auto stores 'auto'" | 674 | "signed-in toggle to auto stores 'auto'" |
| 672 | ); | 675 | ); |
| 673 | assert_eq!(html_theme(&page.body), None, "auto renders no data-theme"); | 676 | assert_eq!(html_theme(&page.body), None, "auto renders no data-theme"); |
| 674 | - assert_eq!( | 677 | + assert_eq!(pressed_theme(&page.body).as_deref(), Some("auto")); |
| 675 | - theme_button(&page.body), | ||
| 676 | - ( | ||
| 677 | - "light".into(), | ||
| 678 | - "Theme: Match the system. Switch to Light".into() | ||
| 679 | - ) | ||
| 680 | - ); | ||
| 681 | 678 | ||
| 682 | let step = env | 679 | let step = env |
| 683 | .http | 680 | .http |
| @@ -690,6 +687,7 @@ async fn theme_button_cycles_light_dark_auto_light_for_signed_in_users() { | |||
| 690 | assert_eq!(step.status, 303, "auto to light: {}", step.body); | 687 | assert_eq!(step.status, 303, "auto to light: {}", step.body); |
| 691 | let page = env.http.get(back, Some(&session)).await; | 688 | let page = env.http.get(back, Some(&session)).await; |
| 692 | assert_eq!(html_theme(&page.body).as_deref(), Some("light")); | 689 | assert_eq!(html_theme(&page.body).as_deref(), Some("light")); |
| 690 | + assert_eq!(pressed_theme(&page.body).as_deref(), Some("light")); | ||
| 693 | } | 691 | } |
| 694 | 692 | ||
| 695 | #[tokio::test] | 693 | #[tokio::test] |