Skip to content

Commit

Permalink
fix: inconsistent page state
Browse files Browse the repository at this point in the history
This change fixes two issues with the page state:

* the defaults/initial terms are not applied properly
* the page state sometimes isn't serialized/stored
  • Loading branch information
ctron committed Oct 11, 2023
1 parent c5ab77b commit 3a466c4
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 284 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"analytics",
"api",
Expand Down
113 changes: 103 additions & 10 deletions integration-tests/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,31 @@ use std::time::Duration;
use tempfile::NamedTempFile;
use test_context::test_context;
use thirtyfour::prelude::{ElementQueryable, ElementWaitable};
use thirtyfour::By;
use thirtyfour::{By, WebDriver, WebElement};

async fn click_nav_link(driver: &WebDriver, label: impl Into<String>) {
let nav = driver
.query(By::Css(".pf-v5-c-nav__link"))
.with_text(label.into())
.first()
.await
.unwrap();
nav.wait_until().clickable().await.unwrap();
nav.click().await.unwrap();
}

async fn find_radio_input(driver: &WebDriver, label: impl Into<String>) -> WebElement {
let label = driver
.query(By::Css(".pf-v5-c-radio__label"))
.with_text(label.into())
.first()
.await
.unwrap();

label.wait_until().displayed().await.unwrap();
let radio = label.parent().await.unwrap();
radio.query(By::Tag("input")).first().await.unwrap()
}

#[cfg_attr(not(feature = "ui"), ignore = "UI tests are not enabled")]
#[test_with::env(CRDA_URL)]
Expand All @@ -15,15 +39,7 @@ async fn issue_tc_587(context: &mut SpogUiContext) {
let driver = &context.driver;

// go to the "scan SBOM" page

let nav = driver
.query(By::Css(".pf-v5-c-nav__link"))
.with_text("Scan SBOM")
.first()
.await
.unwrap();
nav.wait_until().clickable().await.unwrap();
nav.click().await.unwrap();
click_nav_link(driver, "Scan SBOM").await;

// wait for the page to load

Expand Down Expand Up @@ -98,3 +114,80 @@ async fn issue_tc_587(context: &mut SpogUiContext) {
assert!(!btn_scan.first().await.unwrap().is_clickable().await.unwrap());
assert!(btn_clear.first().await.unwrap().is_clickable().await.unwrap());
}

#[cfg_attr(not(feature = "ui"), ignore = "UI tests are not enabled")]
#[test_context(SpogUiContext)]
#[tokio::test]
#[ntest::timeout(60_000)]
async fn ensure_default_values(context: &mut SpogUiContext) {
let driver = &context.driver;

// trigger the search, with no input

let button = driver.query(By::Id("search")).first().await.unwrap();
button.wait_until().clickable().await.unwrap();
button.click().await.unwrap();

// find the "any time" option, ensure it's selected

let any_time = find_radio_input(driver, "Any time").await;

assert_eq!(any_time.value().await.unwrap().unwrap(), "on");
}

#[cfg_attr(not(feature = "ui"), ignore = "UI tests are not enabled")]
#[test_context(SpogUiContext)]
#[tokio::test]
#[ntest::timeout(60_000)]
async fn ensure_page_state(context: &mut SpogUiContext) {
let driver = &context.driver;

// trigger the search, with no input

let terms = driver
.query(By::Id("search_terms"))
.first()
.await
.unwrap()
.query(By::Tag("input"))
.first()
.await
.unwrap();
terms.wait_until().displayed().await.unwrap();
terms.send_keys("foo").await.unwrap();

let button = driver.query(By::Id("search")).first().await.unwrap();
button.wait_until().clickable().await.unwrap();
button.click().await.unwrap();

// find the "This year" option, select it

let this_year = find_radio_input(driver, "This year").await;
this_year.click().await.unwrap();

assert_eq!(this_year.value().await.unwrap().unwrap(), "on");

// navigate away

click_nav_link(driver, "Home").await;

// wait for the page to load

assert_eq!(driver.current_url().await.unwrap().path(), "/");

// press back button

driver.back().await.unwrap();

// ensure the page is loaded

assert_eq!(driver.current_url().await.unwrap().path(), "/search/foo");

// fetch element again

let this_year = find_radio_input(driver, "This year").await;

// ensure it's still "on"

assert_eq!(this_year.value().await.unwrap().unwrap(), "on");
}

0 comments on commit 3a466c4

Please sign in to comment.