From fe1dd19044fb10a4193cb5c42b37833783484350 Mon Sep 17 00:00:00 2001 From: Bertil Varenhorst Date: Tue, 19 Nov 2024 13:13:47 +0100 Subject: [PATCH] resolve #6 Change-Id: I838fba364d2b99e0be3bc879eafbd9ca8296aff4 --- src/plantuml_gui/add.py | 14 +++++++++++++- tests/test_app.py | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/plantuml_gui/add.py b/src/plantuml_gui/add.py index 36b83b1..a7753d5 100644 --- a/src/plantuml_gui/add.py +++ b/src/plantuml_gui/add.py @@ -23,6 +23,7 @@ # SOFTWARE. +import re from typing import Literal @@ -46,7 +47,18 @@ def add( lines = puml.splitlines() if type == "activity": - lines.insert(index, ":Activity;") + activity_numbers = [] + for line in lines: + match = re.search(r":Activity (\d+)", line) + if match: + activity_numbers.append(int(match.group(1))) + + if activity_numbers: + next_activity_number = max(activity_numbers) + 1 + else: + next_activity_number = 1 + + lines.insert(index, f":Activity {next_activity_number};") if type == "connector": lines.insert(index, "(C)") diff --git a/tests/test_app.py b/tests/test_app.py index 9dc9c3d..0756843 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -286,7 +286,7 @@ def test_addtomergenoifmerge3(self, client): endif detach repeat -:Activity; +:Activity 1; :Activity; backward:Activity; repeat while (while ?) is (yes) not (no) @@ -329,7 +329,7 @@ def test_addtomergenoifmerge2(self, client): detach endif repeat -:Activity; +:Activity 1; :Activity; backward:Activity; repeat while (while ?) is (yes) not (no) @@ -372,7 +372,7 @@ def test_addtomergenoifmerge(self, client): :Activity; endif repeat -:Activity; +:Activity 1; :Activity; backward:Activity; repeat while (while ?) is (yes) not (no) @@ -447,7 +447,7 @@ def test_addtomerge2(self, client): else (no) :Activity; endif -:Activity; +:Activity 1; repeat :Activity; :Activity; @@ -519,7 +519,7 @@ def test_addactivitymerge(self, client): else (no) :Actaivity; endif -:Activity; +:Activity 1; :Activity; endif :Activity; @@ -1743,7 +1743,7 @@ def test_add_activity_connector2(self, client): note end note detach -:Activity; +:Activity 1; @endumll""" assert response.data.decode("utf-8") == expected_puml @@ -1950,7 +1950,7 @@ def test_addactivitybelowwithconnector(self, client): (A) detach stop -:Activity; +:Activity 1; @enduml""" assert response.data.decode("utf-8") == expected_puml @@ -3765,7 +3765,7 @@ def test_addtofork(self, client): fork again :action; end fork -:Activity; +:Activity 1; @enduml""" assert response.data.decode("utf-8") == expected_puml @@ -4377,6 +4377,27 @@ def test_addtoactivity(self, client): backward:Activity; repeat while (while ?) is (yes) not (no) :Activity; +@enduml""" + assert response.data.decode("utf-8") == expected_puml + + def test_addactivitytoactivity(self, client): + test_data = { + "plantuml": """@startuml +:Activity 1; +@enduml""", + "svg": """activity 1""", + "svgelement": """""", + "type": "activity", + } + with client: + response = client.post( + "/addToActivity", + data=json.dumps(test_data), + content_type="application/json", + ) + expected_puml = """@startuml +:Activity 1; +:Activity 2; @enduml""" assert response.data.decode("utf-8") == expected_puml