Add test coverage of new features, and some other places
This commit is contained in:
@@ -52,7 +52,7 @@ class NPagedSideBar(QToolBar):
|
||||
|
||||
self._labelCol = None
|
||||
self._spacerHeight = self.fontMetrics().height() // 2
|
||||
self._buttons: dict[int, _NPagedToolButton] = {}
|
||||
self._buttons: dict[int, _PagedToolButton] = {}
|
||||
|
||||
self._group = QButtonGroup(self)
|
||||
self._group.setExclusive(True)
|
||||
@@ -67,7 +67,7 @@ class NPagedSideBar(QToolBar):
|
||||
|
||||
return
|
||||
|
||||
def button(self, buttonId: int) -> _NPagedToolButton:
|
||||
def button(self, buttonId: int) -> _PagedToolButton:
|
||||
"""Return a specific button."""
|
||||
return self._buttons[buttonId]
|
||||
|
||||
@@ -85,7 +85,7 @@ class NPagedSideBar(QToolBar):
|
||||
|
||||
def addButton(self, text: str, buttonId: int = -1) -> QAction:
|
||||
"""Add a new button to the toolbar."""
|
||||
button = _NPagedToolButton(self)
|
||||
button = _PagedToolButton(self)
|
||||
button.setText(text)
|
||||
|
||||
action = self.insertWidget(self._stretchAction, button)
|
||||
@@ -113,7 +113,7 @@ class NPagedSideBar(QToolBar):
|
||||
return
|
||||
|
||||
|
||||
class _NPagedToolButton(QToolButton):
|
||||
class _PagedToolButton(QToolButton):
|
||||
|
||||
__slots__ = ("_bH", "_tM", "_lM", "_cR", "_aH")
|
||||
|
||||
@@ -154,7 +154,7 @@ class _NPagedToolButton(QToolButton):
|
||||
height = self.height()
|
||||
palette = self.palette()
|
||||
|
||||
if opt.state & QtMouseOver == QtMouseOver:
|
||||
if opt.state & QtMouseOver == QtMouseOver: # pragma: no cover
|
||||
backCol = palette.base()
|
||||
paint.setBrush(backCol)
|
||||
paint.setOpacity(0.75)
|
||||
|
||||
@@ -464,10 +464,11 @@ def testFmtToQTextDocument_TextCharFormats(mockGUI):
|
||||
"With sub[sub]script[/sub] text\n\n"
|
||||
"With \u201cdialog\u201d text\n\n"
|
||||
"With |<alternative dialog>| text\n\n"
|
||||
"With http://example.com text\n\n"
|
||||
)
|
||||
doc.tokenizeText()
|
||||
doc.doConvert()
|
||||
assert doc.document.blockCount() == 10
|
||||
assert doc.document.blockCount() == 11
|
||||
|
||||
# 0: Scene
|
||||
block = doc.document.findBlockByNumber(0)
|
||||
@@ -563,6 +564,18 @@ def testFmtToQTextDocument_TextCharFormats(mockGUI):
|
||||
cFmt = charFmtInBlock(block, 28)
|
||||
assert cFmt.foreground() == THEME.text
|
||||
|
||||
# 10: Url
|
||||
block = doc.document.findBlockByNumber(10)
|
||||
assert block.text() == "With http://example.com text"
|
||||
cFmt = charFmtInBlock(block, 1)
|
||||
assert cFmt.foreground() == THEME.text
|
||||
cFmt = charFmtInBlock(block, 6)
|
||||
assert cFmt.foreground() == THEME.link
|
||||
assert cFmt.isAnchor() is True
|
||||
assert cFmt.anchorHref() == "http://example.com"
|
||||
cFmt = charFmtInBlock(block, 24)
|
||||
assert cFmt.foreground() == THEME.text
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testFmtToQTextDocument_Footnotes(mockGUI):
|
||||
|
||||
@@ -20,9 +20,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtGui import QTextBlock, QTextCursor
|
||||
from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtGui import QDesktopServices, QTextBlock, QTextCursor
|
||||
from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
@@ -34,6 +37,35 @@ from novelwriter.types import QtKeepAnchor, QtMoveRight
|
||||
from tests.tools import C, buildTestProject, writeFile
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMainMenu_Slots(qtbot, monkeypatch, nwGUI, projPath):
|
||||
"""Test the main menu slots."""
|
||||
buildTestProject(nwGUI, projPath)
|
||||
|
||||
# Open URL
|
||||
with monkeypatch.context() as mp:
|
||||
openUrl = MagicMock()
|
||||
mp.setattr(QDesktopServices, "openUrl", openUrl)
|
||||
nwGUI.mainMenu._openWebsite("http://www.example.com")
|
||||
assert openUrl.called is True
|
||||
assert openUrl.call_args[0][0] == QUrl("http://www.example.com")
|
||||
|
||||
# Open Manual
|
||||
with monkeypatch.context() as mp:
|
||||
openUrl = MagicMock()
|
||||
mp.setattr(QDesktopServices, "openUrl", openUrl)
|
||||
CONFIG.pdfDocs = projPath / "manual.pdf"
|
||||
CONFIG.pdfDocs.touch()
|
||||
nwGUI.mainMenu._openUserManualFile()
|
||||
assert openUrl.called is True
|
||||
assert "manual.pdf" in openUrl.call_args[0][0].url()
|
||||
|
||||
# Spell Checking
|
||||
assert SHARED.project.data.spellLang is None
|
||||
nwGUI.mainMenu._changeSpelling("en")
|
||||
assert SHARED.project.data.spellLang == "en"
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
"""Test the main menu Edit and Format entries."""
|
||||
|
||||
Reference in New Issue
Block a user