viewpoint_test/config/
mod.rs

1//! Test configuration.
2
3use std::time::Duration;
4
5/// Configuration for test execution.
6#[derive(Debug, Clone)]
7pub struct TestConfig {
8    /// Whether to run the browser in headless mode.
9    pub headless: bool,
10    /// Default timeout for operations.
11    pub timeout: Duration,
12}
13
14impl Default for TestConfig {
15    fn default() -> Self {
16        Self {
17            headless: true,
18            timeout: Duration::from_secs(30),
19        }
20    }
21}
22
23impl TestConfig {
24    /// Create a new test configuration with default values.
25    pub fn new() -> Self {
26        Self::default()
27    }
28
29    /// Create a builder for custom configuration.
30    pub fn builder() -> TestConfigBuilder {
31        TestConfigBuilder::default()
32    }
33}
34
35/// Builder for `TestConfig`.
36#[derive(Debug, Default)]
37pub struct TestConfigBuilder {
38    headless: Option<bool>,
39    timeout: Option<Duration>,
40}
41
42impl TestConfigBuilder {
43    /// Set whether to run in headless mode.
44    #[must_use]
45    pub fn headless(mut self, headless: bool) -> Self {
46        self.headless = Some(headless);
47        self
48    }
49
50    /// Set the default timeout.
51    #[must_use]
52    pub fn timeout(mut self, timeout: Duration) -> Self {
53        self.timeout = Some(timeout);
54        self
55    }
56
57    /// Build the configuration.
58    pub fn build(self) -> TestConfig {
59        TestConfig {
60            headless: self.headless.unwrap_or(true),
61            timeout: self.timeout.unwrap_or(Duration::from_secs(30)),
62        }
63    }
64}