Skip to content

Commit

Permalink
Add test coverage of convert folder feature
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Oct 1, 2022
1 parent 7d99d6c commit 25dec2a
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tests/test_gui/test_gui_projtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def testGuiProjTree_DeleteItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockR


@pytest.mark.gui
def testGuiProjTree_ContextMenu(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd):
def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, fncDir, mockRnd):
"""Test the building of the project tree context menu. All this does
is test that the menu builds. It doesn't open the actual menu,
"""
Expand All @@ -470,6 +470,8 @@ def testGuiProjTree_ContextMenu(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockR
monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True))
monkeypatch.setattr(QMenu, "exec_", lambda *a: None)

nwTree = nwGUI.projView

# Create a project
prjDir = os.path.join(fncDir, "project")
buildTestProject(nwGUI, prjDir)
Expand Down Expand Up @@ -544,6 +546,38 @@ def itemPos(tHandle):
projTree._changeItemLayout(hNovelNote, nwItemLayout.NOTE)
assert nwItem.itemLayout == nwItemLayout.NOTE

# Convert Folders to Documents
# ============================

hNewFolderOne = "0000000000013"
hNewFolderTwo = "0000000000015"

nwTree.setSelectedHandle(hNovelNote)
assert nwTree.projTree.newTreeItem(nwItemType.FOLDER) is True
nwTree.setSelectedHandle(hNewFolderOne)
assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True

nwTree.setSelectedHandle(hNovelNote)
assert nwTree.projTree.newTreeItem(nwItemType.FOLDER) is True
nwTree.setSelectedHandle(hNewFolderTwo)
assert nwTree.projTree.newTreeItem(nwItemType.FILE, isNote=True) is True

# Click no on the dialog
with monkeypatch.context() as mp:
mp.setattr(QMessageBox, "question", lambda *a: QMessageBox.No)
projTree._covertFolderToFile(hNewFolderOne, nwItemLayout.DOCUMENT)
assert nwGUI.theProject.tree[hNewFolderOne].isFolderType()

# Convert the first folder to a document
projTree._covertFolderToFile(hNewFolderOne, nwItemLayout.DOCUMENT)
assert nwGUI.theProject.tree[hNewFolderOne].isFileType()
assert nwGUI.theProject.tree[hNewFolderOne].isDocumentLayout()

# Convert the second folder to a note
projTree._covertFolderToFile(hNewFolderTwo, nwItemLayout.NOTE)
assert nwGUI.theProject.tree[hNewFolderTwo].isFileType()
assert nwGUI.theProject.tree[hNewFolderTwo].isNoteLayout()

# qtbot.stop()

# END Test testGuiProjTree_ContextMenu

0 comments on commit 25dec2a

Please sign in to comment.