From 3c8a74c746adf2f296a132a9fe76c0a66c45a3ae Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Wed, 28 Feb 2024 11:04:46 +0100 Subject: [PATCH] Add unit test for highlights in instruments --- server/core/urls.py | 2 +- server/notes/mutations.py | 2 + server/notes/tests/test_highlights.py | 56 ++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/server/core/urls.py b/server/core/urls.py index c062f80b..291c3da9 100644 --- a/server/core/urls.py +++ b/server/core/urls.py @@ -18,7 +18,7 @@ urlpatterns = [ re_path(r"^statistics/", include("statistics.urls", namespace="statistics")), # wagtail re_path(r"^cms/autocomplete/", include(autocomplete_admin_urls)), - re_path(r"^cms/pages/(\d+)/$", override_wagtailadmin_explore_default_ordering), + # re_path(r"^cms/pages/(\d+)/$", override_wagtailadmin_explore_default_ordering), re_path(r"^cms/", include(wagtailadmin_urls)), re_path(r"^documents/", include(wagtaildocs_urls)), # graphql backend diff --git a/server/notes/mutations.py b/server/notes/mutations.py index b226251d..57e1b5ba 100644 --- a/server/notes/mutations.py +++ b/server/notes/mutations.py @@ -305,6 +305,8 @@ class AddHighlight(relay.ClientIDMutation): page = Module.objects.get(id=page_id) elif page_type == "ChapterNode": page = Chapter.objects.get(id=page_id) + elif page_type == "InstrumentNode": + page = BasicKnowledge.objects.get(id=page_id) else: raise Exception("wrong type") diff --git a/server/notes/tests/test_highlights.py b/server/notes/tests/test_highlights.py index 8d5f3dc9..760ea8a6 100644 --- a/server/notes/tests/test_highlights.py +++ b/server/notes/tests/test_highlights.py @@ -1,5 +1,10 @@ import pytest -from books.factories import ChapterFactory, ContentBlockFactory, ModuleFactory +from books.factories import ( + ChapterFactory, + ContentBlockFactory, + InstrumentFactory, + ModuleFactory, +) from books.models.contentblock import ContentBlock from graphql_relay import to_global_id @@ -121,6 +126,20 @@ module_query = ( """ ) +instrument_query = ( + fragment + + """ + query InstrumentQuery($id: ID!) { + instrument(id:$id) { + id + highlights { + ...HighlightLegacyParts + } + } + } + """ +) + @pytest.mark.usefixtures("create_users") class TestAddHighlight: @@ -186,7 +205,40 @@ class TestAddHighlight: assert result.errors is not None def test_add_highlight_in_instrument(self, teacher, get_client): - assert 1 == 0 + instrument = InstrumentFactory() + client = get_client(teacher) + iid = to_global_id("InstrumentNode", instrument.id) + result = client.execute( + add_highlight_mutation, + variables={ + "input": { + "highlight": { + "page": iid, + "paragraphIndex": 0, + "text": "Hallo", + "startPosition": 0, + "selectionLength": 10, + "color": "alpha", + } + } + }, + ) + assert result.errors is None + + highlight = result.data.get("addHighlight").get("highlight") + logger.debug(highlight) + logger.debug(iid) + assert highlight.get("text") == "Hallo" + assert highlight.get("page").get("id") == iid + + client = get_client(teacher) + result = client.execute(instrument_query, variables={"id": iid}) + assert result.errors is None + instrument = result.data.get("instrument") + logger.debug(instrument) + assert instrument.get("id") == iid + assert instrument.get("highlights")[0].get("color") == "alpha" + assert instrument.get("highlights")[0].get("page").get("id") == iid def test_add_highlight_in_module(self, teacher, get_client): module = ModuleFactory()