Skip to content

Commit 9dddd50

Browse files
committed
Add tests for the recents feature
1 parent 06d75d6 commit 9dddd50

File tree

5 files changed

+92
-4
lines changed

5 files changed

+92
-4
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ checks:pylint:
1010
stage: checks
1111
before_script:
1212
- sudo dnf install -y python3-gobject gtk3 xorg-x11-server-Xvfb
13-
python3-pip python3-mypy python3-pyxdg gtk-layer-shell
13+
python3-pip python3-mypy python3-pyxdg gtk-layer-shell cairo-devel
1414
- pip3 install --quiet -r ci/requirements.txt
1515
- git clone https://github.com/QubesOS/qubes-core-admin-client ~/core-admin-client
1616
script:

qubes_menu/search_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def enable_recent(self, state: bool):
486486
"disable recent applications."
487487
)
488488
search_label.set_text(
489-
"No recent searches. \nUse Menu Settings to disable recent applications."
489+
"No recent searches. \nUse Menu Settings to disable recent searches."
490490
)
491491
else:
492492
app_label.set_text(

qubes_menu/tests/test_appmenu.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_app_menu_conffeatures():
2929
qapp._qubes['dom0'].features['menu-initial-page'] = 'favorites_page'
3030
qapp._qubes['dom0'].features['menu-sort-running'] = '1'
3131
qapp._qubes['dom0'].features['menu-position'] = ''
32+
qapp._qubes['dom0'].features['menu-disable-recent'] = '1'
3233
qapp.update_vm_calls()
3334

3435
dispatcher = MockDispatcher(qapp)
@@ -40,6 +41,7 @@ def test_app_menu_conffeatures():
4041
assert app_menu.initial_page == "favorites_page"
4142
assert app_menu.sort_running
4243
assert app_menu.appmenu_position == "mouse"
44+
assert app_menu.disable_recent == True
4345

4446

4547
def test_app_menu_conffeatures_default():
@@ -51,7 +53,9 @@ def test_app_menu_conffeatures_default():
5153
features={'menu-favorites': '',
5254
'menu-initial-page': 'fake',
5355
'menu-sort-running': 'fake',
54-
'menu-position': 'fake'})
56+
'menu-position': 'fake',
57+
'menu-disable-recent': ''
58+
})
5559
qapp.update_vm_calls()
5660

5761
dispatcher = MockDispatcher(qapp)
@@ -63,6 +67,7 @@ def test_app_menu_conffeatures_default():
6367
assert app_menu.initial_page == "app_page"
6468
assert not app_menu.sort_running
6569
assert app_menu.appmenu_position == "mouse"
70+
assert not app_menu.disable_recent
6671

6772

6873
def test_appmenu_options():
@@ -73,6 +78,7 @@ def test_appmenu_options():
7378
qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page'
7479
qapp._qubes['dom0'].features['menu-sort-running'] = '1'
7580
qapp._qubes['dom0'].features['menu-position'] = 'top-left'
81+
qapp._qubes['dom0'].features['menu-disable-recent'] = ''
7682
qapp.update_vm_calls()
7783

7884
dispatcher = MockDispatcher(qapp)
@@ -101,6 +107,7 @@ def test_appmenu_positioning():
101107
qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page'
102108
qapp._qubes['dom0'].features['menu-sort-running'] = '1'
103109
qapp._qubes['dom0'].features['menu-position'] = ''
110+
qapp._qubes['dom0'].features['menu-disable-recent'] = ''
104111
qapp.update_vm_calls()
105112

106113
dispatcher = MockDispatcher(qapp)

qubes_menu/tests/test_search.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from qubesadmin.tests.mock_app import MockDispatcher
2525
from ..search_page import SearchPage
2626

