Daniel Brötzmann pushed to branch gtk4 at gajim / gajim


Commits:
a96ebb76 by wurstsalat at 2024-11-11T23:33:48+01:00
refactor: Preview: Add basic test

- - - - -


1 changed file:

- + test/gtk/ui_test_preview.py


Changes:

=====================================
test/gtk/ui_test_preview.py
=====================================
@@ -0,0 +1,101 @@
+# This file is part of Gajim.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+
+from typing import Any
+
+from unittest.mock import MagicMock
+
+import gi
+
+gi.require_version('Gst', '1.0')
+
+from gi.repository import Gtk
+
+from gajim.common import app
+from gajim.common import configpaths
+from gajim.common import logging_helpers
+from gajim.common.const import CSSPriority
+from gajim.common.preview import PreviewManager
+from gajim.common.settings import Settings
+
+from gajim.gtk.dropdown import GajimDropDown
+from gajim.gtk.dropdown import KeyValueItem
+from gajim.gtk.preview import PreviewWidget
+from gajim.gtk.widgets import GajimAppWindow
+
+from . import util
+
+util.load_style('gajim.css', CSSPriority.APPLICATION)
+
+ACCOUNT = '[email protected]'
+
+PREVIEW_TYPES = {
+    'geo: URI': 'geo:50.3333,24.5555',
+    'Image URL': 
'https://dev.gajim.org/-/project/30/uploads/b2bca3294faaf560d2808715c2803dcc/Screenshot_After_NotHover.png',
+    'PDF URL': 'https://www.rfc-editor.org/rfc/pdfrfc/rfc6120.txt.pdf',
+    'Regular URL': 'https://gajim.org',
+}
+
+
+class TestPreview(GajimAppWindow):
+    def __init__(self) -> None:
+        GajimAppWindow.__init__(
+            self,
+            name='',
+            title=__class__.__name__,
+            default_width=600,
+            default_height=600,
+        )
+
+        box = Gtk.Box(
+            halign=Gtk.Align.CENTER,
+            valign=Gtk.Align.CENTER,
+            orientation=Gtk.Orientation.VERTICAL,
+            spacing=12,
+        )
+        self.set_child(box)
+
+        self._preview_widget = PreviewWidget(ACCOUNT)
+        box.append(self._preview_widget)
+
+        drop_down = GajimDropDown(list(PREVIEW_TYPES.keys()))
+        drop_down.connect('notify::selected', self._on_preview_type_selected)
+        box.append(drop_down)
+
+    def _on_preview_type_selected(self, drop_down: GajimDropDown, *args: Any) 
-> None:
+        selected_type = drop_down.get_selected_item()
+        assert isinstance(selected_type, KeyValueItem)
+        uri_data = PREVIEW_TYPES[selected_type.key]
+
+        is_outgoing = True
+        muc_context = None
+
+        app.preview_manager.create_preview(
+            uri_data, self._preview_widget, is_outgoing, muc_context
+        )
+
+    def _cleanup(self) -> None:
+        pass
+
+
+app.get_client = MagicMock()
+app.window = MagicMock()
+
+logging_helpers.set_loglevels('gajim=DEBUG')
+
+app.settings = Settings(in_memory=True)
+app.settings.init()
+app.settings.add_account(ACCOUNT)
+
+configpaths.set_separation(True)
+configpaths.set_config_root(str(configpaths.get_temp_dir()))
+configpaths.init()
+configpaths.create_paths()
+
+app.preview_manager = PreviewManager()
+
+window = TestPreview()
+window.show()
+
+util.run_app()



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/a96ebb76b45514707ad3e629b39e4ceb23918a83

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/a96ebb76b45514707ad3e629b39e4ceb23918a83
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to