From 19e6613846bcacdf8b54d16be85d9ddcce69344d Mon Sep 17 00:00:00 2001
From: thomahl <thomahl@stud.ntnu.no>
Date: Mon, 27 Apr 2020 12:38:58 +0200
Subject: [PATCH] =?UTF-8?q?#95=20legger=20til=20ny=20modul=20i=20oppl?=
 =?UTF-8?q?=C3=B8sningstest?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Oppløsningstest OK på 1920 x 1080 (100% & 125%) og 800 x 600
---
 test/test_resolution_smoke_test.py | 53 +++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 12 deletions(-)

diff --git a/test/test_resolution_smoke_test.py b/test/test_resolution_smoke_test.py
index 3bbcb60..dd9453c 100644
--- a/test/test_resolution_smoke_test.py
+++ b/test/test_resolution_smoke_test.py
@@ -19,13 +19,30 @@ from soitool.modules.module_authentication_board import (
     AuthenticationBoardModule,
 )
 from soitool.modules.module_subtractorcodes import SubtractorcodesModule
+from soitool.modules.module_predefined_codes import PredefinedCodesModule
 from soitool.new_module_dialog import MODULE_CHOICES
+from soitool.soi_workspace_widget import DATABASE_MODULES
+from soitool.database import Database
+
+# The error being ignored here is pylint telling us that 'test' is a standard
+# module, so the import should be placed further up. In our case we have an
+# actual custom module called 'test', so pylint is confused.
+# pylint: disable=C0411
+from test.test_database import TESTDBPATH
+
 
 if isinstance(QtGui.qApp, type(None)):
     app = QApplication([])
 else:
     app = QtGui.qApp
 
+# Modules with a popup as part of their __init__
+POPUP_MODULES = [
+    AuthenticationBoardModule,
+    SubtractorcodesModule,
+    PredefinedCodesModule,
+]
+
 
 def screen_information():
     """Get string with information about the screen.
@@ -87,20 +104,28 @@ class TestModulesAcrossResolutions(unittest.TestCase):
         deleted, or changed. It will fail until it is updated.
         """
         expected_result = [
-            {"x": 0, "y": 0, "page": 1, "name": "AuthenticationBoardModule"},
-            {"x": 407.5, "y": 0, "page": 1, "name": "SubtractorcodesModule"},
-            {"x": 602.0, "y": 0, "page": 1, "name": "FreeTextModule"},
-            {"x": 702.0, "y": 0, "page": 1, "name": "TableModule"},
+            {"x": 0, "y": 0, "page": 1, "name": "PredefinedCodesModule"},
+            {"x": 640, "y": 0, "page": 1, "name": "AuthenticationBoardModule"},
+            {"x": 1047.5, "y": 0, "page": 1, "name": "SubtractorcodesModule"},
+            {"x": 1273.0, "y": 0, "page": 1, "name": "FreeTextModule"},
+            {"x": 1373.0, "y": 0, "page": 1, "name": "TableModule"},
         ]
 
+        # For use with modules that require a database
+        self.database = Database(db_path=TESTDBPATH)
+
         def press_enter():
             active_widget = app.activeModalWidget()
-            # triple click to select existing text for overwrite
-            QTest.mouseDClick(active_widget.edit_headline, Qt.LeftButton)
-            QTest.mouseClick(active_widget.edit_headline, Qt.LeftButton)
-            # need to overwrite text because title otherwise contains
-            # unpredictable text
-            QTest.keyClicks(active_widget.edit_headline, "TestTitle")
+
+            # AuthenticationBoardModule needs special treatment because the
+            # title can contain random info
+            if isinstance(active_widget, AuthenticationBoardModule):
+                # triple click to select existing text for overwrite
+                QTest.mouseDClick(active_widget.edit_headline, Qt.LeftButton)
+                QTest.mouseClick(active_widget.edit_headline, Qt.LeftButton)
+                # need to overwrite text because title otherwise contains
+                # unpredictable text
+                QTest.keyClicks(active_widget.edit_headline, "TestTitle")
             QTest.keyClick(active_widget, Qt.Key_Enter)
 
         soi = SOI()
@@ -108,9 +133,13 @@ class TestModulesAcrossResolutions(unittest.TestCase):
         for module in MODULE_CHOICES:
             # If we're adding one of the modules with a popup as part of it's
             # constructor we need to singleShot pressing enter to close it
-            if module in (AuthenticationBoardModule, SubtractorcodesModule):
+            if module in POPUP_MODULES:
                 QTimer.singleShot(0, press_enter)
-            soi.add_module(module.__name__, module())
+
+            if module in DATABASE_MODULES:
+                soi.add_module(module.__name__, module(database=self.database))
+            else:
+                soi.add_module(module.__name__, module())
 
         soi.reorganize()
 
-- 
GitLab