# Copyright 2023 (c) Anna Schumaker. """Tests our Window implementation.""" import unittest import xfstestsdb.gtk.window from gi.repository import Gtk from gi.repository import Adw class TestWindow(unittest.TestCase): """Test case for our Window subclass.""" def setUp(self): """Set up common variables.""" self.window = xfstestsdb.gtk.window.Window() def test_init(self): """Check that the Window is set up correctly.""" self.assertIsInstance(self.window, Adw.Window) self.assertEqual(self.window.props.default_height, 1000) self.assertEqual(self.window.props.default_width, 1600) self.assertTrue(self.window.has_css_class("devel")) self.assertIsInstance(self.window.props.content, Gtk.Box) self.assertEqual(self.window.props.content.get_orientation(), Gtk.Orientation.VERTICAL) def test_headerbar(self): """Test the headerbar property.""" self.assertIsInstance(self.window.headerbar, Adw.HeaderBar) self.assertEqual(self.window.props.content.get_first_child(), self.window.headerbar) self.assertTrue(self.window.headerbar.has_css_class("flat")) def test_title_widget(self): """Test the title widget property.""" self.assertIsInstance(self.window.title, Adw.WindowTitle) self.assertEqual(self.window.title.props.title, "xfstestsdb gtk") self.assertEqual(self.window.headerbar.props.title_widget, self.window.title) def test_splitview(self): """Check that the Window's splitview is set up correctly.""" self.assertIsInstance(self.window._splitview, Adw.OverlaySplitView) self.assertEqual(self.window.headerbar.get_next_sibling(), self.window._splitview) self.assertTrue(self.window._splitview.props.collapsed) def test_show_sidebar(self): """Test the window show sidebar button.""" self.assertIsInstance(self.window._show_sidebar, Gtk.ToggleButton) self.assertEqual(self.window._show_sidebar.get_ancestor(Adw.HeaderBar), self.window.headerbar) self.assertEqual(self.window._show_sidebar.props.icon_name, "sidebar-show") self.assertFalse(self.window.show_sidebar) self.assertFalse(self.window._show_sidebar.props.active) self.assertFalse(self.window._splitview.props.show_sidebar) self.window._show_sidebar.props.active = True self.assertTrue(self.window._splitview.props.show_sidebar) self.assertTrue(self.window.show_sidebar) self.window.show_sidebar = False self.assertFalse(self.window._show_sidebar.props.active) self.assertFalse(self.window._splitview.props.show_sidebar) window2 = xfstestsdb.gtk.window.Window(show_sidebar=True) self.assertTrue(window2.show_sidebar) self.assertTrue(window2._show_sidebar.props.active) self.assertTrue(window2._splitview.props.show_sidebar) def test_content(self): """Test the window content property.""" self.assertIsNone(self.window.child) self.window.child = Gtk.Label() self.assertEqual(self.window._splitview.props.content, self.window.child) label = Gtk.Label() window2 = xfstestsdb.gtk.window.Window(child=label) self.assertEqual(window2.child, label) self.assertEqual(window2._splitview.props.content, label) def test_sidebar(self): """Test the window sidebar property.""" self.assertIsNone(self.window.sidebar) self.window.sidebar = Gtk.Label() self.assertEqual(self.window._splitview.props.sidebar, self.window.sidebar) label = Gtk.Label() window2 = xfstestsdb.gtk.window.Window(sidebar=label) self.assertEqual(window2.sidebar, label) self.assertEqual(window2._splitview.props.sidebar, label) def test_runid(self): """Test the window runid property.""" self.assertEqual(self.window.runid, 0) self.assertEqual(self.window.title.props.subtitle, "") self.window.runid = 3 self.assertEqual(self.window.title.props.subtitle, "runid #3") self.window.runid = 0 self.assertEqual(self.window.title.props.subtitle, "")