From bba94070dfddcd1abb51c9fd371bedde8d2c3e88 Mon Sep 17 00:00:00 2001 From: Mirek Simek Date: Fri, 26 Jan 2024 15:43:35 +0100 Subject: [PATCH] Added defaultComponents to search config, implemented test --- oarepo_ui/resources/resource.py | 6 +++- oarepo_ui/theme/webpack.py | 4 +-- setup.cfg | 2 +- tests/templates/TestSearch.jinja | 5 +-- tests/test_search.py | 55 ++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 tests/test_search.py diff --git a/oarepo_ui/resources/resource.py b/oarepo_ui/resources/resource.py index 2ae018da..e5788f7f 100644 --- a/oarepo_ui/resources/resource.py +++ b/oarepo_ui/resources/resource.py @@ -226,7 +226,11 @@ def search(self): search_options = dict( api_config=self.api_service.config, identity=g.identity, - overrides={"ui_endpoint": self.config.url_prefix, "ui_links": ui_links}, + overrides={ + "ui_endpoint": self.config.url_prefix, + "ui_links": ui_links, + "defaultComponents": {}, + }, ) extra_context = dict() diff --git a/oarepo_ui/theme/webpack.py b/oarepo_ui/theme/webpack.py index cb943c52..e7318054 100644 --- a/oarepo_ui/theme/webpack.py +++ b/oarepo_ui/theme/webpack.py @@ -73,9 +73,7 @@ "oarepo_ui_components": "./js/oarepo_ui/custom-components.js", }, dependencies=dependencies, - devDependencies={ - "eslint-plugin-i18next":"^6.0.3" - }, + devDependencies={"eslint-plugin-i18next": "^6.0.3"}, aliases={ **aliases, "@translations/oarepo_ui": "translations/oarepo_ui", diff --git a/setup.cfg b/setup.cfg index 8c976d0f..bbafe5a7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-ui -version = 5.0.100 +version = 5.0.101 description = UI module for invenio 3.5+ long_description = file: README.md long_description_content_type = text/markdown diff --git a/tests/templates/TestSearch.jinja b/tests/templates/TestSearch.jinja index 6cfe67b8..ded62845 100644 --- a/tests/templates/TestSearch.jinja +++ b/tests/templates/TestSearch.jinja @@ -1,8 +1,9 @@ -{#def extra_context, ui_links #} +{#def extra_context, ui_links, search_app_config #} { "ui_links": {{ ui_links|tojson|safe }}, "permissions": {{ extra_context.permissions|tojson|safe }}, - "dummy_filter": {{ 1|dummy|tojson|safe }} + "dummy_filter": {{ 1|dummy|tojson|safe }}, + "search_config": {{ search_app_config|tojson|safe }} } diff --git a/tests/test_search.py b/tests/test_search.py new file mode 100644 index 00000000..3fb41509 --- /dev/null +++ b/tests/test_search.py @@ -0,0 +1,55 @@ +import json + + +def test_search( + app, record_ui_resource, simple_record, client_with_credentials, fake_manifest +): + with client_with_credentials.get(f"/simple-model/") as c: + txt = json.loads(c.text) + search_config = txt["search_config"] + assert search_config == { + "aggs": [], + "appId": None, + "defaultComponents": {}, + "defaultSortingOnEmptyQueryString": {"sortBy": "newest"}, + "initialQueryState": { + "filters": [], + "hiddenParams": None, + "layout": "list", + "page": 1, + "size": 10, + "sortBy": "bestmatch", + }, + "layoutOptions": {"gridView": False, "listView": True}, + "paginationOptions": { + "defaultValue": 10, + "maxTotalResults": 10000, + "resultsPerPage": [ + {"text": "10", "value": 10}, + {"text": "20", "value": 20}, + {"text": "50", "value": 50}, + ], + }, + "searchApi": { + "axios": { + "headers": {"Accept": "application/vnd.inveniordm.v1+json"}, + "url": "/api/simple-model", + "withCredentials": True, + }, + "invenio": { + "requestSerializer": "InvenioRecordsResourcesRequestSerializer" + }, + }, + "sortOptions": [ + {"sortBy": "bestmatch", "text": "Best match"}, + {"sortBy": "newest", "text": "Newest"}, + {"sortBy": "oldest", "text": "Oldest"}, + ], + "sortOrderDisabled": True, + "ui_endpoint": "/simple-model", + "ui_links": { + "create": "https://127.0.0.1:5000/simple-model/_new", + "next": "https://127.0.0.1:5000/simple-model?page=2", + "self": "https://127.0.0.1:5000/simple-model", + }, + }