Update test coverage
This commit is contained in:
@@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
""" # noqa
|
||||
from __future__ import annotations
|
||||
|
||||
from PyQt6.QtGui import QColor, QFont, QPalette, QPixmap
|
||||
from PyQt6.QtGui import QColor, QFont, QPalette
|
||||
from PyQt6.QtWidgets import (
|
||||
QAbstractButton, QFrame, QHBoxLayout, QLabel, QLayout, QScrollArea,
|
||||
QVBoxLayout, QWidget
|
||||
@@ -170,7 +170,7 @@ class NScrollableForm(QScrollArea):
|
||||
def addRow(
|
||||
self,
|
||||
label: str | None,
|
||||
widget: QWidget | list[QWidget | QPixmap | int],
|
||||
widget: QWidget | list[QWidget | int],
|
||||
helpText: str = "",
|
||||
unit: str | None = None,
|
||||
button: QWidget | None = None,
|
||||
@@ -187,10 +187,6 @@ class NScrollableForm(QScrollArea):
|
||||
for item in widget:
|
||||
if isinstance(item, QWidget):
|
||||
wBox.addWidget(item)
|
||||
elif isinstance(item, QPixmap):
|
||||
icon = QLabel(self)
|
||||
icon.setPixmap(item)
|
||||
wBox.addWidget(icon)
|
||||
elif isinstance(item, int):
|
||||
wBox.addSpacing(item)
|
||||
qWidget = QWidget(self)
|
||||
|
||||
@@ -241,9 +241,9 @@ class NIconToolButton(QToolButton):
|
||||
if icon:
|
||||
self.setThemeIcon(icon, color)
|
||||
|
||||
def setThemeIcon(self, iconKey: str, color: str | None = None) -> None:
|
||||
def setThemeIcon(self, icon: str, color: str | None = None) -> None:
|
||||
"""Set an icon from the current theme."""
|
||||
self.setIcon(SHARED.theme.getIcon(iconKey, color))
|
||||
self.setIcon(SHARED.theme.getIcon(icon, color))
|
||||
|
||||
|
||||
class NIconToggleButton(QToolButton):
|
||||
@@ -262,10 +262,10 @@ class NIconToggleButton(QToolButton):
|
||||
if icon:
|
||||
self.setThemeIcon(icon)
|
||||
|
||||
def setThemeIcon(self, iconKey: str) -> None:
|
||||
def setThemeIcon(self, icon: str) -> None:
|
||||
"""Set an icon from the current theme."""
|
||||
size = self.iconSize()
|
||||
self.setIcon(SHARED.theme.getToggleIcon(iconKey, (size.width(), size.height())))
|
||||
self.setIcon(SHARED.theme.getToggleIcon(icon, (size.width(), size.height())))
|
||||
|
||||
|
||||
class NClickableLabel(QLabel):
|
||||
|
||||
@@ -22,12 +22,13 @@ from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt6.QtCore import QEvent, QPoint, QPointF, Qt
|
||||
from PyQt6.QtCore import QEvent, QPoint, QPointF, QSize, Qt
|
||||
from PyQt6.QtGui import QKeyEvent, QMouseEvent, QStandardItem, QStandardItemModel, QWheelEvent
|
||||
from PyQt6.QtWidgets import QWidget
|
||||
|
||||
from novelwriter.extensions.modified import (
|
||||
NClickableLabel, NComboBox, NDialog, NDoubleSpinBox, NSpinBox, NTreeView
|
||||
NClickableLabel, NComboBox, NDialog, NDoubleSpinBox, NIconToggleButton,
|
||||
NIconToolButton, NSpinBox, NTreeView
|
||||
)
|
||||
from novelwriter.types import QtModNone, QtMouseLeft, QtMouseMiddle, QtRejected
|
||||
|
||||
@@ -168,7 +169,7 @@ def testExtModified_NDoubleSpinBox(qtbot, monkeypatch):
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testExtModified_NClickableLabel(qtbot, monkeypatch):
|
||||
def testExtModified_NClickableLabel(qtbot):
|
||||
"""Test the NClickableLabel class."""
|
||||
widget = NClickableLabel()
|
||||
dialog = SimpleDialog(widget)
|
||||
@@ -181,3 +182,23 @@ def testExtModified_NClickableLabel(qtbot, monkeypatch):
|
||||
|
||||
with qtbot.waitSignal(widget.mouseClicked):
|
||||
widget.mousePressEvent(event)
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testExtModified_ToolButtons(qtbot):
|
||||
"""Test the NIconToolButton and NIconToggleButton classes."""
|
||||
dialog = SimpleDialog(None)
|
||||
|
||||
size = QSize(16, 16)
|
||||
button1 = NIconToolButton(dialog, size, "add", "green")
|
||||
button2 = NIconToggleButton(dialog, size, "bullet")
|
||||
|
||||
assert button1.iconSize() == size
|
||||
assert button2.iconSize() == size
|
||||
|
||||
assert button1.icon().isNull() is False
|
||||
assert button2.icon().isNull() is False
|
||||
|
||||
dialog.addWidget(button1)
|
||||
dialog.addWidget(button2)
|
||||
dialog.show()
|
||||
|
||||
@@ -152,7 +152,7 @@ def testToolManuscript_Builds(qtbot, nwGUI, projPath):
|
||||
assert new.name == "Test Build 2"
|
||||
|
||||
# Trigger a theme update, which should propagate to settings
|
||||
manus.updateTheme()
|
||||
nwGUI.refreshThemeColors()
|
||||
|
||||
# Close the dialog should also close the child dialogs
|
||||
manus.btnClose.click()
|
||||
|
||||
Reference in New Issue
Block a user