Skip to content

Commit 332ae08

Browse files
committed
[[NODE]] migration: adjust Diff/Changelog, add end-to-end test
1 parent d887fa2 commit 332ae08

File tree

16 files changed

+364
-22
lines changed

16 files changed

+364
-22
lines changed

strictdoc/core/document_finder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
PathFinder,
2828
)
2929
from strictdoc.core.project_config import ProjectConfig
30+
from strictdoc.helpers.exception import StrictDocException
3031
from strictdoc.helpers.parallelizer import Parallelizer
3132
from strictdoc.helpers.paths import SDocRelativePath
3233
from strictdoc.helpers.textx import drop_textx_meta
@@ -43,13 +44,11 @@ def find_sdoc_content(
4344
for paths_to_files_or_doc in project_config.input_paths:
4445
if not os.path.exists(paths_to_files_or_doc):
4546
sys.stdout.flush()
46-
err = (
47+
raise StrictDocException(
4748
"error: "
4849
"Provided path is neither a single file or a folder: "
4950
f"'{paths_to_files_or_doc}'"
5051
)
51-
print(err) # noqa: T201
52-
sys.exit(1)
5352

5453
with measure_performance("Completed finding SDoc and assets"):
5554
file_tree, asset_manager = DocumentFinder._build_file_tree(

strictdoc/export/html/templates/components/table_key_value/index.jinja

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@
1212
{% else %}
1313
<div class="sdoc-table_key_value-key">{{ key_value_pair["Key"] }}</div>
1414
{% endif %}
15-
<div class="sdoc-table_key_value-value">{{ key_value_pair["Value"] }}</div>
15+
<div
16+
class="sdoc-table_key_value-value"
17+
data-testid="table-row-value-{{ key_value_pair["Key"].lower().replace(" ", "-") }}"
18+
>
19+
{{ key_value_pair["Value"] }}
20+
</div>
1621
{% endif %}

strictdoc/export/html/templates/screens/git/diff_content.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434

3535
{%- set document_iterator = traceability_index.get_document_iterator(document) -%}
3636
{%- for section_or_requirement in document_iterator.all_content(print_fragments=True, print_fragments_from_files=False) %}
37-
{%- if section_or_requirement.is_requirement() %}
37+
{%- if section_or_requirement.is_requirement() and section_or_requirement.node_type != "SECTION" %}
3838
{%- set requirement = section_or_requirement %}
3939
{% include "screens/git/node/requirement.jinja" %}
4040

41-
{%- elif section_or_requirement.is_section() %}
41+
{%- elif section_or_requirement.is_section() or section_or_requirement.node_type == "SECTION" %}
4242
{%- set section = section_or_requirement %}
4343
{% include "screens/git/node/section.jinja" %}
4444
{%- endif %}

strictdoc/export/html/templates/screens/git/fields/section_fields.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
{%- if section_change.is_paired_change() -%}
4343
<div class="sdoc_pre_content">{{ section_change.get_colored_title_diff(side) }}</div>
4444
{%- else -%}
45-
<div class="sdoc_pre_content">{{ section.title }}</div>
45+
<div class="sdoc_pre_content">{{ section.reserved_title }}</div>
4646
{%- endif -%}
4747
{% else %}
48-
<div class="sdoc_pre_content">{{ section.title }}</div>
48+
<div class="sdoc_pre_content">{{ section.reserved_title }}</div>
4949
{% endif %}
5050
</div>
5151

strictdoc/export/html/templates/screens/git/form.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
placeholder="Enter the LHS revision here"
1515
id="left_revision"
1616
name="left_revision"
17+
data-testid="diff-screen-field-lhs"
1718
/>
1819
{% include "components/button/diff.jinja" %}
1920
<input
@@ -26,6 +27,7 @@
2627
placeholder="Enter the RHS revision here"
2728
id="right_revision"
2829
name="right_revision"
30+
data-testid="diff-screen-field-rhs"
2931
/>
3032
<input
3133
type="hidden"

strictdoc/export/html/templates/screens/git/nav_tabs.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{% else %}
1616
href="changelog.html"
1717
{% endif %}
18+
data-testid="diff-screen-tab-changelog"
1819
>Changelog</a>
1920
</div>
2021
</nav>

strictdoc/export/html/templates/screens/git/node/section.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<span>
1414
{{ section.context.title_number_string if section.context.title_number_string else "&nbsp;"|safe * (section.ng_level * 2 - 1) }}
1515
</span>
16-
<span>{{ section.title }}</span>
16+
<span>{{ section.reserved_title }}</span>
1717
{%- if tab == "diff" -%}
1818
{%- if section_change is not none -%}
1919
{%- if section_change.section_token is not none -%}

strictdoc/git/change.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,14 @@ def __init__(
9595

9696
if matched_mid is not None or matched_uid is not None:
9797
change_type = ChangeType.SECTION_MODIFIED
98-
assert isinstance(lhs_section, SDocSection), lhs_section
99-
assert isinstance(rhs_section, SDocSection), rhs_section
98+
assert isinstance(lhs_section, SDocSection) or (
99+
isinstance(lhs_section, SDocNode)
100+
and lhs_section.node_type == "SECTION"
101+
), lhs_section
102+
assert isinstance(rhs_section, SDocSection) or (
103+
isinstance(rhs_section, SDocNode)
104+
and rhs_section.node_type == "SECTION"
105+
), rhs_section
100106
elif lhs_section is not None:
101107
assert rhs_section is None, rhs_section
102108
change_type = ChangeType.SECTION_REMOVED

strictdoc/git/project_diff_analyzer.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ def _iterate_one_index(
422422
for node in document_iterator.all_content(
423423
print_fragments=True, print_fragments_from_files=False
424424
):
425-
if isinstance(node, (SDocSection, SDocDocument)):
425+
if isinstance(node, (SDocSection, SDocDocument)) or (
426+
isinstance(node, SDocNode) and node.node_type == "SECTION"
427+
):
426428
if node in change_stats.map_nodes_to_changes:
427429
continue
428430

@@ -455,8 +457,12 @@ def _iterate_one_index(
455457
)
456458
# FIXME: This is when a Requirement becomes
457459
# a Section with the same UID preserved.
458-
if other_section_or_none is not None and not isinstance(
459-
other_section_or_none, SDocSection
460+
if other_section_or_none is not None and not (
461+
isinstance(other_section_or_none, SDocSection)
462+
or (
463+
isinstance(other_section_or_none, SDocNode)
464+
and other_section_or_none.node_type == "SECTION"
465+
)
460466
):
461467
other_section_or_none = None
462468
matched_uid = None
@@ -481,19 +487,22 @@ def _iterate_one_index(
481487
uid_modified = True
482488

483489
if other_section_or_none is not None:
484-
if node.title != other_section_or_none.title:
490+
if (
491+
node.reserved_title
492+
!= other_section_or_none.reserved_title
493+
):
485494
title_modified = True
486495
lhs_colored_title_diff = (
487496
get_colored_html_diff_string(
488-
node.title,
489-
other_section_or_none.title,
497+
node.reserved_title,
498+
other_section_or_none.reserved_title,
490499
"left",
491500
)
492501
)
493502
rhs_colored_title_diff = (
494503
get_colored_html_diff_string(
495-
node.title,
496-
other_section_or_none.title,
504+
node.reserved_title,
505+
other_section_or_none.reserved_title,
497506
"right",
498507
)
499508
)
@@ -508,8 +517,12 @@ def _iterate_one_index(
508517
if other_section_or_none is not None:
509518
section_token = MID.create()
510519

511-
lhs_section: Optional[Union[SDocSection, SDocDocument]]
512-
rhs_section: Optional[Union[SDocSection, SDocDocument]]
520+
lhs_section: Optional[
521+
Union[SDocSection, SDocDocument, SDocNode]
522+
]
523+
rhs_section: Optional[
524+
Union[SDocSection, SDocDocument, SDocNode]
525+
]
513526
if side == "left":
514527
lhs_section = node
515528
rhs_section = other_section_or_none
@@ -536,7 +549,7 @@ def _iterate_one_index(
536549
] = section_change
537550
change_stats.add_change(section_change)
538551

539-
if isinstance(node, SDocNode):
552+
if isinstance(node, SDocNode) and node.node_type != "SECTION":
540553
#
541554
# Step: We check if a requirement was modified at all, or if
542555
# it has already been checked before. Skipping the requirement
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from tests.end2end.helpers.screens.screen import Screen
2+
3+
4+
class Screen_Diff(Screen): # pylint: disable=invalid-name
5+
def do_enter_field_lhs(self, field_value: str):
6+
xpath_to_lhs_field = "(//*[@data-testid='diff-screen-field-lhs'])"
7+
8+
self.do_fill_in_field_value(xpath_to_lhs_field, field_value=field_value)
9+
10+
def do_enter_field_rhs(self, field_value: str):
11+
xpath_to_lhs_field = "(//*[@data-testid='diff-screen-field-rhs'])"
12+
13+
self.do_fill_in_field_value(xpath_to_lhs_field, field_value=field_value)
14+
15+
def do_submit(self):
16+
self.test_case.click_xpath('//*[@data-testid="form-submit-action"]')
17+
18+
def do_switch_tab_to_changelog(self):
19+
self.test_case.click_xpath(
20+
'//*[@data-testid="diff-screen-tab-changelog"]'
21+
)
22+
23+
def assert_documents_modified(self, stats: str) -> None:
24+
xpath = '//*[@data-testid="table-row-value-documents-modified"]'
25+
self.assert_xpath_contains(xpath, stats)
26+
27+
def assert_sections_modified(self, stats: str) -> None:
28+
xpath = '//*[@data-testid="table-row-value-sections-modified"]'
29+
self.assert_xpath_contains(xpath, stats)
30+
31+
def assert_requirements_modified(self, stats: str) -> None:
32+
xpath = '//*[@data-testid="table-row-value-requirements-modified"]'
33+
self.assert_xpath_contains(xpath, stats)

tests/end2end/helpers/screens/project_index/screen_project_index.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from selenium.webdriver.common.by import By
22
from seleniumbase import BaseCase
33

4+
from tests.end2end.helpers.screens.diff.diff import Screen_Diff
45
from tests.end2end.helpers.screens.document.screen_document import (
56
Screen_Document,
67
)
@@ -91,6 +92,12 @@ def assert_link_to_search_screen_present(self) -> None:
9192
by=By.XPATH,
9293
)
9394

95+
def assert_link_to_diff_screen_present(self) -> None:
96+
self.test_case.assert_element(
97+
'//a[@data-testid="project-tree-link-diff"]',
98+
by=By.XPATH,
99+
)
100+
94101
def do_click_on_first_document(self) -> Screen_Document:
95102
self.test_case.click_xpath('//*[@data-testid="tree-file-link"]')
96103
return Screen_Document(self.test_case)
@@ -125,6 +132,14 @@ def do_click_on_search_screen_link(
125132
)
126133
return Screen_Search(self.test_case)
127134

135+
def do_click_on_diff_screen_link(
136+
self,
137+
) -> Screen_Diff:
138+
self.test_case.click_xpath(
139+
'//a[@data-testid="project-tree-link-diff"]',
140+
)
141+
return Screen_Diff(self.test_case)
142+
128143
def do_click_on_the_document(self, doc_order: int = 1) -> Screen_Document:
129144
self.test_case.click_xpath(
130145
f"(//*[@data-testid='tree-file-link'])[{doc_order}]"

tests/end2end/helpers/screens/screen.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from selenium.webdriver.common.by import By
2+
from selenium.webdriver.support.wait import WebDriverWait
23
from seleniumbase import BaseCase
34
from typing_extensions import deprecated
45

@@ -132,3 +133,13 @@ def assert_toc_contains_not(self, string: str) -> None:
132133
def get_collapsible_list(self) -> CollapsibleList:
133134
CollapsibleList(self.test_case).assert_is_collapsible()
134135
return CollapsibleList(self.test_case)
136+
137+
def do_fill_in_field_value(
138+
self, field_xpath: str, field_value: str
139+
) -> None:
140+
self.test_case.type(field_xpath, f"{field_value}", by=By.XPATH)
141+
142+
WebDriverWait(self.test_case.driver, timeout=3).until(
143+
lambda _: self.test_case.get_value(field_xpath, by=By.XPATH)
144+
== field_value
145+
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[DOCUMENT]
2+
TITLE: Test document
3+
OPTIONS:
4+
ENABLE_MID: True
5+
6+
[GRAMMAR]
7+
ELEMENTS:
8+
- TAG: SECTION
9+
PROPERTIES:
10+
IS_COMPOSITE: True
11+
VIEW_STYLE: Narrative
12+
FIELDS:
13+
- TITLE: MID
14+
TYPE: String
15+
REQUIRED: False
16+
- TITLE: UID
17+
TYPE: String
18+
REQUIRED: False
19+
- TITLE: TITLE
20+
TYPE: String
21+
REQUIRED: True
22+
- TAG: TEXT
23+
FIELDS:
24+
- TITLE: UID
25+
TYPE: String
26+
REQUIRED: False
27+
- TITLE: STATEMENT
28+
TYPE: String
29+
REQUIRED: False
30+
- TAG: REQUIREMENT
31+
PROPERTIES:
32+
VIEW_STYLE: Table
33+
FIELDS:
34+
- TITLE: MID
35+
TYPE: String
36+
REQUIRED: False
37+
- TITLE: UID
38+
TYPE: String
39+
REQUIRED: False
40+
- TITLE: STATUS
41+
TYPE: String
42+
REQUIRED: False
43+
- TITLE: TITLE
44+
TYPE: String
45+
REQUIRED: False
46+
- TITLE: STATEMENT
47+
TYPE: String
48+
REQUIRED: False
49+
- TITLE: RATIONALE
50+
TYPE: String
51+
REQUIRED: False
52+
- TITLE: COMMENT
53+
TYPE: String
54+
REQUIRED: False
55+
RELATIONS:
56+
- TYPE: Parent
57+
- TYPE: File
58+
59+
[[SECTION]]
60+
MID: 8e4ede877770402b91a59026d31a7020
61+
TITLE: Section title
62+
63+
[REQUIREMENT]
64+
MID: c46def916b6f4df692c98888414feebb
65+
UID: REQ-1
66+
STATUS: Active
67+
TITLE: Requirement title
68+
STATEMENT: Requirement statement.
69+
RATIONALE: Rationale. TBD
70+
71+
[[/SECTION]]

0 commit comments

Comments
 (0)