Update tests

This commit is contained in:
Veronica Berglyd Olsen
2024-12-29 17:38:21 +01:00
parent 2fa1dcccac
commit e924d121bf
3 changed files with 67 additions and 36 deletions
+2 -1
View File
@@ -1,5 +1,5 @@
[Meta] [Meta]
timestamp = 2024-11-03 21:45:08 timestamp = 2024-12-29 17:30:10
[Main] [Main]
font = font =
@@ -71,6 +71,7 @@ useridletime = 300
[State] [State]
showviewerpanel = True showviewerpanel = True
showedittoolbar = False showedittoolbar = False
showsessiontime = True
viewcomments = True viewcomments = True
viewsynopsis = True viewsynopsis = True
searchcase = False searchcase = False
+21 -3
View File
@@ -23,11 +23,13 @@ from __future__ import annotations
import pytest import pytest
from PyQt5.QtCore import QEvent, QPoint, QPointF, Qt from PyQt5.QtCore import QEvent, QPoint, QPointF, Qt
from PyQt5.QtGui import QKeyEvent, QWheelEvent from PyQt5.QtGui import QKeyEvent, QMouseEvent, QWheelEvent
from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QWidget
from novelwriter.extensions.modified import NComboBox, NDialog, NDoubleSpinBox, NSpinBox from novelwriter.extensions.modified import (
from novelwriter.types import QtModNone, QtRejected NClickableLabel, NComboBox, NDialog, NDoubleSpinBox, NSpinBox
)
from novelwriter.types import QtModNone, QtMouseLeft, QtRejected
from tests.tools import SimpleDialog from tests.tools import SimpleDialog
@@ -139,3 +141,19 @@ def testExtModified_NDoubleSpinBox(qtbot, monkeypatch):
assert event.ignored is True assert event.ignored is True
# qtbot.stop() # qtbot.stop()
@pytest.mark.gui
def testExtModified_NClickableLabel(qtbot, monkeypatch):
"""Test the NClickableLabel class."""
widget = NClickableLabel()
dialog = SimpleDialog(widget)
dialog.show()
position = widget.rect().center()
event = QMouseEvent(
QEvent.Type.MouseButtonPress, position, QtMouseLeft, QtMouseLeft, QtModNone
)
with qtbot.waitSignal(widget.mouseClicked):
widget.mousePressEvent(event)
+44 -32
View File
@@ -39,56 +39,68 @@ def testGuiStatusBar_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
newDoc.writeDocument("# A Note\n\n") newDoc.writeDocument("# A Note\n\n")
nwGUI.rebuildIndex(beQuiet=True) nwGUI.rebuildIndex(beQuiet=True)
status = nwGUI.mainStatus
# Reference Time # Reference Time
refTime = time.time() refTime = time.time()
nwGUI.mainStatus.setRefTime(refTime) status.setRefTime(refTime)
assert nwGUI.mainStatus._refTime == refTime assert status._refTime == refTime
# Project Status # Project Status
nwGUI.mainStatus.setProjectStatus(nwTrinary.NEUTRAL) status.setProjectStatus(nwTrinary.NEUTRAL)
assert nwGUI.mainStatus.projIcon.state == nwTrinary.NEUTRAL assert status.projIcon.state == nwTrinary.NEUTRAL
nwGUI.mainStatus.setProjectStatus(nwTrinary.NEGATIVE) status.setProjectStatus(nwTrinary.NEGATIVE)
assert nwGUI.mainStatus.projIcon.state == nwTrinary.NEGATIVE assert status.projIcon.state == nwTrinary.NEGATIVE
nwGUI.mainStatus.setProjectStatus(nwTrinary.POSITIVE) status.setProjectStatus(nwTrinary.POSITIVE)
assert nwGUI.mainStatus.projIcon.state == nwTrinary.POSITIVE assert status.projIcon.state == nwTrinary.POSITIVE
# Document Status # Document Status
nwGUI.mainStatus.setDocumentStatus(nwTrinary.NEUTRAL) status.setDocumentStatus(nwTrinary.NEUTRAL)
assert nwGUI.mainStatus.docIcon.state == nwTrinary.NEUTRAL assert status.docIcon.state == nwTrinary.NEUTRAL
nwGUI.mainStatus.setDocumentStatus(nwTrinary.NEGATIVE) status.setDocumentStatus(nwTrinary.NEGATIVE)
assert nwGUI.mainStatus.docIcon.state == nwTrinary.NEGATIVE assert status.docIcon.state == nwTrinary.NEGATIVE
nwGUI.mainStatus.setDocumentStatus(nwTrinary.POSITIVE) status.setDocumentStatus(nwTrinary.POSITIVE)
assert nwGUI.mainStatus.docIcon.state == nwTrinary.POSITIVE assert status.docIcon.state == nwTrinary.POSITIVE
# Idle Status # Idle Status
CONFIG.stopWhenIdle = False CONFIG.stopWhenIdle = False
nwGUI.mainStatus.setUserIdle(True) status.setUserIdle(True)
nwGUI.mainStatus.updateTime() status.updateTime()
assert nwGUI.mainStatus._userIdle is False assert status._userIdle is False
assert nwGUI.mainStatus.timeText.text() == "00:00:00" assert status.timeText.text() == "00:00:00"
CONFIG.stopWhenIdle = True CONFIG.stopWhenIdle = True
nwGUI.mainStatus.setUserIdle(True) status.setUserIdle(True)
nwGUI.mainStatus.updateTime(5) status.updateTime(5)
assert nwGUI.mainStatus._userIdle is True assert status._userIdle is True
assert nwGUI.mainStatus.timeText.text() != "00:00:00" assert status.timeText.text() != "00:00:00"
nwGUI.mainStatus.setUserIdle(False) status.setUserIdle(False)
nwGUI.mainStatus.updateTime(5) status.updateTime(5)
assert nwGUI.mainStatus._userIdle is False assert status._userIdle is False
assert nwGUI.mainStatus.timeText.text() != "00:00:00" assert status.timeText.text() != "00:00:00"
# Show/Hide Timer
assert status.timeText.isVisible() is True
assert CONFIG.showSessionTime is True
status._onClickTimerLabel()
assert status.timeText.isVisible() is False
assert CONFIG.showSessionTime is False
status._onClickTimerLabel()
assert status.timeText.isVisible() is True
assert CONFIG.showSessionTime is True
# Language # Language
nwGUI.mainStatus.setLanguage("None", "None") status.setLanguage("None", "None")
assert nwGUI.mainStatus.langText.text() == "None" assert status.langText.text() == "None"
nwGUI.mainStatus.setLanguage("en", "None") status.setLanguage("en", "None")
assert nwGUI.mainStatus.langText.text() == "American English" assert status.langText.text() == "American English"
# Project Stats # Project Stats
CONFIG.incNotesWCount = False CONFIG.incNotesWCount = False
nwGUI._lastTotalCount = 0 nwGUI._lastTotalCount = 0
nwGUI._updateStatusWordCount() nwGUI._updateStatusWordCount()
assert nwGUI.mainStatus.statsText.text() == "Words: 9 (+9)" assert status.statsText.text() == "Words: 9 (+9)"
# Update again, but through time tick # Update again, but through time tick
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
@@ -96,6 +108,6 @@ def testGuiStatusBar_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
CONFIG.incNotesWCount = True CONFIG.incNotesWCount = True
nwGUI._lastTotalCount = 0 nwGUI._lastTotalCount = 0
nwGUI._timeTick() nwGUI._timeTick()
assert nwGUI.mainStatus.statsText.text() == "Words: 11 (+11)" assert status.statsText.text() == "Words: 11 (+11)"
# qtbot.stop() # qtbot.stop()