//! Integration tests that parse and validate the media-stats-ui example. use pinakes_plugin_api::{PluginManifest, UiPage}; /// Resolve a path relative to the workspace root. fn workspace_path(rel: &str) -> std::path::PathBuf { // tests run from the crate root (crates/pinakes-plugin-api) std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("../..") .join(rel) } #[test] fn example_plugin_manifest_parses() { let path = workspace_path("examples/plugins/media-stats-ui/plugin.toml"); // load_ui_pages needs the manifest validated, but the file-based pages // just need the paths to exist; we test them separately below. let content = std::fs::read_to_string(&path).expect("read plugin.toml"); // parse_str validates the manifest; it returns Err for any violation let manifest = PluginManifest::parse_str(&content) .expect("plugin.toml should parse and validate"); assert_eq!(manifest.plugin.name, "media-stats-ui"); assert_eq!( manifest.ui.pages.len(), 2, "expected 2 page file references" ); assert_eq!(manifest.ui.widgets.len(), 1, "expected 1 widget"); } #[test] fn example_stats_page_parses_and_validates() { let path = workspace_path("examples/plugins/media-stats-ui/pages/stats.json"); let content = std::fs::read_to_string(&path).expect("read stats.json"); let page: UiPage = serde_json::from_str(&content).expect("stats.json should deserialise"); assert_eq!(page.id, "stats"); page.validate().expect("stats page should pass validation"); } #[test] fn example_tag_manager_page_parses_and_validates() { let path = workspace_path("examples/plugins/media-stats-ui/pages/tag-manager.json"); let content = std::fs::read_to_string(&path).expect("read tag-manager.json"); let page: UiPage = serde_json::from_str(&content) .expect("tag-manager.json should deserialise"); assert_eq!(page.id, "tag-manager"); page .validate() .expect("tag-manager page should pass validation"); // Verify the named action and data source are both present assert!( page.actions.contains_key("create-tag"), "create-tag action should be defined" ); assert!( page.data_sources.contains_key("tags"), "tags data source should be defined" ); }