use super::*;
#[test]
fn test_no_duplicate_field_names() {
let mut seen = std::collections::HashSet::new();
for field in BUILTIN_FIELDS {
assert!(
seen.insert(field.name),
"duplicate field name '{}' in BUILTIN_FIELDS",
field.name
);
}
}
#[test]
fn test_array_fields_have_items_type() {
for field in BUILTIN_FIELDS {
if field.field_type == FieldType::Array {
assert!(
field.items_type.is_some(),
"array field '{}' must have items_type set",
field.name
);
}
}
}
#[test]
fn test_labels_propagate_to_schema() {
let schema = crate::schema::builtin_schema();
let depth = schema
.frontmatter
.fields
.get("children_depth")
.expect("children_depth");
assert_eq!(depth.label.as_deref(), Some("Depth"));
}
#[test]
fn test_no_label_means_none() {
let schema = crate::schema::builtin_schema();
let title = schema.frontmatter.fields.get("title").expect("title");
assert!(title.label.is_none());
}
#[test]
fn test_select_fields_have_enum_values() {
for field in BUILTIN_FIELDS {
if field.widget == Widget::Select && !field.skip_schema {
assert!(
field.enum_values.is_some(),
"select widget field '{}' should have enum_values",
field.name
);
}
}
}
#[test]
fn test_all_non_skip_fields_have_a_group() {
for field in BUILTIN_FIELDS {
if !field.skip_schema {
assert!(
!field.group.is_empty(),
"field '{}' has skip_schema=false but no group",
field.name
);
}
}
}
#[test]
fn test_groups_are_valid_scope_groups() {
const VALID: &[&str] = &["This Page", "Child Pages", "Child Styles", "Whole Site"];
for field in BUILTIN_FIELDS {
if !field.skip_schema {
assert!(
VALID.contains(&field.group),
"field '{}' has unexpected group '{}'; expected one of {:?}",
field.name,
field.group,
VALID
);
}
}
}
#[test]
fn test_score_in_valid_range() {
for field in BUILTIN_FIELDS {
if !field.skip_schema {
assert!(
field.score > 0,
"non-skip field '{}' has score=0; set a score >= 1",
field.name
);
}
}
}
const INTENTIONALLY_SKIP_SCHEMA: &[&str] = &[
"home",
"analytics",
"uid",
"cover_type",
"children_source",
"_from_sidebar_alias",
];
#[test]
fn test_skip_schema_fields_are_on_the_allowlist() {
for field in BUILTIN_FIELDS {
if field.skip_schema {
assert!(
INTENTIONALLY_SKIP_SCHEMA.contains(&field.name),
"field '{}' is skip_schema=true but not in INTENTIONALLY_SKIP_SCHEMA — \
if it's a real per-page/site control (has enum_values, a widget, a \
user-facing description) it should be skip_schema=false with a group \
instead; if it's genuinely internal, add its name to the allowlist",
field.name
);
}
}
}
#[test]
fn every_file_picker_field_declares_file_kinds() {
for f in BUILTIN_FIELDS {
if matches!(f.widget, Widget::FilePicker) {
assert!(
f.file_kinds.is_some(),
"FilePicker field `{}` declares no file_kinds",
f.name
);
}
}
}
#[test]
fn asset_field_names_is_exactly_cover_and_logo() {
let names: Vec<&str> = asset_field_names().collect();
assert_eq!(names, vec!["cover", "logo"]);
}