Anna Schumaker
51096104ce
It doesn't have any children yet, the application will save its size when the user resizes it. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
139 lines
5.9 KiB
Python
139 lines
5.9 KiB
Python
# Copyright 2022 (c) Anna Schumaker.
|
|
"""Tests our application window."""
|
|
import unittest
|
|
import emmental.window
|
|
from gi.repository import Adw
|
|
from gi.repository import Gtk
|
|
|
|
|
|
class TestWindow(unittest.TestCase):
|
|
"""Test case for our custom Gtk.Window."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.window = emmental.window.Window("Test 1.2.3")
|
|
|
|
def tearDown(self):
|
|
"""Clean up."""
|
|
self.window.close()
|
|
|
|
def test_init(self):
|
|
"""Check that the window gets set up properly."""
|
|
self.assertIsInstance(self.window, Adw.Window)
|
|
self.assertIsInstance(self.window._box, Gtk.Box)
|
|
self.assertIsInstance(self.window._header, Adw.Bin)
|
|
self.assertIsInstance(self.window._outer_pane, Gtk.Paned)
|
|
self.assertIsInstance(self.window._inner_pane, Gtk.Paned)
|
|
self.assertIsInstance(self.window._toast, Adw.ToastOverlay)
|
|
self.assertTrue(self.window.has_css_class("devel"))
|
|
|
|
self.assertEqual(self.window.get_icon_name(), "emmental")
|
|
self.assertEqual(self.window.get_title(), "Test 1.2.3")
|
|
self.assertEqual(self.window.get_default_size(), (1600, 900))
|
|
|
|
def test_content(self):
|
|
"""Check that the Window content is set up properly."""
|
|
self.assertEqual(self.window._box.get_orientation(),
|
|
Gtk.Orientation.VERTICAL)
|
|
self.assertEqual(self.window._box.get_spacing(), 0)
|
|
self.assertEqual(self.window.get_content(), self.window._box)
|
|
self.assertEqual(self.window._box.get_first_child(),
|
|
self.window._header)
|
|
self.assertEqual(self.window._header.get_next_sibling(),
|
|
self.window._toast)
|
|
self.assertEqual(self.window._toast.get_child(),
|
|
self.window._outer_pane)
|
|
self.assertEqual(self.window._outer_pane.get_end_child(),
|
|
self.window._inner_pane)
|
|
self.assertTrue(self.window._outer_pane.has_css_class(
|
|
"emmental-padding"))
|
|
|
|
subtests = [(self.window._outer_pane, Gtk.Orientation.HORIZONTAL),
|
|
(self.window._inner_pane, Gtk.Orientation.VERTICAL)]
|
|
for pane, orientation in subtests:
|
|
self.assertEqual(pane.get_orientation(), orientation)
|
|
self.assertFalse(pane.get_shrink_start_child())
|
|
self.assertFalse(pane.get_resize_start_child())
|
|
self.assertTrue(pane.get_hexpand())
|
|
self.assertTrue(pane.get_vexpand())
|
|
self.assertTrue(pane.has_css_class("emmental-pane"))
|
|
|
|
def test_header(self):
|
|
"""Check setting a widget to the header area."""
|
|
self.assertIsNone(self.window.header)
|
|
self.window.header = Gtk.Label()
|
|
self.assertEqual(self.window._header.get_child(), self.window.header)
|
|
|
|
window2 = emmental.window.Window(version="1.2.3", header=Gtk.Label())
|
|
self.assertIsInstance(window2.header, Gtk.Label)
|
|
self.assertEqual(window2._header.get_child(), window2.header)
|
|
|
|
def test_sidebar(self):
|
|
"""Check setting a widget to the sidebar area."""
|
|
self.assertIsNone(self.window.sidebar)
|
|
self.window.sidebar = Gtk.Label()
|
|
self.assertEqual(self.window._outer_pane.get_start_child(),
|
|
self.window.sidebar)
|
|
|
|
window2 = emmental.window.Window(version="1.2.3", sidebar=Gtk.Label())
|
|
self.assertIsInstance(window2.sidebar, Gtk.Label)
|
|
self.assertEqual(window2._outer_pane.get_start_child(),
|
|
window2.sidebar)
|
|
|
|
def test_now_playing(self):
|
|
"""Check setting a widget to the now_playing area."""
|
|
self.assertIsNone(self.window.now_playing)
|
|
self.window.now_playing = Gtk.Label()
|
|
self.assertEqual(self.window._inner_pane.get_start_child(),
|
|
self.window.now_playing)
|
|
|
|
window2 = emmental.window.Window(version="1.2.3",
|
|
now_playing=Gtk.Label())
|
|
self.assertIsInstance(window2.now_playing, Gtk.Label)
|
|
self.assertEqual(window2._inner_pane.get_start_child(),
|
|
window2.now_playing)
|
|
|
|
def test_now_playing_size(self):
|
|
"""Check setting the size of the now playing area."""
|
|
self.assertEqual(self.window.now_playing_size, 250)
|
|
self.assertEqual(self.window._inner_pane.get_position(), 250)
|
|
|
|
self.window.now_playing_size = 100
|
|
self.assertEqual(self.window.now_playing_size, 100)
|
|
self.assertEqual(self.window._inner_pane.get_position(), 100)
|
|
|
|
self.window._inner_pane.set_position(200)
|
|
self.assertEqual(self.window.now_playing_size, 200)
|
|
self.assertEqual(self.window._inner_pane.get_position(), 200)
|
|
|
|
def test_tracklist(self):
|
|
"""Check setting a widget to the tracklist area."""
|
|
self.assertIsNone(self.window.tracklist)
|
|
self.window.tracklist = Gtk.Label()
|
|
self.assertEqual(self.window._inner_pane.get_end_child(),
|
|
self.window.tracklist)
|
|
|
|
window2 = emmental.window.Window(version="1.2.3",
|
|
tracklist=Gtk.Label())
|
|
self.assertIsInstance(window2.tracklist, Gtk.Label)
|
|
self.assertEqual(window2._inner_pane.get_end_child(),
|
|
window2.tracklist)
|
|
|
|
def test_post_toast(self):
|
|
"""Test posting a Toast message to the window."""
|
|
toast = self.window.post_toast("Test Toast")
|
|
self.assertIsInstance(toast, Adw.Toast)
|
|
self.assertEqual(toast.get_title(), "Test Toast")
|
|
|
|
def test_close(self):
|
|
"""Test calling close()."""
|
|
with unittest.mock.patch.object(Gtk.Window, "close") as mock_close:
|
|
self.window.close(1, 2, 3, 4, 5)
|
|
mock_close.assert_called()
|
|
|
|
def test_present(self):
|
|
"""Test calling present()."""
|
|
with unittest.mock.patch.object(Gtk.Window, "present") as mock_present:
|
|
self.window.present(1, 2, 3, 4, 5)
|
|
mock_present.assert_called()
|