266 lines
8.2 KiB
Rust
266 lines
8.2 KiB
Rust
//! Project Mycelium UX Test Suite - Main Test Runner
|
|
//!
|
|
//! Complete end-to-end testing framework for validating the entire user experience
|
|
//! as specified in the roadmap Section 9.
|
|
//!
|
|
//! ## Usage:
|
|
//! ```bash
|
|
//! # Run all UX tests
|
|
//! cargo test --test ux_suite_main --features ux_testing
|
|
//!
|
|
//! # Run specific test category
|
|
//! cargo test --test ux_suite_main test_public_access --features ux_testing
|
|
//! cargo test --test ux_suite_main test_authentication --features ux_testing
|
|
//! cargo test --test ux_suite_main test_shopping --features ux_testing
|
|
//! ```
|
|
//!
|
|
//! ## Environment Variables:
|
|
//! - `UX_TEST_MODE`: "dev" (default), "ci", "full"
|
|
//! - `UX_TEST_TIMEOUT`: Timeout in seconds (default: 60)
|
|
//! - `SELENIUM_URL`: WebDriver URL (default: http://localhost:4444)
|
|
|
|
use std::sync::Once;
|
|
|
|
// Import all test modules
|
|
mod ux_suite;
|
|
use ux_suite::*;
|
|
|
|
static INIT_LOGGER: Once = Once::new();
|
|
|
|
/// Initialize logging for tests
|
|
fn init_test_logging() {
|
|
INIT_LOGGER.call_once(|| {
|
|
env_logger::builder()
|
|
.filter_level(log::LevelFilter::Info)
|
|
.format_timestamp(Some(env_logger::fmt::TimestampPrecision::Seconds))
|
|
.try_init()
|
|
.ok();
|
|
|
|
log::info!("Project Mycelium UX Test Suite initialized");
|
|
log::info!("Test mode: {}", std::env::var("UX_TEST_MODE").unwrap_or_else(|_| "dev".to_string()));
|
|
});
|
|
}
|
|
|
|
/// Setup test environment and run a test function
|
|
async fn run_ux_test<F, Fut>(test_name: &str, test_fn: F) -> Result<(), Box<dyn std::error::Error>>
|
|
where
|
|
F: FnOnce() -> Fut,
|
|
Fut: std::future::Future<Output = Result<(), Box<dyn std::error::Error>>>,
|
|
{
|
|
init_test_logging();
|
|
|
|
log::info!("=== Starting UX Test: {} ===", test_name);
|
|
|
|
let start_time = std::time::Instant::now();
|
|
let result = test_fn().await;
|
|
let duration = start_time.elapsed();
|
|
|
|
match &result {
|
|
Ok(_) => {
|
|
log::info!("=== UX Test PASSED: {} ({:.2}s) ===", test_name, duration.as_secs_f64());
|
|
}
|
|
Err(e) => {
|
|
log::error!("=== UX Test FAILED: {} ({:.2}s) - {} ===", test_name, duration.as_secs_f64(), e);
|
|
}
|
|
}
|
|
|
|
result
|
|
}
|
|
|
|
// ===== PUBLIC ACCESS TESTS =====
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_public_information_pages() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Public Information Pages", || async {
|
|
flows::public_access::test_public_information_pages().await
|
|
}).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_anonymous_marketplace_browsing() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Anonymous Marketplace Browsing", || async {
|
|
flows::public_access::test_anonymous_marketplace_browsing().await
|
|
}).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_anonymous_cart_functionality() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Anonymous Cart Functionality", || async {
|
|
flows::public_access::test_anonymous_cart_functionality().await
|
|
}).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_marketplace_search_and_filtering() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Marketplace Search and Filtering", || async {
|
|
flows::public_access::test_marketplace_search_and_filtering().await
|
|
}).await
|
|
}
|
|
|
|
// ===== AUTHENTICATION TESTS =====
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_user_registration_flow() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("User Registration Flow", || async {
|
|
flows::authentication::test_user_registration_flow().await
|
|
}).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_user_login_flow() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("User Login Flow", || async {
|
|
flows::authentication::test_user_login_flow().await
|
|
}).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_cart_migration_during_login() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Cart Migration During Login", || async {
|
|
flows::authentication::test_cart_migration_during_login().await
|
|
}).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_session_management() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Session Management", || async {
|
|
flows::authentication::test_session_management().await
|
|
}).await
|
|
}
|
|
|
|
// ===== SHOPPING WORKFLOW TESTS =====
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_buy_now_complete_workflow() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Buy Now Complete Workflow", || async {
|
|
flows::shopping::test_buy_now_complete_workflow().await
|
|
}).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_add_to_cart_workflow() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Add to Cart Workflow", || async {
|
|
flows::shopping::test_add_to_cart_workflow().await
|
|
}).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_cart_management() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Cart Management", || async {
|
|
flows::shopping::test_cart_management().await
|
|
}).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_complete_checkout_process() -> Result<(), Box<dyn std::error::Error>> {
|
|
run_ux_test("Complete Checkout Process", || async {
|
|
flows::shopping::test_complete_checkout_process().await
|
|
}).await
|
|
}
|
|
|
|
// ===== COMPREHENSIVE TEST SUITES =====
|
|
|
|
/// Run all public access tests
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_suite_public_access() -> Result<(), Box<dyn std::error::Error>> {
|
|
init_test_logging();
|
|
log::info!("Running Public Access Test Suite");
|
|
|
|
test_public_information_pages().await?;
|
|
test_anonymous_marketplace_browsing().await?;
|
|
test_anonymous_cart_functionality().await?;
|
|
test_marketplace_search_and_filtering().await?;
|
|
|
|
log::info!("Public Access Test Suite completed successfully");
|
|
Ok(())
|
|
}
|
|
|
|
/// Run all authentication tests
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_suite_authentication() -> Result<(), Box<dyn std::error::Error>> {
|
|
init_test_logging();
|
|
log::info!("Running Authentication Test Suite");
|
|
|
|
test_user_registration_flow().await?;
|
|
test_user_login_flow().await?;
|
|
test_cart_migration_during_login().await?;
|
|
test_session_management().await?;
|
|
|
|
log::info!("Authentication Test Suite completed successfully");
|
|
Ok(())
|
|
}
|
|
|
|
/// Run all shopping workflow tests
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_suite_shopping() -> Result<(), Box<dyn std::error::Error>> {
|
|
init_test_logging();
|
|
log::info!("Running Shopping Workflow Test Suite");
|
|
|
|
test_buy_now_complete_workflow().await?;
|
|
test_add_to_cart_workflow().await?;
|
|
test_cart_management().await?;
|
|
test_complete_checkout_process().await?;
|
|
|
|
log::info!("Shopping Workflow Test Suite completed successfully");
|
|
Ok(())
|
|
}
|
|
|
|
/// Run all core UX tests (Phase 2 complete)
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_suite_core_ux() -> Result<(), Box<dyn std::error::Error>> {
|
|
init_test_logging();
|
|
log::info!("Running Complete Core UX Test Suite");
|
|
|
|
// Run all test suites sequentially
|
|
test_suite_public_access().await?;
|
|
test_suite_authentication().await?;
|
|
test_suite_shopping().await?;
|
|
|
|
log::info!("Complete Core UX Test Suite completed successfully");
|
|
log::info!("All Phase 2 UX tests passed!");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Performance and load testing
|
|
#[tokio::test]
|
|
#[serial_test::serial]
|
|
async fn test_performance_benchmarks() -> Result<(), Box<dyn std::error::Error>> {
|
|
init_test_logging();
|
|
log::info!("Running Performance Benchmarks");
|
|
|
|
let environment = TestFixtures::setup_test_environment().await?;
|
|
let mut helper = UXTestHelper::new(&environment);
|
|
|
|
// Test page load times
|
|
let pages = vec!["/", "/marketplace", "/docs", "/login"];
|
|
|
|
for page in pages {
|
|
let start = std::time::Instant::now();
|
|
helper.browser.navigate_to(page).await?;
|
|
let load_time = start.elapsed();
|
|
|
|
log::info!("Page {} loaded in {:.2}ms", page, load_time.as_millis());
|
|
|
|
// Assert reasonable load time (5 seconds max)
|
|
assert!(load_time.as_secs() < 5, "Page {} took too long to load: {:.2}s", page, load_time.as_secs_f64());
|
|
}
|
|
|
|
log::info!("Performance benchmarks completed successfully");
|
|
Ok(())
|
|
} |