Tab the PC detail page and add panel groups to the ADR-010 contract
This commit is contained in:
@@ -142,3 +142,86 @@ def test_asset_presentation_skip_disabled_plugin(app, client, auth_headers, monk
|
||||
|
||||
entries = _data(client, '/api/pluginui/asset-presentation', auth_headers)
|
||||
assert 'measuring_tool' not in {e.get('assettype') for e in entries}
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# asset-panel groups (which detail-page tab a panel lands in)
|
||||
# =============================================================================
|
||||
|
||||
def test_every_panel_comes_back_with_a_group(app, client, db, auth_headers,
|
||||
monkeypatch):
|
||||
"""The client filters by group, so a panel without one must not vanish.
|
||||
|
||||
Resolution happens on the server precisely so a plugin written before tabs
|
||||
existed still lands somewhere a person can see.
|
||||
"""
|
||||
from shopdb.core.api.pluginui import ASSET_PANEL_GROUPS
|
||||
pm = app.extensions['plugin_manager']
|
||||
monkeypatch.setattr(pm.registry, 'is_enabled', lambda name: True)
|
||||
assetid = _make_asset(db)
|
||||
|
||||
panels = _data(client, '/api/pluginui/asset-panels?assetid=%d' % assetid,
|
||||
auth_headers)
|
||||
assert panels, 'no panels matched, so this test proves nothing'
|
||||
for panel in panels:
|
||||
assert panel.get('group') in ASSET_PANEL_GROUPS, panel.get('id')
|
||||
|
||||
|
||||
def test_an_undeclared_group_defaults_to_details(app, client, db, auth_headers,
|
||||
monkeypatch):
|
||||
"""Omitting group is the documented answer for most panels."""
|
||||
pm = app.extensions['plugin_manager']
|
||||
monkeypatch.setattr(pm.registry, 'is_enabled', lambda name: True)
|
||||
plugin = next(iter(pm.get_all_plugins().values()))
|
||||
monkeypatch.setattr(plugin, 'get_asset_panels', lambda: [{
|
||||
'id': 'nogroup', 'title': 'No group', 'assettypes': ['*'],
|
||||
'endpoint': '/api/whatever', 'render': 'keyvalue', 'position': 1,
|
||||
}])
|
||||
assetid = _make_asset(db)
|
||||
|
||||
panels = _data(client, '/api/pluginui/asset-panels?assetid=%d' % assetid,
|
||||
auth_headers)
|
||||
panel = next(p for p in panels if p['id'] == 'nogroup')
|
||||
assert panel['group'] == 'details'
|
||||
|
||||
|
||||
def test_a_group_nobody_defined_falls_back_rather_than_disappearing(
|
||||
app, client, db, auth_headers, monkeypatch):
|
||||
"""A typo must not drop the panel off every tab.
|
||||
|
||||
The page renders known groups only, so an unrecognised value that survived
|
||||
to the client would be a panel that exists and is never shown anywhere.
|
||||
"""
|
||||
pm = app.extensions['plugin_manager']
|
||||
monkeypatch.setattr(pm.registry, 'is_enabled', lambda name: True)
|
||||
plugin = next(iter(pm.get_all_plugins().values()))
|
||||
monkeypatch.setattr(plugin, 'get_asset_panels', lambda: [{
|
||||
'id': 'typo', 'title': 'Typo', 'assettypes': ['*'],
|
||||
'endpoint': '/api/whatever', 'render': 'keyvalue', 'position': 1,
|
||||
'group': 'metrcis',
|
||||
}])
|
||||
assetid = _make_asset(db)
|
||||
|
||||
panels = _data(client, '/api/pluginui/asset-panels?assetid=%d' % assetid,
|
||||
auth_headers)
|
||||
panel = next(p for p in panels if p['id'] == 'typo')
|
||||
assert panel['group'] == 'details'
|
||||
|
||||
|
||||
def test_group_matching_is_not_case_or_space_sensitive(app, client, db,
|
||||
auth_headers, monkeypatch):
|
||||
"""'Metrics ' is obviously meant to be metrics; do not send it to details."""
|
||||
pm = app.extensions['plugin_manager']
|
||||
monkeypatch.setattr(pm.registry, 'is_enabled', lambda name: True)
|
||||
plugin = next(iter(pm.get_all_plugins().values()))
|
||||
monkeypatch.setattr(plugin, 'get_asset_panels', lambda: [{
|
||||
'id': 'shouty', 'title': 'Shouty', 'assettypes': ['*'],
|
||||
'endpoint': '/api/whatever', 'render': 'keyvalue', 'position': 1,
|
||||
'group': ' Metrics ',
|
||||
}])
|
||||
assetid = _make_asset(db)
|
||||
|
||||
panels = _data(client, '/api/pluginui/asset-panels?assetid=%d' % assetid,
|
||||
auth_headers)
|
||||
panel = next(p for p in panels if p['id'] == 'shouty')
|
||||
assert panel['group'] == 'metrics'
|
||||
|
||||
Reference in New Issue
Block a user