118 lines
3.7 KiB
Python
118 lines
3.7 KiB
Python
"""
|
||
novelWriter – Main GUI Novel Tree Class Tester
|
||
==============================================
|
||
|
||
This file is a part of novelWriter
|
||
Copyright 2018–2022, Veronica Berglyd Olsen
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful, but
|
||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
"""
|
||
|
||
import pytest
|
||
|
||
from PyQt5.QtCore import Qt
|
||
from PyQt5.QtWidgets import QMessageBox
|
||
|
||
|
||
@pytest.mark.gui
|
||
def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||
"""Test navigating the novel tree.
|
||
"""
|
||
# Block message box
|
||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes)
|
||
|
||
nwGUI.openProject(nwMinimal)
|
||
novelView = nwGUI.novelView
|
||
novelTree = novelView.novelTree
|
||
|
||
# Show/Hide Scrollbars
|
||
# ====================
|
||
|
||
nwGUI.mainConf.hideVScroll = True
|
||
nwGUI.mainConf.hideHScroll = True
|
||
novelView.initSettings()
|
||
assert not novelTree.verticalScrollBar().isVisible()
|
||
assert not novelTree.horizontalScrollBar().isVisible()
|
||
|
||
nwGUI.mainConf.hideVScroll = False
|
||
nwGUI.mainConf.hideHScroll = False
|
||
novelView.initSettings()
|
||
assert novelTree.verticalScrollBar().isEnabled()
|
||
assert novelTree.horizontalScrollBar().isEnabled()
|
||
|
||
# Populate Tree
|
||
# =============
|
||
|
||
nwGUI.projStack.setCurrentIndex(nwGUI.idxNovelView)
|
||
nwGUI.rebuildIndex()
|
||
novelTree._populateTree(rootHandle=None)
|
||
assert novelTree.topLevelItemCount() == 3
|
||
|
||
# Rebuild should preserve selection
|
||
topItem = novelTree.topLevelItem(0)
|
||
assert not topItem.isSelected()
|
||
topItem.setSelected(True)
|
||
assert novelTree.selectedItems()[0] == topItem
|
||
assert novelView.getSelectedHandle() == ("a35baf2e93843", 0)
|
||
|
||
novelView.refreshTree()
|
||
assert novelTree.topLevelItem(0).isSelected()
|
||
|
||
# Open Items
|
||
# ==========
|
||
|
||
# Clear selection
|
||
novelTree.clearSelection()
|
||
scItem = novelTree.topLevelItem(2)
|
||
scItem.setSelected(True)
|
||
assert scItem.isSelected()
|
||
|
||
# Clear selection with mouse
|
||
vPort = novelTree.viewport()
|
||
qtbot.mouseClick(vPort, Qt.LeftButton, pos=vPort.rect().center(), delay=10)
|
||
assert not scItem.isSelected()
|
||
|
||
# Double-click item
|
||
scItem.setSelected(True)
|
||
assert scItem.isSelected()
|
||
assert nwGUI.docEditor.docHandle() is None
|
||
novelTree._treeDoubleClick(scItem, 0)
|
||
assert nwGUI.docEditor.docHandle() == "8c659a11cd429"
|
||
|
||
# Open item with middle mouse button
|
||
scItem.setSelected(True)
|
||
assert scItem.isSelected()
|
||
assert nwGUI.docViewer.docHandle() is None
|
||
qtbot.mouseClick(vPort, Qt.MiddleButton, pos=vPort.rect().center(), delay=10)
|
||
assert nwGUI.docViewer.docHandle() is None
|
||
|
||
scRect = novelTree.visualItemRect(scItem)
|
||
oldData = scItem.data(novelTree.C_TITLE, Qt.UserRole)
|
||
scItem.setData(novelTree.C_TITLE, Qt.UserRole, (None, "", ""))
|
||
qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10)
|
||
assert nwGUI.docViewer.docHandle() is None
|
||
|
||
scItem.setData(novelTree.C_TITLE, Qt.UserRole, oldData)
|
||
qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10)
|
||
assert nwGUI.docViewer.docHandle() == "8c659a11cd429"
|
||
|
||
# Close
|
||
# =====
|
||
|
||
# qtbot.stop()
|
||
nwGUI.closeProject()
|
||
|
||
# END Test testGuiNovelTree_TreeItems
|