diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b60dbc15..447883d82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Next * Define initial note structure for projects in designs * Allow exporting and importing notes +* Fix chapter number always prepended to title in `` component ## v2024.8 - 2024-01-23 diff --git a/api/src/reportcreator_api/tests/mock.py b/api/src/reportcreator_api/tests/mock.py index 583e3b1b2..534ae80da 100644 --- a/api/src/reportcreator_api/tests/mock.py +++ b/api/src/reportcreator_api/tests/mock.py @@ -159,7 +159,7 @@ def create_project_type(assets_kwargs=None, **kwargs) -> ProjectType: for idx, asset_kwargs in enumerate(assets_kwargs if assets_kwargs is not None else [{}] * 2): UploadedAsset.objects.create(linked_object=project_type, **{ 'name': f'file{idx}.png', - 'file': SimpleUploadedFile(name=f'file{idx}.png', content=create_png_file()) + 'file': SimpleUploadedFile(name=f'file{idx}.png', content=asset_kwargs.pop('content', create_png_file())) } | asset_kwargs) UploadedAsset.objects.create(linked_object=project_type, name='file1.png', file=SimpleUploadedFile(name='file1.png', content=b'file1')) diff --git a/api/src/reportcreator_api/tests/test_rendering.py b/api/src/reportcreator_api/tests/test_rendering.py index c0cba9781..e41723f1f 100644 --- a/api/src/reportcreator_api/tests/test_rendering.py +++ b/api/src/reportcreator_api/tests/test_rendering.py @@ -7,9 +7,8 @@ from unittest import mock from pytest_django.asserts import assertHTMLEqual from django.test import override_settings -from django.core.files.uploadedfile import SimpleUploadedFile -from reportcreator_api.tests.mock import create_imported_member, create_project_type, create_project, create_user, create_finding +from reportcreator_api.tests.mock import create_imported_member, create_png_file, create_project_type, create_project, create_user, create_finding from reportcreator_api.tasks.rendering.entry import render_pdf, render_project_markdown_fields_to_html from reportcreator_api.tasks.rendering.render import render_to_html from reportcreator_api.utils.utils import copy_keys, merge @@ -25,7 +24,10 @@ class TestHtmlRendering: @pytest.fixture(autouse=True) def setUp(self): self.user = create_user() - self.project_type = create_project_type(assets_kwargs=[{'name': 'test.js', 'file': SimpleUploadedFile(name='test.js', content=b'console.log("Script loaded");')}]) + self.project_type = create_project_type(assets_kwargs=[ + {'name': 'image.png', 'content': create_png_file()}, + {'name': 'test.js', 'content': b'console.log("Script loaded");'}, + ]) self.project = create_project( project_type=self.project_type, members=[self.user], @@ -171,6 +173,41 @@ def test_comma_and_join(self, props, items, html): ).replace('', '') assert actual_html == html + @pytest.mark.parametrize(['template', 'expected'], [ + ('' , 'H1'), + ('' , 'H1 numbered'), + ('', 'H1.1 numbered'), + ('', 'H1 appendix'), + ('', 'H1.1 appendix'), + ('title', 'title'), + ('', 'caption1'), + ('', 'caption2'), + ('', 'caption3'), + ('title', 'title'), + ('', 'caption1'), + ('', 'caption2'), + ('title', 'title'), + ('title', 'title'), + ]) + def test_ref_rendering(self, template, expected): + html = self.render_html(f""" +
{template}
+

H1

+

H1 numbered

+

H1.1 numbered

+
+

H1 appendix

+

H1.1 appendix

+
+
caption1
+
caption2
+
caption3
+
caption1
+
caption2
+
other
+ """) + actual = self.extract_html_part(html, '
', '
')[6:-7] + assertHTMLEqual(actual, expected) def test_toc_rendering(self): html = self.render_html(""" @@ -212,6 +249,52 @@ def test_toc_rendering(self): """) + def test_lof_rendering(self): + html = self.render_html(""" + +
+

List of Figures

+
    +
  • + +
  • +
+
+
+
caption1
+
caption2
+
caption3
+ """) + assertHTMLEqual(self.extract_html_part(html, '
    ', '
'), """ + + """) + + def test_lot_rendering(self): + html = self.render_html(""" + +
+

List of Tables

+
    +
  • + +
  • +
+
+
+
caption1
+
caption2
+ """) + assertHTMLEqual(self.extract_html_part(html, '
    ', '
'), """ + + """) + def test_chart_rendering(self): html = self.render_html("""