Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Sep 5, 2023
1 parent f754c80 commit b109548
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion novelwriter/gui/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, mainGui: GuiMain) -> None:
iconSize = QSize(iPx, iPx)
self.setContentsMargins(0, 0, 0, 0)

# Actions
# Buttons
self.tbProject = QToolButton(self)
self.tbProject.setToolTip(self.tr("Project Tree View"))
self.tbProject.setIconSize(iconSize)
Expand Down
10 changes: 5 additions & 5 deletions novelwriter/guimain.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(self) -> None:
self.itemDetails = GuiItemDetails(self)
self.outlineView = GuiOutlineView(self)
self.mainMenu = GuiMainMenu(self)
self.viewsBar = GuiSideBar(self)
self.sideBar = GuiSideBar(self)

# Project Tree Stack
self.projStack = QStackedWidget(self)
Expand Down Expand Up @@ -224,7 +224,7 @@ def __init__(self) -> None:

# Assemble Main Window Elements
self.mainBox = QHBoxLayout(self)
self.mainBox.addWidget(self.viewsBar)
self.mainBox.addWidget(self.sideBar)
self.mainBox.addWidget(self.mainStack)
self.mainBox.setContentsMargins(0, 0, 0, 0)
self.mainBox.setSpacing(0)
Expand All @@ -244,7 +244,7 @@ def __init__(self) -> None:
SHARED.projectStatusMessage.connect(self.mainStatus.setStatusMessage)
SHARED.spellLanguageChanged.connect(self.mainStatus.setLanguage)

self.viewsBar.viewChangeRequested.connect(self._changeView)
self.sideBar.viewChangeRequested.connect(self._changeView)

self.projView.selectedItemChanged.connect(self.itemDetails.updateViewBox)
self.projView.openDocumentRequest.connect(self._openDocument)
Expand Down Expand Up @@ -880,7 +880,7 @@ def showPreferencesDialog(self) -> None:
SHARED.theme.loadTheme()
self.docEditor.updateTheme()
self.docViewer.updateTheme()
self.viewsBar.updateTheme()
self.sideBar.updateTheme()
self.projView.updateTheme()
self.novelView.updateTheme()
self.outlineView.updateTheme()
Expand Down Expand Up @@ -1154,7 +1154,7 @@ def toggleFocusMode(self) -> bool:
self.treePane.setVisible(isVisible)
self.mainStatus.setVisible(isVisible)
self.mainMenu.setVisible(isVisible)
self.viewsBar.setVisible(isVisible)
self.sideBar.setVisible(isVisible)

hideDocFooter = self.isFocusMode and CONFIG.hideFocusFooter
self.docEditor.docFooter.setVisible(not hideDocFooter)
Expand Down
27 changes: 15 additions & 12 deletions tests/test_gui/test_gui_guimain.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def testGuiMain_ProjectBlocker(nwGUI):

@pytest.mark.gui
def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, prjLipsum):
"""Test the handling of launch tasks.
"""
"""Test the handling of launch tasks."""
monkeypatch.setattr(GuiProjectLoad, "exec_", lambda *a: None)
monkeypatch.setattr(GuiProjectLoad, "result", lambda *a: QDialog.Accepted)
CONFIG.lastNotes = "0x0"
Expand Down Expand Up @@ -140,8 +139,7 @@ def testGuiMain_NewProject(monkeypatch, nwGUI, projPath):

@pytest.mark.gui
def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
"""Test handling of project tree items based on GUI focus states.
"""
"""Test handling of project tree items based on GUI focus states."""
buildTestProject(nwGUI, projPath)

sHandle = "000000000000f"
Expand Down Expand Up @@ -190,8 +188,7 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):

@pytest.mark.gui
def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
"""Test the document editor.
"""
"""Test the document editor."""
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True)
monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *a: True)
monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True))
Expand Down Expand Up @@ -555,9 +552,8 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):


@pytest.mark.gui
def testGuiMain_FocusFullMode(qtbot, nwGUI, projPath, mockRnd):
"""Test toggling focus mode in main window.
"""
def testGuiMain_Features(qtbot, nwGUI, projPath, mockRnd):
"""Test various features of the main window."""
buildTestProject(nwGUI, projPath)
assert nwGUI.isFocusMode is False

Expand All @@ -576,15 +572,15 @@ def testGuiMain_FocusFullMode(qtbot, nwGUI, projPath, mockRnd):
assert nwGUI.treePane.isVisible() is False
assert nwGUI.mainStatus.isVisible() is False
assert nwGUI.mainMenu.isVisible() is False
assert nwGUI.viewsBar.isVisible() is False
assert nwGUI.sideBar.isVisible() is False
assert nwGUI.splitView.isVisible() is False

# Disable focus mode
assert nwGUI.toggleFocusMode() is True
assert nwGUI.treePane.isVisible() is True
assert nwGUI.mainStatus.isVisible() is True
assert nwGUI.mainMenu.isVisible() is True
assert nwGUI.viewsBar.isVisible() is True
assert nwGUI.sideBar.isVisible() is True
assert nwGUI.splitView.isVisible() is True

# Full Screen Mode
Expand All @@ -596,6 +592,13 @@ def testGuiMain_FocusFullMode(qtbot, nwGUI, projPath, mockRnd):
nwGUI.toggleFullScreenMode()
assert nwGUI.windowState() & Qt.WindowFullScreen != Qt.WindowFullScreen

# SideBar Menu
# ============

# Just make sure the custom event handler executes and don't fail
nwGUI.sideBar.mSettings.show()
nwGUI.sideBar.mSettings.hide()

# qtbot.stop()

# END Test testGuiMain_FocusFullMode
# END Test testGuiMain_Features

0 comments on commit b109548

Please sign in to comment.