"""Порядок строк ответа `GET …/statement` (P3-17): строки `ok` по коду, вложения источника — за своей строкой.""" from src.domain.statement_layout import LayoutLine, order_lines def L( # noqa: N802 - короткая фабрика строки для таблиц тестов key: str, row_index: int | None, status: str, code: str | None, parent: int | None ) -> LayoutLine: return LayoutLine(key=key, row_index=row_index, line_status=status, line_code=code, parent_row_index=parent) def test_order_lines_attachments() -> None: lines = [ L("m0", 0, "missing", None, None), L("1230", 1, "ok", "1230", None), L("u2", 2, "unreadable", None, None), L("1210", 3, "ok", "1210", None), L("d4", 4, "detail", None, 3), L("t1250", None, "ok", "1250", None), L("2410b", 9, "ok", "2410", None), L("2410a", 6, "ok", "2410", None), ] assert order_lines(lines) == ["m0", "1210", "d4", "1230", "u2", "t1250", "2410a", "2410b"] def test_detail_without_parent_follows_previous_ok() -> None: assert order_lines([L("1110", 0, "ok", "1110", None), L("d1", 1, "detail", None, None)]) == ["1110", "d1"] def test_detail_with_unknown_parent_falls_back_to_previous_ok() -> None: lines = [L("1110", 0, "ok", "1110", None), L("d5", 5, "detail", None, 4)] assert order_lines(lines) == ["1110", "d5"] def test_attachments_keep_row_order() -> None: lines = [ L("u3", 3, "unreadable", None, None), L("1110", 0, "ok", "1110", None), L("d2", 2, "detail", None, 0), L("m1", 1, "missing", None, None), ] assert order_lines(lines) == ["1110", "m1", "d2", "u3"] def test_empty() -> None: assert order_lines([]) == []