27-
2827
def test_search(test_desktop_file_path, test_qapp, test_builder):
2928
dispatcher = MockDispatcher(test_qapp)
3029
vm_manager = VMManager(test_qapp, dispatcher)
@@ -90,3 +89,71 @@ def test_search(test_desktop_file_path, test_qapp, test_builder):
9089
if search_page._is_app_fitting(row)]
9190
assert len(found_entries) == 1
9291
assert found_entries[0].app_info.app_name == 'Xfce Appearance Settings'
92+
93+
@mock.patch('gi.repository.Gtk.Application')
94+
def test_recent_searches(mock_application, test_desktop_file_path, test_qapp,
95+
test_builder):
96+
dispatcher = MockDispatcher(test_qapp)
97+
vm_manager = VMManager(test_qapp, dispatcher)
98+
99+
with mock.patch.object(DesktopFileManager, 'desktop_dirs',
100+
[test_desktop_file_path]):
101+
desktop_file_manager = DesktopFileManager(test_qapp)
102+
103+
search_page = SearchPage(vm_manager, test_builder, desktop_file_manager)
104+
105+
assert search_page.search_entry.get_sensitive()
106+
107+
search_page.search_entry.set_text('dragons')
108+
109+
# find a dom0 app
110+
search_page.search_entry.set_text('dom0')
111+
112+
for row in search_page.app_list.get_children():
113+
if search_page._is_app_fitting(row):
114+
with mock.patch('subprocess.Popen') as mock_run, mock.patch.object(
115+
row.get_toplevel(), 'get_application', side_effect=mock_application):
116+
row.activate()
117+
assert mock_run.call_count == 1
118+
assert mock.call().emit('app-started', 'test3.desktop') in mock_application.mock_calls
119+
120+
# we are faking signals here
121+
search_page.recent_apps_manager.add_new_recent_app(None, 'test3.desktop')
122+
123+
texts = [row.search_text for row in search_page.recent_list.get_children()]
124+
assert texts == ['dom0']
125+
apps = [row.app_info.entry_name for row in
126+
search_page.recent_app_list.get_children()]
127+
assert apps == ['test3.desktop']
128+
129+
# do two more searches, but one should be the same as an existing search
130+
search_page.search_entry.set_text('')
131+
search_page.search_entry.set_text('xTeRm')
132+
133+
for row in search_page.app_list.get_children():
134+
if search_page._is_app_fitting(row):
135+
with mock.patch('subprocess.Popen') as mock_run, mock.patch.object(
136+
row.get_toplevel(), 'get_application', side_effect=mock_application):
137+
row.activate()
138+
assert mock_run.call_count == 1
139+
assert mock.call().emit('app-started', 'test1.desktop') in mock_application.mock_calls
140+
141+
search_page.recent_apps_manager.add_new_recent_app(None, 'test1.desktop')
142+
search_page.search_entry.set_text('')
143+
search_page.search_entry.set_text('dom0')
144+
145+
for row in search_page.app_list.get_children():
146+
if search_page._is_app_fitting(row):
147+
with mock.patch('subprocess.Popen') as mock_run, mock.patch.object(
148+
row.get_toplevel(), 'get_application', side_effect=mock_application):
149+
row.activate()
150+
assert mock_run.call_count == 1
151+
assert mock.call().emit('app-started', 'test3.desktop') in mock_application.mock_calls
152+
153+
search_page.recent_apps_manager.add_new_recent_app(None, 'test3.desktop')
154+
155+
texts = [row.search_text for row in search_page.recent_list.get_children()]
156+
assert texts == ['dom0', 'xTeRm']
157+
apps = [row.app_info.entry_name for row in
158+
search_page.recent_app_list.get_children()]
159+
assert apps == ['test3.desktop', 'test1.desktop']

qubes_menu_settings/test_menu_settings.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_menu_settings_load():
2828
qapp._qubes["dom0"].features["menu-sort-running"] = "1"
2929
qapp._qubes["dom0"].features["menu-favorites"] = ""
3030
qapp._qubes["dom0"].features["menu-position"] = ""
31+
qapp._qubes["dom0"].features["menu-disable-recent"] = "1"
3132

3233
qapp.update_vm_calls()
3334

@@ -38,6 +39,7 @@ def test_menu_settings_load():
3839
assert app.initial_page_model.get_selected() == "favorites_page"
3940
assert app.menu_position_model.get_selected() == "mouse"
4041
assert app.sort_running_check.get_active()
42+
assert not app.show_recent_check.get_active()
4143

4244

4345
def test_menu_settings_change():
@@ -46,6 +48,7 @@ def test_menu_settings_change():
4648
qapp._qubes["dom0"].features["menu-sort-running"] = ""
4749
qapp._qubes["dom0"].features["menu-favorites"] = ""
4850
qapp._qubes["dom0"].features["menu-position"] = "mouse"
51+
qapp._qubes["dom0"].features["menu-disable-recent"] = "1"
4952

5053
qapp.update_vm_calls()
5154

@@ -56,10 +59,12 @@ def test_menu_settings_change():
5659
assert app.initial_page_model.get_selected() == "app_page"
5760
assert app.menu_position_model.get_selected() == "mouse"
5861
assert not app.sort_running_check.get_active()
62+
assert not app.show_recent_check.get_active()
5963

6064
app.starting_page_combo.set_active_id("Search") # the first option is search
6165
app.menu_position_combo.set_active_id("Top Left") # the first option is Top Left
6266
app.sort_running_check.set_active(True)
67+
app.show_recent_check.set_active(True)
6368

6469
qapp.expected_calls[("dom0", "admin.vm.feature.Set", "menu-sort-running", b"1")] = (
6570
b"0\0"
@@ -70,6 +75,9 @@ def test_menu_settings_change():
7075
qapp.expected_calls[
7176
("dom0", "admin.vm.feature.Set", "menu-position", b"top-left")
7277
] = b"0\0"
78+
qapp.expected_calls[
79+
("dom0", "admin.vm.feature.Remove", "menu-disable-recent", None)
80+
] = b"0\0"
7381

7482
app._save()
7583

@@ -80,6 +88,7 @@ def test_menu_settings_change2():
8088
qapp._qubes["dom0"].features["menu-sort-running"] = ""
8189
qapp._qubes["dom0"].features["menu-favorites"] = ""
8290
qapp._qubes["dom0"].features["menu-position"] = "mouse"
91+
qapp._qubes["dom0"].features["menu-disable-recent"] = ""
8392

8493
qapp.update_vm_calls()
8594

@@ -89,11 +98,16 @@ def test_menu_settings_change2():
8998

9099
assert app.initial_page_model.get_selected() == "app_page"
91100
assert not app.sort_running_check.get_active()
101+
assert app.show_recent_check.get_active()
92102

93103
app.starting_page_combo.set_active_id("Favorites")
104+
app.show_recent_check.set_active(False)
94105

95106
qapp.expected_calls[
96107
("dom0", "admin.vm.feature.Set", "menu-initial-page", b"favorites_page")
97108
] = b"0\0"
109+
qapp.expected_calls[
110+
("dom0", "admin.vm.feature.Set", "menu-disable-recent", b"1")
111+
] = b"0\0"
98112

99113
app._save()

0 commit comments

Comments
 (0)