-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_second_controller_import.py
More file actions
158 lines (128 loc) · 4.41 KB
/
test_second_controller_import.py
File metadata and controls
158 lines (128 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import pytest
from app.controller.second_controller import SecondController
class ComboBoxStub:
def __init__(self, text=""):
self.items = []
self._text = text
def currentText(self):
return self._text
def clear(self):
self.items.clear()
def addItem(self, text):
self.items.append(text)
if not self._text:
self._text = text
def setCurrentText(self, text):
self._text = text
class LabelStub:
def __init__(self):
self.text = ""
def setText(self, text):
self.text = text
class TableStub:
def __init__(self):
self.headers = []
def setHorizontalHeaderLabels(self, labels):
self.headers = labels
class ViewStub:
def __init__(self, mode_text):
self.contentModeComboBox = ComboBoxStub(mode_text)
self.previewTable = TableStub()
self.selectionHelpLabel = LabelStub()
@pytest.fixture
def controller_factory():
def build_controller(mode_text="Prefer Context When Available"):
controller = SecondController.__new__(SecondController)
controller.view = ViewStub(mode_text)
controller.current_mode_map = {
"Prefer Context When Available": "prefer_secondary",
"Context Only": "secondary_only",
"Main Text Only": "primary_only",
"Combine Main Text and Context": "combine",
"Prefer Speaker Notes": "prefer_secondary",
"Speaker Notes Only": "secondary_only",
"Slide Text Only": "primary_only",
"Combine Slide Text and Speaker Notes": "combine",
"Row Text Only": "primary_only",
"Include Sheet and Column Context": "combine",
}
return controller
return build_controller
def test_build_import_payload_prefers_secondary_with_primary_fallback(
controller_factory,
):
controller = controller_factory("Prefer Context When Available")
selected_rows = [
{
"item_number": 1,
"title": "Item 1",
"primary_text": "Primary summary",
"secondary_text": "Context notes",
},
{
"item_number": 2,
"title": "Item 2",
"primary_text": "Only primary text",
"secondary_text": "",
},
]
payload_rows, imported_text = controller._build_import_payload(selected_rows)
assert len(payload_rows) == 2
assert payload_rows[0]["resolved_text"] == "Context notes"
assert payload_rows[1]["resolved_text"] == "Only primary text"
assert imported_text == "Context notes\n\nOnly primary text"
def test_build_import_payload_combines_main_text_and_context(controller_factory):
controller = controller_factory("Combine Main Text and Context")
selected_rows = [
{
"item_number": 3,
"title": "Chapter 3",
"primary_text": "Agenda",
"secondary_text": "Longer narration",
}
]
payload_rows, imported_text = controller._build_import_payload(selected_rows)
assert payload_rows[0]["content_mode"] == "combine"
assert payload_rows[0]["resolved_text"] == "Agenda\n\nLonger narration"
assert imported_text == "Agenda\n\nLonger narration"
@pytest.mark.parametrize(
("source_type", "expected_headers", "expected_mode", "expected_mode_value"),
[
(
"pptx",
["Item", "Slide Text", "Speaker Notes"],
"Speaker Notes Only",
"secondary_only",
),
(
"pdf",
["Item", "Page Text", "Page Context"],
"Page Text Only",
"primary_only",
),
(
"xlsx",
["Item", "Row Text", "Sheet / Column Context"],
"Include Sheet and Column Context",
"combine",
),
(
"unknown",
["Item", "Main Text", "Context"],
"Prefer Context When Available",
"prefer_secondary",
),
],
)
def test_apply_format_profile_uses_format_specific_terms(
controller_factory,
source_type,
expected_headers,
expected_mode,
expected_mode_value,
):
controller = controller_factory("")
controller._apply_format_profile(source_type)
assert controller.view.previewTable.headers == expected_headers
assert expected_mode in controller.view.contentModeComboBox.items
assert controller.current_mode_map[expected_mode] == expected_mode_value