Skip to content

Commit

Permalink
refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RabiyaF committed Aug 21, 2024
1 parent f2efc23 commit 92353a9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
10 changes: 7 additions & 3 deletions rascal2/dialogs/startup_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ def _cancel_project_creation(self):
Cancel project creation.
"""
self._switch_to_startup_dialog.emit()
self._reset_variables()

def _reset_variables(self):
"""
Resets the variables.
"""
self._folder_selected = False
self._project_folder.setText("")
self._project_name.setText("")
Expand Down Expand Up @@ -232,9 +238,7 @@ def _verify_inputs(self):
"""
if self._project_name.text() != "" and self._folder_selected:
self._create_project.emit()
self._folder_selected = False
self._project_folder.setText("")
self._project_name.setText("")
self._reset_variables()
elif not self._project_name.text():
self._show_error_message(
text="Specify project name",
Expand Down
Binary file added rascal2/static/images/tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion rascal2/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def createProject(self):
"""Creates the project"""
self.startup_dlg.close()
self.project_dlg.close()
self.setWindowTitle(MAIN_WINDOW_TITLE + self.project_dlg._project_name.text())
self.setWindowTitle(MAIN_WINDOW_TITLE + " - " + self.project_dlg._project_name.text())
self.setupMDI()

def createActions(self):
Expand Down Expand Up @@ -114,6 +114,7 @@ def createActions(self):
# Window menu actions
self.tile_windows_action = QtGui.QAction("Tile Windows", self)
self.tile_windows_action.setStatusTip("Arrange windows in the default grid")
self.tile_windows_action.setIcon(QtGui.QIcon(path_for("tile.png")))
self.tile_windows_action.triggered.connect(self.mdi.tileSubWindows)

def createMenus(self):
Expand Down
67 changes: 32 additions & 35 deletions tests/test_dialogs.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
import pytest
from PyQt6 import QtCore

from rascal2.dialogs.startup_dialog import ProjectDialog, StartUpDialog
from rascal2.ui.view import MainWindowView


class TestStartUpDialog:
@pytest.fixture(autouse=True)
def setUp(self):
self.view = MainWindowView()
self.startup_dialog = StartUpDialog(self.view)
def test_startup_dialog_initial_state():
"""
Tests the initial state of the start up dialog.
"""
startup_dialog = StartUpDialog()

def test_initial_state(self):
assert self.startup_dialog.windowFlags() == (
QtCore.Qt.WindowType.FramelessWindowHint | QtCore.Qt.WindowType.Dialog
)
assert self.startup_dialog.isModal()
assert startup_dialog.windowFlags() == (QtCore.Qt.WindowType.FramelessWindowHint | QtCore.Qt.WindowType.Dialog)
assert startup_dialog.isModal()

assert self.startup_dialog._new_project_button.isEnabled()
assert self.startup_dialog._import_project_button.isEnabled()
assert self.startup_dialog._load_example_button.isEnabled()
assert startup_dialog._new_project_button.isEnabled()
assert startup_dialog._import_project_button.isEnabled()
assert startup_dialog._load_example_button.isEnabled()

assert self.startup_dialog._new_project_label.text() == "New\nProject"
assert self.startup_dialog._import_project_label.text() == "Import Existing\nProject"
assert self.startup_dialog._load_example_label.text() == "Open Example\nProject"
assert startup_dialog._new_project_label.text() == "New\nProject"
assert startup_dialog._import_project_label.text() == "Import Existing\nProject"
assert startup_dialog._load_example_label.text() == "Open Example\nProject"


class TestProjectDialog:
@pytest.fixture(autouse=True)
def setUp(self):
self.view = MainWindowView()
self.project_dialog = ProjectDialog(self.view)
def test_project_dialog_initial_state():
"""
Tests the inital state of the project dialog.
"""
project_dialog = ProjectDialog()

def test_initial_state(self):
assert self.project_dialog._create_button.isEnabled()
assert self.project_dialog._cancel_button.isEnabled()
assert self.project_dialog._browse_button.isEnabled()
assert project_dialog.isModal()

assert self.project_dialog._create_button.text() == " Create"
assert self.project_dialog._cancel_button.text() == " Cancel"
assert self.project_dialog._browse_button.text() == " Browse"
assert project_dialog._create_button.isEnabled()
assert project_dialog._cancel_button.isEnabled()
assert project_dialog._browse_button.isEnabled()

assert self.project_dialog._project_name_label.text() == "Project Name:"
assert self.project_dialog._project_folder_label.text() == "Project Folder:"
assert self.project_dialog._project_folder.text() == "No folder selected"
assert project_dialog._create_button.text() == " Create"
assert project_dialog._cancel_button.text() == " Cancel"
assert project_dialog._browse_button.text() == " Browse"

assert self.project_dialog._project_name.text() == ""
assert self.project_dialog._project_name.placeholderText() == "Enter project name"
assert project_dialog._project_name_label.text() == "Project Name:"
assert project_dialog._project_folder_label.text() == "Project Folder:"
assert project_dialog._project_folder.text() == "No folder selected"

assert project_dialog._project_name.text() == ""
assert project_dialog._project_name.placeholderText() == "Enter project name"
assert not project_dialog._folder_selected

0 comments on commit 92353a9

Please sign in to comment.