pinakes-plugin-api: add integration and sample plugin tests
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I0de4c3e1e5b49579ae42983f93a2332e6a6a6964
This commit is contained in:
parent
5a0901ba95
commit
7a6d602eed
2 changed files with 422 additions and 0 deletions
61
crates/pinakes-plugin-api/tests/example_plugin.rs
Normal file
61
crates/pinakes-plugin-api/tests/example_plugin.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
//! 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"
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue