viewpoint_test/expect/
soft_page.rs

1//! Soft page assertion methods.
2//!
3//! This module contains all the assertion methods for `SoftPageAssertions`.
4
5use std::sync::{Arc, Mutex};
6
7use super::page::PageAssertions;
8use super::soft::SoftAssertionError;
9
10/// Soft assertions for pages.
11///
12/// These assertions collect failures instead of failing immediately.
13pub struct SoftPageAssertions<'a> {
14    pub(super) assertions: PageAssertions<'a>,
15    pub(super) errors: Arc<Mutex<Vec<SoftAssertionError>>>,
16}
17
18impl SoftPageAssertions<'_> {
19    /// Assert page URL (soft).
20    pub async fn to_have_url(&self, expected: impl AsRef<str>) {
21        let expected_str = expected.as_ref().to_string();
22        match self.assertions.to_have_url(&expected_str).await {
23            Ok(()) => {}
24            Err(e) => {
25                self.errors.lock().unwrap().push(
26                    SoftAssertionError::new("to_have_url", e.to_string())
27                        .with_expected(&expected_str)
28                );
29            }
30        }
31    }
32
33    /// Assert page title (soft).
34    pub async fn to_have_title(&self, expected: impl AsRef<str>) {
35        let expected_str = expected.as_ref().to_string();
36        match self.assertions.to_have_title(&expected_str).await {
37            Ok(()) => {}
38            Err(e) => {
39                self.errors.lock().unwrap().push(
40                    SoftAssertionError::new("to_have_title", e.to_string())
41                        .with_expected(&expected_str)
42                );
43            }
44        }
45    }
46}