Commit ed2e1ba1 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Add tests for view management

parent fe71e7e7
Pipeline #230599 passed with stage
in 8 minutes and 7 seconds
......@@ -25,4 +25,5 @@ kate_executable_tests(
urlinfo_test
json_utils_test
location_history_test
kate_view_mgmt_tests
)
/*
SPDX-FileCopyrightText: 2022 Waqar Ahmed <waqar.17a@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kate_view_mgmt_tests.h"
#include "katemainwindow.h"
#include "kateviewspace.h"
#include "ktexteditor_utils.h"
#include <QCommandLineParser>
#include <QPointer>
#include <QSignalSpy>
#include <QTest>
QTEST_MAIN(KateViewManagementTests)
KateViewManagementTests::KateViewManagementTests(QObject *)
{
m_tempdir = new QTemporaryDir;
QVERIFY(m_tempdir->isValid());
// create KWrite variant to avoid plugin loading!
static QCommandLineParser parser;
app = std::make_unique<KateApp>(parser, KateApp::ApplicationKWrite, m_tempdir->path());
app->sessionManager()->activateAnonymousSession();
}
void KateViewManagementTests::testSingleViewspaceDoesntCloseWhenLastViewClosed()
{
// Test that if we have 1 viewspaces then
// closing the last view doesn't close the viewspace
auto mw = app->activeKateMainWindow();
auto vm = mw->viewManager();
// Initially we have one viewspace and one view
QCOMPARE(vm->m_views.size(), 1);
QCOMPARE(vm->m_viewSpaceList.size(), 1);
// close active view
vm->closeView(vm->activeView());
// still same
QCOMPARE(vm->m_views.size(), 1);
QCOMPARE(vm->m_viewSpaceList.size(), 1);
}
void KateViewManagementTests::testViewspaceClosesWhenLastViewClosed()
{
// Test that if we have greater than 1 viewspaces then
// closing the last view in a viewspace closes that view
// space
auto mw = app->activeKateMainWindow();
auto vm = mw->viewManager();
// Initially we have one viewspace
QCOMPARE(vm->m_viewSpaceList.size(), 1);
vm->slotSplitViewSpaceVert();
// Now we have two
QCOMPARE(vm->m_viewSpaceList.size(), 2);
// and two views, one in each viewspace
QCOMPARE(vm->m_views.size(), 2);
// close active view
vm->closeView(vm->activeView());
QCOMPARE(vm->m_views.size(), 1);
QCOMPARE(vm->m_viewSpaceList.size(), 1);
}
void KateViewManagementTests::testViewspaceClosesWhenThereIsWidget()
{
// Test that if we have greater than 1 viewspaces then
// closing the last view in a viewspace closes that view
// space
KateMainWindow *mw = app->activeKateMainWindow();
auto vm = mw->viewManager();
QCOMPARE(vm->m_viewSpaceList.size(), 1);
vm->slotSplitViewSpaceVert();
// Now we have two viewspaces
QCOMPARE(vm->m_viewSpaceList.size(), 2);
// add a widget
QPointer<QWidget> widget = new QWidget;
Utils::addWidget(widget, app->activeMainWindow());
// there should still be 2 views
// widget is not counted in views
QCOMPARE(vm->m_views.size(), 2);
// Widget should be active
QVERIFY(vm->activeViewSpace()->currentWidget());
// close active view
// active view still points to the last active view
// even though it is not in focus by user
vm->closeView(vm->activeView());
// one view left, but two viewspaces
QCOMPARE(vm->m_views.size(), 1);
QCOMPARE(vm->m_viewSpaceList.size(), 2);
// close the widget!
QVERIFY(vm->removeWidget(widget));
QTest::qWait(100);
QVERIFY(!widget); // widget should be gone
// only one viewspace should be left now
QCOMPARE(vm->m_views.size(), 1);
QCOMPARE(vm->m_viewSpaceList.size(), 1);
}
void KateViewManagementTests::testMoveViewBetweenViewspaces()
{
KateMainWindow *mw = app->activeKateMainWindow();
auto vm = mw->viewManager();
vm->slotSplitViewSpaceVert();
// we have two viewspaces with 2 views
QCOMPARE(vm->m_viewSpaceList.size(), 2);
QCOMPARE(vm->m_views.size(), 2);
auto src = vm->activeViewSpace();
auto dest = vm->m_viewSpaceList.front();
QVERIFY(src != dest);
vm->moveViewToViewSpace(dest, src, vm->activeView()->document());
QTest::qWait(100);
// after moving we should have 2 views but only one viewspace left
QCOMPARE(vm->m_viewSpaceList.size(), 1);
QCOMPARE(vm->m_views.size(), 2);
}
/*
SPDX-FileCopyrightText: 2022 Waqar Ahmed <waqar.17a@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kateapp.h"
#include <QObject>
#include <QTemporaryDir>
#include <QTemporaryFile>
#include <memory>
class KateApp;
class KateViewSpace;
class KateViewManager;
class KateViewManagementTests : public QObject
{
Q_OBJECT
public:
KateViewManagementTests(QObject *parent = nullptr);
private Q_SLOTS:
void testSingleViewspaceDoesntCloseWhenLastViewClosed();
void testViewspaceClosesWhenLastViewClosed();
void testViewspaceClosesWhenThereIsWidget();
void testMoveViewBetweenViewspaces();
private:
class QTemporaryDir *m_tempdir;
std::unique_ptr<KateApp> app;
};
......@@ -41,6 +41,8 @@ class KATE_PRIVATE_EXPORT KateViewManager : public KateSplitter
{
Q_OBJECT
friend class KateViewManagementTests;
public:
KateViewManager(QWidget *parentW, KateMainWindow *parent);
~KateViewManager() override;
......
......@@ -29,6 +29,9 @@ class KATE_PRIVATE_EXPORT KateViewSpace : public QWidget
{
Q_OBJECT
friend class LocationHistoryTest;
friend class KateViewManagementTests;
public:
explicit KateViewSpace(KateViewManager *, QWidget *parent = nullptr, const char *name = nullptr);
......@@ -327,8 +330,6 @@ private:
class QVBoxLayout *mainLayout = nullptr;
} m_layout;
friend class LocationHistoryTest;
// should the tab bar be auto hidden if just one document is open?
bool m_autoHideTabBar = false;
};
......
Supports Markdown
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