From 7a8e807d685d0e6cb4277c979c089fea11a4f9bd Mon Sep 17 00:00:00 2001 From: morkolai <nikolai-mork@live.no> Date: Wed, 29 Apr 2020 10:09:52 +0200 Subject: [PATCH] =?UTF-8?q?#96=20Fullf=C3=B8rt=20tester.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_module_phonebook.py | 43 ++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/test/test_module_phonebook.py b/test/test_module_phonebook.py index d79517f..d6206fc 100644 --- a/test/test_module_phonebook.py +++ b/test/test_module_phonebook.py @@ -4,7 +4,12 @@ import unittest from PySide2.QtGui import qApp, QKeySequence from PySide2.QtCore import Qt, QTimer from PySide2.QtTest import QTest -from PySide2.QtWidgets import QApplication, QCheckBox, QPushButton +from PySide2.QtWidgets import ( + QApplication, + QCheckBox, + QPushButton, + QTableWidgetItem, +) from soitool.soi import SOI from soitool.modules.module_phonebook import ( PhonebookModule, @@ -30,14 +35,14 @@ class TestPhonebokkModule(unittest.TestCase): """Test header is correct.""" self.assertEqual(self.phonebook.header.text(), "Telefonliste") - def test_type_table(self): + def test_resize_width(self): """Test able to type in table and resize to content.""" rambo_quote = "Live for nothing or die for something." - self.phonebook.table.setCurrentCell(1, 0) - QTest.keyClicks(self.phonebook.table, rambo_quote) - print(self.phonebook.table.currentItem().text()) - - # TODO + item = QTableWidgetItem(rambo_quote) + old_width = self.phonebook.minimumWidth() + self.phonebook.table.setItem(1, 0, item) + new_width = self.phonebook.minimumWidth() + self.assertGreater(new_width, old_width) def test_popup(self): """Test popup is shown and i able to edit columns.""" @@ -64,18 +69,21 @@ class TestPhonebokkModule(unittest.TestCase): new_column_count = visible_columns_in(self.phonebook.table) self.assertEqual(new_column_count, old_column_count + 1) - def test_add_row(self): - """Test adding row.""" + def test_add_row_and_resize(self): + """Test adding row and resizes acordingly.""" old_row_count = self.phonebook.table.rowCount() + old_height = self.phonebook.minimumHeight() QTest.keySequence( self.phonebook, QKeySequence(Qt.ControlModifier + Qt.Key_Plus) ) new_row_count = self.phonebook.table.rowCount() + new_height = self.phonebook.minimumHeight() self.assertEqual(new_row_count, old_row_count + 1) + self.assertGreater(new_height, old_height) def test_remove_row(self): """Test removing row.""" - self.phonebook.table.setRowCount(self.phonebook.table.rowCount() + 1) + self.phonebook.table.setRowCount(self.phonebook.table.rowCount() + 5) old_row_count = self.phonebook.table.rowCount() self.phonebook.table.setCurrentCell(1, 0) QTest.keySequence( @@ -84,8 +92,14 @@ class TestPhonebokkModule(unittest.TestCase): new_row_count = self.phonebook.table.rowCount() self.assertEqual(new_row_count, old_row_count - 1) + def test_buttons_visibility(self): + """Test buttons only are visible when mouse is in widgets space.""" + self.assertFalse(self.phonebook.buttons.isVisible()) + QTest.mouseMove(self.phonebook.buttons) + self.assertTrue(self.phonebook.table.isVisible()) + def test_add_to_soi_smoke_test(self): - """Test that can add to SOI sccessfully.""" + """Test that can add to SOI successfully.""" soi = SOI() test_name = "Test name" soi.add_module(test_name, self.phonebook, False) @@ -125,6 +139,13 @@ class TestPhonebookModuleWithDataParameter(unittest.TestCase): current_text, self.data[column_header][row_index - 1] ) + def test_add_to_soi_smoketest(self): + """Test that can add to SOI successfully.""" + soi = SOI() + test_name = "Test name" + soi.add_module(test_name, self.phonebook, False) + self.assertTrue(soi.module_name_taken(test_name)) + def visible_columns_in(table): """Count number of visible columns in a table. -- GitLab