# Copyright 2023 (c) Anna Schumaker. """Tests our adaptable layout widget.""" import unittest import emmental.layout from gi.repository import Gtk from gi.repository import Adw class TestLayout(unittest.TestCase): """Test case for our adaptable layout.""" def setUp(self): """Set up common variables.""" self.layout = emmental.layout.Layout() def test_init(self): """Check that the layout is set up properly.""" self.assertIsInstance(self.layout, Adw.Bin) self.assertIsInstance(self.layout._split_view, Adw.OverlaySplitView) self.assertTrue(self.layout._split_view.props.collapsed) def test_wide_view(self): """Test the layout when we have a wide window.""" self.assertFalse(self.layout.wide_view) self.assertEqual(self.layout.props.child, self.layout._split_view) self.layout.wide_view = True self.assertFalse(self.layout._split_view.props.collapsed) def test_content(self): """Test the content widget property.""" self.assertIsNone(self.layout.content) widget = Gtk.Label() self.layout.content = widget self.assertEqual(self.layout._split_view.props.content, widget) self.assertEqual(self.layout.content, widget) widget2 = Gtk.Label() layout2 = emmental.layout.Layout(content=widget2) self.assertEqual(layout2.content, widget2) def test_sidebar(self): """Test the sidebar widget property.""" self.assertIsNone(self.layout.sidebar) widget = Gtk.Label() self.layout.sidebar = widget self.assertEqual(self.layout._split_view.props.sidebar, widget) self.assertEqual(self.layout.sidebar, widget) widget2 = Gtk.Label() layout2 = emmental.layout.Layout(sidebar=widget2) self.assertEqual(layout2.sidebar, widget2) def test_show_sidebar(self): """Test the show-sidebar property.""" self.assertFalse(self.layout.show_sidebar) self.assertFalse(self.layout._split_view.props.show_sidebar) self.layout.show_sidebar = True self.assertTrue(self.layout._split_view.props.show_sidebar) self.layout._split_view.props.show_sidebar = False self.assertFalse(self.layout.show_sidebar)