Files
k-frame/crates/domain/tests/data_source_tests.rs
Gabriel Kaszewski a51d22649a internal data sources (clock, static text), connection indicator, rendering fixes
DataSourceConfig refactored to enum: External/Clock/StaticText. Clock
generates formatted time via chrono, static text emits configured string.

ESP32: connection status indicator (green/red dot bottom-right), per-widget
clear before redraw, RenderEvent enum for local + server messages.

Polling uses DataUpdate instead of ScreenUpdate to avoid wiping widget state.
Empty mappings passthrough raw source data for internal sources.
2026-06-19 11:26:49 +02:00

60 lines
1.7 KiB
Rust

use domain::{DataSource, DataSourceConfig, DataSourceType, DataSourceValidationError};
use std::time::Duration;
fn make_source(source_type: DataSourceType, url: Option<&str>, poll: Duration) -> DataSource {
DataSource {
id: 1,
name: "test".into(),
source_type,
poll_interval: poll,
config: DataSourceConfig::External {
url: url.map(Into::into),
headers: vec![],
api_key: None,
},
}
}
#[test]
fn http_json_requires_url() {
let source = make_source(DataSourceType::HttpJson, None, Duration::from_secs(60));
let errors = source.validate();
assert!(errors.contains(&DataSourceValidationError::UrlRequired));
}
#[test]
fn webhook_does_not_allow_poll_interval() {
let source = make_source(DataSourceType::Webhook, None, Duration::from_secs(60));
let errors = source.validate();
assert!(errors.contains(&DataSourceValidationError::PollIntervalNotAllowed));
}
#[test]
fn webhook_with_zero_interval_is_valid() {
let source = make_source(DataSourceType::Webhook, None, Duration::ZERO);
let errors = source.validate();
assert!(errors.is_empty());
}
#[test]
fn poll_based_source_requires_nonzero_interval() {
let source = make_source(
DataSourceType::Weather,
Some("https://api.weather.com"),
Duration::ZERO,
);
let errors = source.validate();
assert!(errors.contains(&DataSourceValidationError::PollIntervalRequired));
}
#[test]
fn valid_poll_source_has_no_errors() {
let source = make_source(
DataSourceType::Rss,
Some("https://feed.example.com"),
Duration::from_secs(300),
);
let errors = source.validate();
assert!(errors.is_empty());
}