use fantoccini::{Client, Locator}; use perseus::wait_for_checkpoint; // This is is an E2E test with the following steps: // - Go to the index page // - Navigate to all transactions // - Try all page sizes and verify that they are respected // - Try to go to page 2 // - Use the async select component to find any company // - Click on this company and verify that we arrived // - Come back to the root using the top left link // - Find the first link in the table and click on it // - Verify that all the company names in the table of the new page are the same as the link we // clicked before // Run like this: // - Run any headless browser drive like geckodriver // - Run perseus test // - The backend should be available with at least 11 saved transactions #[perseus::test] async fn index(c: &mut Client) -> Result<(), fantoccini::error::CmdError> { c.goto("http://localhost:8080").await?; wait_for_checkpoint!("begin", 0, c); let url = c.current_url().await?; assert!(url.as_ref().starts_with("http://localhost:8080")); wait_for_checkpoint!("page_interactive", 0, c); // Verify the page title let title = c.find(Locator::Css("title")).await?.html(false).await?; assert!(title.contains("Fast Insiders")); let all_transactions_link = c.find(Locator::Css("#header-all-transactions")).await?; all_transactions_link.click().await?; let url = c.current_url().await?; assert!(url .as_ref() .starts_with("http://localhost:8080/transactions")); wait_for_checkpoint!("page_interactive", 1, c); // Verify that the default table size is 20 let page_size_select = c.find(Locator::Css("#size-select")).await?; let default_page_size = page_size_select .prop("value") .await? .expect("The value prop must be set"); assert_eq!(default_page_size.parse::().unwrap(), 20); // Test all page sizes let page_sizes = [20, 30, 40, 50, 10].iter(); for page_size in page_sizes { let page_size_select = c.find(Locator::Css("#size-select")).await?; page_size_select .select_by_value(&page_size.to_string()) .await?; let table_rows = c.find_all(Locator::Css("table tr")).await?.iter().count(); let page_size_select = c.find(Locator::Css("#size-select")).await?; let browser_page_size = page_size_select .prop("value") .await? .expect("The value prop must be set"); assert_eq!(browser_page_size.parse::().unwrap(), *page_size); assert_eq!(table_rows, page_size + 1); // The header also counts as a table row } // Verify that we can change pages let page_buttons = c.find_all(Locator::Css("#page_buttons button")).await?; assert_eq!(page_buttons[0].text().await?, "<<"); assert_eq!(page_buttons[1].text().await?, ">>"); let page_numbers = c .find(Locator::Css("#page_buttons div")) .await? .text() .await? .split("/") .map(|x| x.parse().unwrap()) .collect::>(); assert_eq!(page_numbers[0], 1); page_buttons[1].click().await?; let new_page_numbers = c .find(Locator::Css("#page_buttons div")) .await? .text() .await? .split("/") .map(|x| x.parse().unwrap()) .collect::>(); assert_eq!(new_page_numbers[0], page_numbers[0] + 1); // let table = c.find(Locator::Css("table")).await?.html(true).await?; let filter_button = c.find(Locator::Css("#main button")).await?; filter_button.click().await?; let company_select = c.find(Locator::Css("#filters input")).await?; company_select.send_keys("E").await?; // E is one of the most used letter. wait_for_checkpoint!("async_select_item_change", 0, c); let first_company = c.find(Locator::Css("div.relative li")).await?; let clicked_company = first_company.text().await?; first_company.click().await?; let search_button = c.find(Locator::Css("#filters button")).await?; search_button.click().await?; let page = c.current_url().await?; assert!( page.as_ref() .starts_with("http://localhost:8080/transactions"), "Unexpected target url reached: {}", page ); wait_for_checkpoint!("page_interactive", 2, c); for a in c.find_all(Locator::Css("table a")).await? { let a_text = a.text().await?; assert_eq!(clicked_company, a_text, "The clicked company is different from the target page list of companies, respectively {} and {}", clicked_company, a_text); } let transactions_link = c.find(Locator::Css("a h1")).await?; transactions_link.click().await?; let first_company_in_table = c.find(Locator::Css("table a")).await?; let company_name = first_company_in_table.text().await?; first_company_in_table.click().await?; for a in c.find_all(Locator::Css("table a")).await? { let a_text = a.text().await?; assert_eq!(company_name, a_text, "The clicked company is different from the target page list of companies, respectively {} and {}", company_name, a_text); } assert!( page.as_ref() .starts_with("http://localhost:8080/transactions"), "Unexpected target url reached: {}", page ); Ok(()) }