Commit c7509acd authored by Ronan Abhamon's avatar Ronan Abhamon

feat(tests/MainViewTest): add a `showManageAccountsPopup` method

parent 4524a403
......@@ -213,8 +213,12 @@ set(HEADERS
)
set(TESTS
src/tests/main-view/MainViewTest.cpp
src/tests/main-view/MainViewTest.hpp
src/tests/self-test/SelfTest.cpp
src/tests/self-test/SelfTest.hpp
src/tests/TestUtils.cpp
src/tests/TestUtils.hpp
)
set(MAIN_FILE src/app/main.cpp)
......
......@@ -43,7 +43,7 @@
#define NOTIFICATION_PROPERTY_X "popupX"
#define NOTIFICATION_PROPERTY_Y "popupY"
#define NOTIFICATION_PROPERTY_WINDOW "__internalWindow"
#define NOTIFICATION_PROPERTY_WINDOW "internalWindow"
#define NOTIFICATION_PROPERTY_TIMER "__timer"
......
/*
* TestUtils.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: July 18, 2017
* Author: Ronan Abhamon
*/
#ifdef QT_NO_DEBUG
#undef QT_NO_DEBUG
#endif // ifdef QT_NO_DEBUG
#include <QtGlobal>
#include "../app/App.hpp"
#include "TestUtils.hpp"
// =============================================================================
static void printItemTree (const QQuickItem *item, QString &output, int spaces) {
output.append(QString().leftJustified(spaces, ' '));
output.append(item->metaObject()->className());
output.append("\n");
for (const auto &childItem : item->childItems())
printItemTree(childItem, output, spaces + 2);
}
void TestUtils::printItemTree (const QQuickItem *item) {
QString output;
::printItemTree(item, output, 0);
qInfo().noquote() << output;
}
// -----------------------------------------------------------------------------
QQuickItem *TestUtils::getMainLoaderFromMainWindow () {
QQuickWindow *window = App::getInstance()->getMainWindow();
Q_CHECK_PTR(window);
QList<QQuickItem *> items = window->contentItem()->childItems();
Q_ASSERT(!items.empty());
for (int i = 0; i < 3; ++i) {
items = items.at(0)->childItems();
Q_ASSERT(!items.empty());
}
QQuickItem *loader = items.at(0);
Q_ASSERT(!strcmp(loader->metaObject()->className(), "QQuickLoader"));
return loader;
}
// -----------------------------------------------------------------------------
QQuickItem *TestUtils::getVirtualWindow (const QQuickWindow *window) {
Q_CHECK_PTR(window);
QList<QQuickItem *> items = window->contentItem()->childItems();
Q_ASSERT(!items.empty());
items = items.at(0)->childItems();
Q_ASSERT(!items.empty());
items = items.at(0)->childItems();
Q_ASSERT(items.size() == 2);
const char name[] = "VirtualWindow_QMLTYPE_";
QQuickItem *virtualWindow = items.at(1);
Q_ASSERT(!strncmp(virtualWindow->metaObject()->className(), name, sizeof name - 1));
return virtualWindow;
}
// -----------------------------------------------------------------------------
QQuickItem *TestUtils::getVirtualWindowContainer (const QQuickItem *virtualWindow) {
Q_CHECK_PTR(virtualWindow);
QList<QQuickItem *> items = virtualWindow->childItems();
Q_ASSERT(items.size() == 2);
QQuickItem *container = items.at(1);
Q_ASSERT(!container->childItems().empty());
return container;
}
/*
* TestUtils.hpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: July 18, 2017
* Author: Ronan Abhamon
*/
#include <QQuickItem>
#include <QQuickWindow>
// =============================================================================
namespace TestUtils {
void printItemTree (const QQuickItem *item);
QQuickItem *getMainLoaderFromMainWindow ();
QQuickItem *getVirtualWindow (const QQuickWindow *window);
QQuickItem *getVirtualWindowContainer (const QQuickItem *virtualWindow);
}
/*
* MainViewTest.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: July 18, 2017
* Author: Ronan Abhamon
*/
#include <QTest>
#include "../../app/App.hpp"
#include "../TestUtils.hpp"
#include "MainViewTest.hpp"
// =============================================================================
void MainViewTest::showManageAccountsPopup () {
QQuickWindow *mainWindow = App::getInstance()->getMainWindow();
QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(100, 35));
QTest::qWait(1000);
const char name[] = "DialogPlus_QMLTYPE_";
QQuickItem *virtualWindowContent = TestUtils::getVirtualWindowContainer(
TestUtils::getVirtualWindow(mainWindow)
)->childItems().at(0);
QVERIFY(!strncmp(virtualWindowContent->metaObject()->className(), name, sizeof name - 1));
QVERIFY(virtualWindowContent->objectName() == "manageAccounts");
}
/*
* MainViewTest.hpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: July 18, 2017
* Author: Ronan Abhamon
*/
#include <QObject>
// =============================================================================
class MainViewTest : public QObject {
Q_OBJECT;
public:
MainViewTest () = default;
private slots:
void showManageAccountsPopup ();
};
......@@ -26,13 +26,14 @@
#include "../app/AppController.hpp"
#include "../utils/Utils.hpp"
#include "main-view/MainViewTest.hpp"
#include "self-test/SelfTest.hpp"
// =============================================================================
static QHash<QString, QObject *> initializeTests () {
QHash<QString, QObject *> hash;
// TODO: Add tests here.
hash["main-view"] = new MainViewTest();
return hash;
}
......
......@@ -24,14 +24,20 @@
#include <QTest>
#include "../../components/core/CoreManager.hpp"
#include "../TestUtils.hpp"
#include "SelfTest.hpp"
#define SELF_TEST_DELAY 5000
// =============================================================================
void SelfTest::checkAppStartup () {
QSignalSpy spy(CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::coreStarted);
QVERIFY(spy.wait(SELF_TEST_DELAY));
QSignalSpy spyCoreStarted(CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::coreStarted);
QSignalSpy spyLoaderReady(TestUtils::getMainLoaderFromMainWindow(), SIGNAL(loaded()));
QVERIFY(spyCoreStarted.wait(5000));
if (spyLoaderReady.count() == 1)
return;
QVERIFY(spyLoaderReady.wait(1000));
}
......@@ -48,7 +48,7 @@ Item {
id: window
// Used for internal purposes only. Like Notifications.
objectName: '__internalWindow'
objectName: 'internalWindow'
flags: wrapper.flags
opacity: 0
......
......@@ -39,6 +39,6 @@ TestCase {
var window = notification.data[0]
compare(Utils.qmlTypeof(window, 'QQuickWindowQmlImpl'), true)
compare(window.objectName === '__internalWindow', true)
compare(window.objectName === 'internalWindow', true)
}
}
......@@ -18,6 +18,7 @@ DialogPlus {
]
centeredButtons: true
objectName: 'manageAccounts'
height: ManageAccountsStyle.height
width: ManageAccountsStyle.width
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment