|
20 | 20 | # if not DISPLAY: |
21 | 21 | # pytest.skip("Skipped because of missing DISPLAY", allow_module_level=True) # Avoid failing unit tests in system without X11 |
22 | 22 | import wx |
| 23 | + |
| 24 | +import robotide.editor.editors |
23 | 25 | from .fakeplugin import FakePlugin |
24 | 26 | from robotide.controller.macrocontrollers import TestCaseController |
25 | | -from robotide.editor.macroeditors import TestCaseEditor |
| 27 | +from robotide.publish.messages import RideItemNameChanged |
| 28 | +from robotide.editor.editors import FindUsagesHeader |
| 29 | +from robotide.editor.macroeditors import TestCaseEditor, UserKeywordEditor |
26 | 30 |
|
| 31 | +DELEGATED_METHODS =[('save', 'save'), |
| 32 | + # ('undo', 'on_undo'), # Disabled because of double Ctrl-Z |
| 33 | + ('redo', 'on_redo'), |
| 34 | + ('cut', 'on_cut'), |
| 35 | + ('copy', 'on_copy'), |
| 36 | + ('paste', 'on_paste'), |
| 37 | + ('insert', 'on_insert'), |
| 38 | + ('insert_cells', 'on_insert_cells'), |
| 39 | + ('insert_rows', 'on_insert_rows'), |
| 40 | + ('delete_rows', 'on_delete_rows'), |
| 41 | + ('delete_cells', 'on_delete_cells'), |
| 42 | + ('delete', 'on_delete'), |
| 43 | + ('show_content_assist', 'show_content_assist'), |
| 44 | + ('on_move_rows_up', 'on_move_rows_up'), |
| 45 | + ('on_move_rows_down', 'on_move_rows_down'), |
| 46 | + ('comment_rows', 'on_comment_rows'), |
| 47 | + ('uncomment_rows', 'on_uncomment_rows'), |
| 48 | + ('sharp_comment_rows', 'on_sharp_comment_rows'), |
| 49 | + ('sharp_uncomment_rows', 'on_sharp_uncomment_rows'), |
| 50 | + ('comment_cells', 'on_comment_cells'), |
| 51 | + ('uncomment_cells', 'on_uncomment_cells')] |
27 | 52 |
|
28 | 53 | TestCaseEditor._populate = lambda self: None |
29 | 54 |
|
@@ -60,33 +85,70 @@ class MacroEditorTest(unittest.TestCase): |
60 | 85 |
|
61 | 86 | def setUp(self): |
62 | 87 | myapp = wx.App(None) |
63 | | - controller = TestCaseController(IncredibleMock(), IncredibleMock()) |
64 | | - plugin = FakePlugin({}, controller) |
| 88 | + self.controller = TestCaseController(IncredibleMock(), IncredibleMock()) |
| 89 | + plugin = FakePlugin({}, self.controller) |
65 | 90 | self.tc_editor = TestCaseEditor( |
66 | | - plugin, wx.Frame(None), controller, None) |
| 91 | + plugin, wx.Frame(None), self.controller, None) |
67 | 92 |
|
68 | 93 | def test_delegation_to_kw_editor(self): |
69 | | - for method, kw_method in \ |
70 | | - [('save', 'save'), |
71 | | - # ('undo', 'on_undo'), # Disabled because of double Ctrl-Z |
72 | | - ('redo', 'on_redo'), |
73 | | - ('cut', 'on_cut'), |
74 | | - ('copy', 'on_copy'), |
75 | | - ('paste', 'on_paste'), |
76 | | - ('insert', 'on_insert'), |
77 | | - ('insert_cells', 'on_insert_cells'), |
78 | | - ('insert_rows', 'on_insert_rows'), |
79 | | - ('delete_rows', 'on_delete_rows'), |
80 | | - ('delete_cells', 'on_delete_cells'), |
81 | | - ('delete', 'on_delete'), |
82 | | - ('show_content_assist', 'show_content_assist')]: |
| 94 | + for method, kw_method in DELEGATED_METHODS: |
| 95 | + kw_mock = MockKwEditor() |
| 96 | + self.tc_editor.kweditor = kw_mock |
| 97 | + getattr(kw_mock, kw_method).is_to_be_called() |
| 98 | + getattr(self.tc_editor, method)() |
| 99 | + assert getattr(kw_mock, kw_method).has_been_called(), (f"Should have called \"" |
| 100 | + f"{kw_method}\" when calling \"{method}\"") |
| 101 | + |
| 102 | + self.tc_editor._populate() |
| 103 | + RideItemNameChanged(item=self.controller, old_name='Title of User Keyword', new_name="New Name").publish() |
| 104 | + # self.tc_editor._name_changed(message) |
| 105 | + # print(f"DEBUG: Name={self.tc_editor.header}") |
| 106 | + # assert self.tc_editor.title == "New Name" |
| 107 | + |
| 108 | + |
| 109 | +class MacroEditorUserKWTest(unittest.TestCase): |
| 110 | + |
| 111 | + def setUp(self): |
| 112 | + myapp = wx.App(None) |
| 113 | + self.controller = TestCaseController(IncredibleMock(), IncredibleMock()) |
| 114 | + plugin = FakePlugin({}, self.controller) |
| 115 | + self.tc_editor = UserKeywordEditor( |
| 116 | + plugin, wx.Frame(None), self.controller, None) |
| 117 | + |
| 118 | + def test_delegation_to_kw_editor(self): |
| 119 | + for method, kw_method in DELEGATED_METHODS: |
83 | 120 | kw_mock = MockKwEditor() |
84 | 121 | self.tc_editor.kweditor = kw_mock |
85 | 122 | getattr(kw_mock, kw_method).is_to_be_called() |
86 | 123 | getattr(self.tc_editor, method)() |
87 | 124 | assert getattr(kw_mock, kw_method).has_been_called(), (f"Should have called \"" |
88 | 125 | f"{kw_method}\" when calling \"{method}\"") |
89 | 126 |
|
| 127 | + def test_header(self): |
| 128 | + myapp = wx.App(None) |
| 129 | + kw_mock = MockKwEditor() |
| 130 | + self.tc_editor.kweditor = kw_mock |
| 131 | + header = self.tc_editor._create_header(text="Title of User Keyword", readonly=False) |
| 132 | + assert isinstance(header, FindUsagesHeader) |
| 133 | + label = header._header.GetLabel() |
| 134 | + assert label == "Title of User Keyword" |
| 135 | + |
| 136 | + def test_header_read_only(self): |
| 137 | + myapp = wx.App(None) |
| 138 | + kw_mock = MockKwEditor() |
| 139 | + self.tc_editor.kweditor = kw_mock |
| 140 | + header = self.tc_editor._create_header(text="Title of User Keyword", readonly=True) |
| 141 | + assert isinstance(header, FindUsagesHeader) |
| 142 | + label = header._header.GetLabel() |
| 143 | + assert label == "Title of User Keyword (READ ONLY)" |
| 144 | + |
| 145 | + def test_misc(self): |
| 146 | + myapp = wx.App(None) |
| 147 | + kw_mock = MockKwEditor() |
| 148 | + self.tc_editor.kweditor = kw_mock |
| 149 | + self.tc_editor.undo() # Should do nothing |
| 150 | + self.tc_editor.close() |
| 151 | + |
90 | 152 |
|
91 | 153 | if __name__ == '__main__': |
92 | 154 | app = wx.App() |
|
0 commit comments