diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/fixtures/workspace-cycle.js | 54 | ||||
| -rw-r--r-- | tests/test_canonical.py | 1 | ||||
| -rw-r--r-- | tests/test_canonical_desktop.py | 30 | ||||
| -rw-r--r-- | tests/test_workspace_cycle.py | 38 |
4 files changed, 115 insertions, 8 deletions
diff --git a/tests/fixtures/workspace-cycle.js b/tests/fixtures/workspace-cycle.js new file mode 100644 index 0000000..13e1bc7 --- /dev/null +++ b/tests/fixtures/workspace-cycle.js @@ -0,0 +1,54 @@ +import assert from "node:assert/strict"; + +const bindings = new Map(); +const Extension = class { + getSettings() { + return {}; + } +}; +const Meta = { KeyBindingFlags: { NONE: 0 } }; +const Shell = { ActionMode: { NORMAL: 1, OVERVIEW: 2 } }; +const Main = { + wm: { + addKeybinding(name, settings, flags, mode, callback) { + assert.equal(mode, 3); + bindings.set(name, callback); + }, + removeKeybinding(name) { + bindings.delete(name); + }, + }, +}; +let active = 0; +let activations = 0; +global.workspace_manager = { + n_workspaces: 3, + get_active_workspace_index: () => active, + get_workspace_by_index: (index) => ({ + activate(time) { + assert.equal(time, 123); + active = index; + activations++; + }, + }), +}; +global.get_current_time = () => 123; + +// EXTENSION + +const extension = new WorkspaceCycle(); +extension.enable(); +bindings.get("previous-workspace")(); +assert.equal(active, 2); +bindings.get("next-workspace")(); +assert.equal(active, 0); +bindings.get("next-workspace")(); +assert.equal(active, 1); +global.workspace_manager.n_workspaces = 1; +extension.cycle(1); +assert.equal(activations, 3); +extension.disable(); +assert.equal(bindings.size, 0); +extension.enable(); +assert.equal(bindings.size, 2); +extension.disable(); diff --git a/tests/test_canonical.py b/tests/test_canonical.py index 724b922..317fe98 100644 --- a/tests/test_canonical.py +++ b/tests/test_canonical.py @@ -224,6 +224,7 @@ class RoleTests(unittest.TestCase): ".local/bin/rqr", ".local/share/gnome-shell/extensions/corporate-panel@dotfiles/extension.js", ".local/share/gnome-shell/extensions/external-display@dotfiles/extension.js", + ".local/share/gnome-shell/extensions/workspace-cycle@dotfiles/extension.js", ]: self.assertIn(required, files) for path in files: diff --git a/tests/test_canonical_desktop.py b/tests/test_canonical_desktop.py index 146ae9f..039948f 100644 --- a/tests/test_canonical_desktop.py +++ b/tests/test_canonical_desktop.py @@ -60,17 +60,31 @@ class DesktopTests(unittest.TestCase): with patch.object(desktop, "write_key") as write: desktop.tiling({}) schema = "org.gnome.shell.extensions.o-tiling" - for key in [ - "tile-enter", - "toggle-tiling", - "tile-orientation", - "pop-workspace-up", - "pop-workspace-down", - ]: + for key in ["toggle-tiling", "pop-workspace-up", "pop-workspace-down"]: write.assert_any_call(schema, key, [], {}) write.assert_any_call(schema, "new-window-placement", "focused", {}) - write.assert_any_call(schema, "focus-right", ["<Super>Right"], {}) + write.assert_any_call(schema, "focus-right", ["<Super>l"], {}) write.assert_any_call(schema, "tile-move-down-global", ["<Super><Shift>j"], {}) + write.assert_any_call(schema, "tile-enter", ["<Super>r"], {}) + write.assert_any_call(schema, "tile-resize-left", ["h"], {}) + + def test_desktop_bindings_release_sway_keys_and_keep_lock(self): + with patch.object(desktop, "write_key") as write: + desktop.desktop_bindings({}) + wm = "org.gnome.desktop.wm.keybindings" + media = "org.gnome.settings-daemon.plugins.media-keys" + write.assert_any_call(wm, "switch-applications", ["<Alt>Tab"], {}) + write.assert_any_call(wm, "switch-input-source", [], {}) + write.assert_any_call(wm, "switch-input-source-backward", [], {}) + write.assert_any_call(media, "screensaver", ["<Super><Shift>s"], {}) + write.assert_any_call(media, "mic-mute", ["<Super>m"], {}) + + def test_workspace_cycle_keys_are_configured(self): + with patch.object(desktop, "write_key") as write: + desktop.workspaces({}) + schema = "org.gnome.shell.extensions.workspace-cycle" + write.assert_any_call(schema, "next-workspace", ["<Super>Tab"], {}) + write.assert_any_call(schema, "previous-workspace", ["<Super><Shift>Tab"], {}) def test_clipboard_shortcut_preserves_other_display_bindings(self): settings = MagicMock() diff --git a/tests/test_workspace_cycle.py b/tests/test_workspace_cycle.py new file mode 100644 index 0000000..09dbc2a --- /dev/null +++ b/tests/test_workspace_cycle.py @@ -0,0 +1,38 @@ +import json +import subprocess +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +EXTENSION = ROOT / "dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles" + + +class WorkspaceCycleTests(unittest.TestCase): + def test_schema_and_metadata(self): + metadata = json.loads((EXTENSION / "metadata.json").read_text()) + self.assertEqual(metadata["uuid"], "workspace-cycle@dotfiles") + self.assertEqual(metadata["shell-version"], ["50"]) + subprocess.run( + [ + "glib-compile-schemas", + "--strict", + "--dry-run", + str(EXTENSION / "schemas"), + ], + check=True, + ) + + def test_cycle_wraps_in_both_directions_and_releases_keys(self): + source = "\n".join( + line + for line in (EXTENSION / "extension.js").read_text().splitlines() + if not line.startswith("import ") + ) + source = source.replace("export default class", "class") + harness = (ROOT / "tests/fixtures/workspace-cycle.js").read_text() + subprocess.run( + ["node", "--input-type=module"], + input=harness.replace("// EXTENSION", source), + text=True, + check=True, + ) |
