diff --git a/emmental/__init__.py b/emmental/__init__.py index 2873e0e..4f5c26e 100644 --- a/emmental/__init__.py +++ b/emmental/__init__.py @@ -206,11 +206,14 @@ class Application(Adw.Application): now_playing=self.build_now_playing(), sidebar=self.build_sidebar(), tracklist=self.build_tracklist()) + win.bind_property("show-sidebar", win.header, "show-sidebar", + GObject.BindingFlags.BIDIRECTIONAL) win.bind_property("user-editing", win.now_playing, "editing") for (setting, property) in [("window.width", "default-width"), ("window.height", "default-height"), - ("now-playing.size", "now-playing-size")]: + ("now-playing.size", "now-playing-size"), + ("sidebar.show", "show-sidebar")]: self.db.settings.bind_setting(setting, win, property) self.__add_accelerators(win.accelerators) diff --git a/tests/test_emmental.py b/tests/test_emmental.py index 30db1e3..be94256 100644 --- a/tests/test_emmental.py +++ b/tests/test_emmental.py @@ -292,3 +292,17 @@ class TestEmmental(unittest.TestCase): win.header.bg_volume = 0.5 self.assertTrue(player.bg_enabled) self.assertEqual(player.bg_volume, 0.5) + + @unittest.mock.patch("sys.stdout", new_callable=io.StringIO) + def test_show_sidebar(self, mock_stdout: io.StringIO): + """Test showing the sidebar.""" + self.application.db = emmental.db.Connection() + self.application.factory = emmental.playlist.Factory( + self.application.db) + self.application.player = emmental.audio.Player() + win = self.application.build_window() + + win.show_sidebar = True + self.assertTrue(win.header.show_sidebar) + win.header.show_sidebar = False + self.assertFalse(win.show_sidebar) diff --git a/tests/test_settings.py b/tests/test_settings.py index cfebae1..6c710e5 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -38,6 +38,16 @@ class TestSettings(unittest.TestCase): win = self.app.build_window() self.assertEqual(win.get_default_size(), (100, 200)) + def test_save_show_sidebar(self, mock_stdout: io.StringIO): + """Check saving and loading the show-sidebar property.""" + self.assertFalse(self.settings["sidebar.show"]) + + self.win.show_sidebar = True + self.assertTrue(self.settings["sidebar.show"]) + + win = self.app.build_window() + self.assertTrue(win.show_sidebar) + def test_save_volume(self, mock_stdout: io.StringIO): """Check saving and loading volume from the database.""" self.assertEqual(self.settings["audio.volume"], 1.0)