# 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_constants(self): """Check constant variables.""" self.assertEqual(emmental.layout.MIN_WIDTH, Adw.BreakpointConditionLengthType.MIN_WIDTH) 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) @unittest.mock.patch("gi.repository.Adw.Breakpoint.add_setter") def test_breakpoints(self, mock_add_setter: unittest.mock.Mock): """Test the layout breakpoints property.""" points = self.layout.breakpoints self.assertEqual(len(points), 1) self.assertIsInstance(points[0], Adw.Breakpoint) condition = points[0].props.condition self.assertIsInstance(condition, Adw.BreakpointCondition) self.assertEqual(condition.to_string(), "min-width: 1000sp") mock_add_setter.assert_called_once() args = mock_add_setter.mock_calls[0].args self.assertEqual(args[0], self.layout) self.assertEqual(args[1], "wide-view") self.assertTrue(args[2].get_boolean())