Add product-area presentation to Views
This commit is contained in:
@@ -26,7 +26,7 @@ class ViewsMigrationTests(unittest.TestCase):
|
||||
try:
|
||||
with engine.connect() as connection:
|
||||
self.assertIn(
|
||||
"b8e4c1f7a2d9",
|
||||
"c6f2a9d4e7b1",
|
||||
set(MigrationContext.configure(connection).get_current_heads()),
|
||||
)
|
||||
self.assertEqual(
|
||||
@@ -42,6 +42,15 @@ class ViewsMigrationTests(unittest.TestCase):
|
||||
if name.startswith("view_")
|
||||
},
|
||||
)
|
||||
self.assertIn(
|
||||
"presentation",
|
||||
{
|
||||
column["name"]
|
||||
for column in inspect(connection).get_columns(
|
||||
"view_revisions"
|
||||
)
|
||||
},
|
||||
)
|
||||
finally:
|
||||
engine.dispose()
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ from govoplan_views.backend.service import (
|
||||
create_revision,
|
||||
get_revision,
|
||||
list_definitions,
|
||||
normalize_view_presentation,
|
||||
normalize_visible_surface_ids,
|
||||
publish_revision,
|
||||
resolve_effective_view,
|
||||
@@ -193,6 +194,70 @@ class ViewsServiceTests(unittest.TestCase):
|
||||
self.session.close()
|
||||
self.engine.dispose()
|
||||
|
||||
def test_view_presentation_is_normalized_and_versioned(self) -> None:
|
||||
definition = create_definition(
|
||||
self.session,
|
||||
tenant_id="tenant-1",
|
||||
scope_type="tenant",
|
||||
scope_id=None,
|
||||
definition_key=None,
|
||||
name="Product navigation",
|
||||
description=None,
|
||||
visible_surface_ids=ordinary_surface_ids(),
|
||||
catalogue=self.catalogue,
|
||||
actor_id="account-admin",
|
||||
presentation={
|
||||
"navigation_mode": "grouped",
|
||||
"product_area_order": ["work", "records-documents"],
|
||||
"product_area_labels": {"work": "My work"},
|
||||
},
|
||||
available_product_area_ids=("work", "records-documents"),
|
||||
)
|
||||
revision = get_revision(self.session, definition_id=definition.id)
|
||||
self.assertEqual("grouped", revision.presentation["navigation_mode"])
|
||||
compatible_revision = create_revision(
|
||||
self.session,
|
||||
definition,
|
||||
visible_surface_ids=lockout_safe_surface_ids(),
|
||||
catalogue=self.catalogue,
|
||||
actor_id="legacy-client",
|
||||
available_product_area_ids=("work", "records-documents"),
|
||||
)
|
||||
self.assertEqual(
|
||||
revision.presentation,
|
||||
compatible_revision.presentation,
|
||||
"omitting presentation must preserve the previous revision contract",
|
||||
)
|
||||
revision = compatible_revision
|
||||
publish_revision(
|
||||
self.session,
|
||||
definition,
|
||||
revision,
|
||||
catalogue=self.catalogue,
|
||||
actor_id="account-admin",
|
||||
)
|
||||
self.assign(
|
||||
definition,
|
||||
scope_type="tenant",
|
||||
scope_id=None,
|
||||
)
|
||||
state = resolve_effective_view(
|
||||
self.session,
|
||||
tenant_id="tenant-1",
|
||||
account_id="account-1",
|
||||
catalogue=self.catalogue,
|
||||
)
|
||||
self.assertEqual("My work", state.effective.presentation["product_area_labels"]["work"])
|
||||
|
||||
def test_view_presentation_rejects_unknown_or_unavailable_fields(self) -> None:
|
||||
with self.assertRaises(ViewsValidationError):
|
||||
normalize_view_presentation({"unknown": True})
|
||||
with self.assertRaises(ViewsValidationError):
|
||||
normalize_view_presentation(
|
||||
{"product_area_order": ["unavailable"]},
|
||||
available_product_area_ids=("work",),
|
||||
)
|
||||
|
||||
def create_published_definition(
|
||||
self,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user