diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..500eff6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +*.pro.user +*.moc +*.o diff --git a/base/Helpers.qml b/base/Helpers.qml new file mode 100644 index 0000000..5029f27 --- /dev/null +++ b/base/Helpers.qml @@ -0,0 +1,50 @@ +import QtQuick 2.14 + +QtObject { + + function checkClassName(item, name) { + let stringy = item.toString() + return stringy.indexOf(name) !== -1 + } + + function topChildAt(item, x, y) { + var obj = item.childAt(x, y) + if (!!obj) { + for (var idx in obj.children) { + var child = obj.children[idx] + + var position = mapToItem(child, x, y) + if (position.x < 0 || position.y <= 0) { + continue + } else { + return topChildAt(child, position.x, position.y) + } + } + + return obj + } + + return null + } + + function findChildByClassName(item, className) { + for (var idx in item.children) { + let child = item.children[idx] + let cname = child.toString(); + if (cname.indexOf(className) !== -1) { + return child; + } + } + + return null; + } + + function checkIfItemExists(parent, x, y, className) { + var obj = parent.childAt(x, y) + if (className !== undefined) { + return !!obj && checkClassName(obj, className); + } else { + return !!obj + } + } +} diff --git a/base/WindowTestCase.qml b/base/WindowTestCase.qml new file mode 100644 index 0000000..de1a960 --- /dev/null +++ b/base/WindowTestCase.qml @@ -0,0 +1,16 @@ +import QtQuick 2.14 +import QtTest 1.14 + +import QtQuick.Window 2.14 + +TestCase { + id: root + + readonly property Window window: baseWindow + + Window { + id: baseWindow + width: 800 + height: 600 + } +} diff --git a/tst_Modals.qml b/tst_Modals.qml index 1815fe1..ae70b77 100644 --- a/tst_Modals.qml +++ b/tst_Modals.qml @@ -2,6 +2,7 @@ import QtQuick 2.14 import QtQuick.Window 2.14 import QtTest 1.14 +import "base" import "status-desktop/ui/app/AppLayouts/Chat/components" as DesktopComponents @@ -9,6 +10,8 @@ TestCase { name: "ProfilePopup" when: windowShown + Helpers { id: helpers } + /// TODO: add good test data QtObject { id: chatsModel @@ -45,7 +48,7 @@ TestCase { } Window { - id: tstWindow + id: window width: 800 height: 600 DesktopComponents.ProfilePopup { @@ -55,7 +58,7 @@ TestCase { /////// function initTestCase() { - tstWindow.show() + window.show() } function cleanupTestCase() { @@ -65,8 +68,8 @@ TestCase { function test_case1() { propfilePopup.openPopup(true, "Test user", "Some author", "", "bla bla test it bitch", "Nickname") wait(2000) // for show how its works - print(propfilePopup.contentItem, propfilePopup.width - 65) mouseClick(propfilePopup.background, propfilePopup.width - 65, 20, Qt.LeftButton) + verify(helpers.checkIfItemExists(propfilePopup.background, propfilePopup.width - 65, 20, "StatusFlatRoundButton")) wait(2000) // for show how its works verify(propfilePopup.contentItem.qrCodePopup.visible, "Qr code should be visible") propfilePopup.contentItem.qrCodePopup.close() diff --git a/tst_initialtest.qml b/tst_initialtest.qml index c7cd4a7..199673b 100644 --- a/tst_initialtest.qml +++ b/tst_initialtest.qml @@ -1,11 +1,15 @@ import QtQuick 2.14 import QtTest 1.14 +import "base" + import StatusQ.Core.Theme 0.1 TestCase { name: "initialTest" + Helpers { id: helpers } + function initTestCase() { } @@ -14,5 +18,6 @@ TestCase { function test_case1() { verify(!!Theme.palette, "Theme available"); + verify(helpers.checkClassName(Theme.palette, "StatusLightTheme")) } } diff --git a/ui-tests.pro b/ui-tests.pro index f8c983d..e363fc3 100644 --- a/ui-tests.pro +++ b/ui-tests.pro @@ -7,6 +7,8 @@ DESTDIR += $${PWD}/bin DEFINES += PROJECT_PATH=\"$${PWD}\" DISTFILES += \ + base/Helpers.qml \ + base/WindowTestCase.qml \ tst_Modals.qml \ tst_initialtest.qml