Anna Schumaker
4cd1e89493
This dialog is used to manually edit the settings in the database. I bind the properties in such a way that changes are seen instantly. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
144 lines
5.8 KiB
Python
144 lines
5.8 KiB
Python
# Copyright 2022 (c) Anna Schumaker.
|
|
"""Tests our Settings dialog."""
|
|
import unittest.mock
|
|
import emmental.header.settings
|
|
import emmental.entry
|
|
import tests.util
|
|
from gi.repository import Gtk
|
|
from gi.repository import Adw
|
|
|
|
|
|
class TestValueRow(tests.util.TestCase):
|
|
"""Test the settings Value Row."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
super().setUp()
|
|
self.listitem = Gtk.ListItem()
|
|
self.row = emmental.header.settings.ValueRow(self.listitem)
|
|
|
|
def make_setting(self, name: str, type: str, value: any) -> None:
|
|
"""Create a setting in the database."""
|
|
setting = self.sql.settings.create(name, type, value)
|
|
self.listitem.get_item = unittest.mock.Mock(return_value=setting)
|
|
|
|
def test_init(self):
|
|
"""Tetst that the ValueRow is configured correctly."""
|
|
self.assertIsInstance(self.row, emmental.factory.ListRow)
|
|
self.assertIsNone(self.row.child)
|
|
|
|
def test_boolean_setting(self):
|
|
"""Test configuring the row for a boolean setting."""
|
|
self.make_setting("test.bool", "gboolean", True)
|
|
|
|
self.row.bind()
|
|
self.assertIsInstance(self.row.child, Gtk.Switch)
|
|
self.assertEqual(self.row.child.get_halign(), Gtk.Align.START)
|
|
self.assertTrue(self.row.child.get_active())
|
|
|
|
def test_string_setting(self):
|
|
"""Test configuring the row for a string setting."""
|
|
self.make_setting("test.string", "gchararray", "Test Text")
|
|
|
|
self.row.bind()
|
|
self.assertIsInstance(self.row.child, emmental.entry.String)
|
|
self.assertFalse(self.row.child.get_has_frame())
|
|
self.assertEqual(self.row.child.value, "Test Text")
|
|
|
|
def test_integer_setting(self):
|
|
"""Test configuring the row for an integer setting."""
|
|
self.make_setting("test.int", "gint", 42)
|
|
|
|
self.row.bind()
|
|
self.assertIsInstance(self.row.child, emmental.entry.Integer)
|
|
self.assertFalse(self.row.child.get_has_frame())
|
|
self.assertEqual(self.row.child.value, 42)
|
|
|
|
def test_float_setting(self):
|
|
"""Test configuring the row for a float setting."""
|
|
self.make_setting("test.float", "gdouble", 1.234)
|
|
|
|
self.row.bind()
|
|
self.assertIsInstance(self.row.child, emmental.entry.Float)
|
|
self.assertFalse(self.row.child.get_has_frame())
|
|
self.assertEqual(self.row.child.value, 1.234)
|
|
|
|
|
|
class TestWindow(tests.util.TestCase):
|
|
"""Test the Settings Window."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
super().setUp()
|
|
self.window = emmental.header.settings.Window(sql=self.sql)
|
|
|
|
def test_init(self):
|
|
"""Test that the Settings Window is configured properly."""
|
|
self.assertIsInstance(self.window, Adw.Window)
|
|
self.assertEqual(self.window.get_default_size(), (500, 500))
|
|
self.assertEqual(self.window.get_title(), "Emmental Settings")
|
|
self.assertEqual(self.window.get_icon_name(), "settings")
|
|
self.assertTrue(self.window.get_hide_on_close())
|
|
self.assertTrue(self.window.has_css_class("devel"))
|
|
|
|
def test_content(self):
|
|
"""Test that the Window content was set up properly."""
|
|
box = self.window.get_content()
|
|
self.assertIsInstance(box, Gtk.Box)
|
|
self.assertEqual(box.get_orientation(), Gtk.Orientation.VERTICAL)
|
|
self.assertEqual(box.get_spacing(), 0)
|
|
|
|
def test_headerbar(self):
|
|
"""Test that the Window headerbar was set up properly."""
|
|
self.assertIsInstance(self.window._header, Gtk.HeaderBar)
|
|
self.assertEqual(self.window.get_content().get_first_child(),
|
|
self.window._header)
|
|
|
|
def test_search(self):
|
|
"""Test the search entry widget."""
|
|
self.assertIsInstance(self.window._search, emmental.entry.Filter)
|
|
self.assertEqual(self.window._search.get_placeholder_text(),
|
|
"type to filter settings")
|
|
self.assertEqual(self.window._header.get_title_widget(),
|
|
self.window._search)
|
|
|
|
self.window._search.set_text("abcde")
|
|
with unittest.mock.patch.object(self.sql.settings,
|
|
"filter") as mock_filter:
|
|
self.window._search.emit("search-changed")
|
|
mock_filter.assert_called_with("*abcde*")
|
|
|
|
def test_columnview(self):
|
|
"""Test the columnview widget."""
|
|
self.assertIsInstance(self.window._scroll, Gtk.ScrolledWindow)
|
|
self.assertIsInstance(self.window._selection, Gtk.NoSelection)
|
|
self.assertIsInstance(self.window._view, Gtk.ColumnView)
|
|
|
|
self.assertEqual(self.window._scroll.get_policy(),
|
|
(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC))
|
|
|
|
self.assertEqual(self.window._view.get_model(), self.window._selection)
|
|
self.assertEqual(self.window._selection.get_model(), self.sql.settings)
|
|
self.assertTrue(self.window._view.get_show_row_separators())
|
|
|
|
self.assertEqual(self.window._header.get_next_sibling(),
|
|
self.window._scroll)
|
|
self.assertEqual(self.window._scroll.get_child(), self.window._view)
|
|
|
|
def test_columns(self):
|
|
"""Test the view's columns."""
|
|
columns = self.window._view.get_columns()
|
|
self.assertEqual(len(columns), 2)
|
|
|
|
self.assertIsInstance(columns[0].get_factory(),
|
|
emmental.factory.InscriptionFactory)
|
|
self.assertEqual(columns[0].get_title(), "Key")
|
|
self.assertEqual(columns[0].get_fixed_width(), 400)
|
|
|
|
self.assertIsInstance(columns[1].get_factory(),
|
|
emmental.factory.Factory)
|
|
self.assertEqual(columns[1].get_factory().row_type,
|
|
emmental.header.settings.ValueRow)
|
|
self.assertEqual(columns[1].get_title(), "Value")
|
|
self.assertEqual(columns[1].get_fixed_width(), 100)
|