Skip to content

Commit

Permalink
Update unittests for custom Appmenu positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Sep 16, 2024
1 parent 6bc8534 commit f3762c4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions qubes_menu/appmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(self, qapp, dispatcher):
self.highlight_tag: Optional[str] = None

self.tasks = []
self.appmenu_position: str = 'mouse'

def _add_cli_options(self):
self.add_main_option(
Expand Down Expand Up @@ -199,6 +200,7 @@ def reposition(self):
"""
Helper function to reposition Appmenu based on 'menu_position' feature
"""
assert self.main_window
match self.appmenu_position:
case 'top-left':
self.main_window.move(0, 0)
Expand Down
34 changes: 33 additions & 1 deletion qubes_menu/tests/test_appmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_app_menu_conffeatures():
features={'menu-favorites': ''})
qapp._qubes['dom0'].features['menu-initial-page'] = 'favorites_page'
qapp._qubes['dom0'].features['menu-sort-running'] = '1'
qapp._qubes['dom0'].features['menu-position'] = ''
qapp.update_vm_calls()

dispatcher = MockDispatcher(qapp)
Expand All @@ -38,6 +39,7 @@ def test_app_menu_conffeatures():
# check that initial page is correct
assert app_menu.initial_page == "favorites_page"
assert app_menu.sort_running
assert app_menu.appmenu_position == "mouse"


def test_app_menu_conffeatures_default():
Expand All @@ -48,7 +50,8 @@ def test_app_menu_conffeatures_default():
name="test-vm2", qapp=qapp,
features={'menu-favorites': '',
'menu-initial-page': 'fake',
'menu-sort-running': 'fake'})
'menu-sort-running': 'fake',
'menu-position': 'fake'})
qapp.update_vm_calls()

dispatcher = MockDispatcher(qapp)
Expand All @@ -59,6 +62,7 @@ def test_app_menu_conffeatures_default():
# check that default configuration is correct
assert app_menu.initial_page == "app_page"
assert not app_menu.sort_running
assert app_menu.appmenu_position == "mouse"


def test_appmenu_options():
Expand All @@ -68,6 +72,7 @@ def test_appmenu_options():
features={'menu-favorites': ''})
qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page'
qapp._qubes['dom0'].features['menu-sort-running'] = '1'
qapp._qubes['dom0'].features['menu-position'] = 'top-left'
qapp.update_vm_calls()

dispatcher = MockDispatcher(qapp)
Expand All @@ -86,3 +91,30 @@ def test_appmenu_options():

assert app_menu.initial_page == "favorites_page"
assert app_menu.keep_visible
assert app_menu.appmenu_position == "top-left"

def test_appmenu_positioning():
qapp = MockQubesComplete()

qapp._qubes['test-vm2'] = MockQube(name="test-vm2", qapp=qapp,
features={'menu-favorites': ''})
qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page'
qapp._qubes['dom0'].features['menu-sort-running'] = '1'
qapp._qubes['dom0'].features['menu-position'] = ''
qapp.update_vm_calls()

dispatcher = MockDispatcher(qapp)
app_menu = AppMenu(qapp, dispatcher)

app_menu.perform_setup()

app_menu.appmenu_position = "mouse"
app_menu.reposition()
app_menu.appmenu_position = "top-left"
app_menu.reposition()
app_menu.appmenu_position = "top-right"
app_menu.reposition()
app_menu.appmenu_position = "bottom-left"
app_menu.reposition()
app_menu.appmenu_position = "bottom-right"
app_menu.reposition()
7 changes: 7 additions & 0 deletions qubes_menu_settings/test_menu_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_menu_settings_load():
qapp._qubes['dom0'].features['menu-initial-page'] = 'favorites_page'
qapp._qubes['dom0'].features['menu-sort-running'] = '1'
qapp._qubes['dom0'].features['menu-favorites'] = ''
qapp._qubes['dom0'].features['menu-position'] = ''

qapp.update_vm_calls()

Expand All @@ -35,6 +36,7 @@ def test_menu_settings_load():
app.perform_setup()

assert app.initial_page_model.get_selected() == "favorites_page"
assert app.menu_position_model.get_selected() == "mouse"
assert app.sort_running_check.get_active()


Expand All @@ -43,6 +45,7 @@ def test_menu_settings_change():
qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page'
qapp._qubes['dom0'].features['menu-sort-running'] = ''
qapp._qubes['dom0'].features['menu-favorites'] = ''
qapp._qubes['dom0'].features['menu-position'] = 'mouse'

qapp.update_vm_calls()

Expand All @@ -51,13 +54,16 @@ def test_menu_settings_change():
app.perform_setup()

assert app.initial_page_model.get_selected() == "app_page"
assert app.menu_position_model.get_selected() == "mouse"
assert not app.sort_running_check.get_active()

app.starting_page_combo.set_active_id("Search") # the first option is search
app.menu_position_combo.set_active_id("Top Left") # the first option is Top Left
app.sort_running_check.set_active(True)

qapp.expected_calls[('dom0', 'admin.vm.feature.Set', 'menu-sort-running', b'1')] = b'0\0'
qapp.expected_calls[('dom0', 'admin.vm.feature.Set', 'menu-initial-page', b'search_page')] = b'0\0'
qapp.expected_calls[('dom0', 'admin.vm.feature.Set', 'menu-position', b'top-left')] = b'0\0'

app._save()

Expand All @@ -67,6 +73,7 @@ def test_menu_settings_change2():
qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page'
qapp._qubes['dom0'].features['menu-sort-running'] = ''
qapp._qubes['dom0'].features['menu-favorites'] = ''
qapp._qubes['dom0'].features['menu-position'] = 'mouse'

qapp.update_vm_calls()

Expand Down
4 changes: 4 additions & 0 deletions rpm_spec/qubes-desktop-linux-menu.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
/usr/share/icons/hicolor/scalable/apps/qappmenu-pause.svg
/usr/share/icons/hicolor/scalable/apps/qappmenu-shutdown.svg
/usr/share/icons/hicolor/scalable/apps/qappmenu-start.svg
/usr/share/icons/hicolor/scalable/apps/qappmenu-top-left.svg
/usr/share/icons/hicolor/scalable/apps/qappmenu-top-right.svg
/usr/share/icons/hicolor/scalable/apps/qappmenu-bottom-left.svg
/usr/share/icons/hicolor/scalable/apps/qappmenu-bottom-right.svg
/usr/share/icons/hicolor/scalable/apps/appmenu-settings-program-icon.svg
/usr/share/icons/hicolor/scalable/apps/settings-black.svg
/usr/share/icons/hicolor/scalable/apps/settings-blue.svg
Expand Down

0 comments on commit f3762c4

Please sign in to comment.