aboutsummaryrefslogtreecommitdiff
path: root/tests/test_mainwindow_projects.py
blob: a6df4768823e01d248911a1a047688cb15dde562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from PyQt6 import QtCore
import os
from pytest import fixture
from pytestqt import qtbot
from avp.gui.mainwindow import MainWindow
from . import getTestDataPath, window, settings


def test_mainwindow_init_with_project(qtbot, settings):
    window = MainWindow(getTestDataPath("config/projects/testproject.avp"), None)
    qtbot.addWidget(window)
    assert window.core.selectedComponents[0].name == "Classic Visualizer"
    assert window.core.selectedComponents[1].name == "Color"


def test_mainwindow_clear(qtbot, window):
    """MainWindow.clear() gives us a clean slate"""
    assert len(window.core.selectedComponents) == 0


def test_mainwindow_presetDir_in_tests(qtbot, window):
    """`presetDir` is the filepath on which "Import Preset" file picker opens"""
    assert os.path.basename(window.core.settings.value("presetDir")) == "presets"


def test_mainwindow_openProject(qtbot, window):
    """Open testproject.avp using MainWindow.openProject()"""
    window.openProject(getTestDataPath("config/projects/testproject.avp"), prompt=False)
    assert len(window.core.selectedComponents) == 2


def test_mainwindow_newProject_without_unsaved_changes(qtbot, window):
    """Starting new project without unsaved changes"""
    didCallFunction = False

    def captureFunction(*args, **kwargs):
        nonlocal didCallFunction
        didCallFunction = True

    window.createNewProject(prompt=False)
    assert not didCallFunction
    assert len(window.core.selectedComponents) == 0


def test_mainwindow_newProject_with_unsaved_changes(qtbot, window):
    """Starting new project with unsaved changes"""
    didCallFunction = False

    def captureFunction(*args, **kwargs):
        nonlocal didCallFunction
        didCallFunction = True

    window.openSaveChangesDialog = captureFunction
    window.createNewProject(prompt=True)
    assert didCallFunction