diff --git a/CMakeLists.txt b/CMakeLists.txt index eca26f473..fa7958741 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,7 +178,7 @@ add_definitions(-DQT_NO_FOREACH) add_subdirectory(src) if (BUILD_TESTING) - find_package(Qt6 ${QT_MIN_VERSION} NO_MODULE COMPONENTS Test HttpServer) + find_package(Qt6 ${QT_MIN_VERSION} NO_MODULE COMPONENTS Test HttpServer QuickTest) add_subdirectory(autotests) # add_subdirectory(appiumtests) if (NOT ANDROID) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 5ec04ee64..38f68d38b 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -110,3 +110,32 @@ ecm_add_test( LINK_LIBRARIES neochat Qt::Test neochat_server Devtools TEST_NAME modeltest ) + +macro(add_qml_tests) + if (WIN32) + set(_extra_args -platform offscreen) + endif() + + foreach(test ${ARGV}) + add_test(NAME ${test} + COMMAND qmltest + ${_extra_args} + -input ${test} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endforeach() +endmacro() + +add_executable(qmltest qmltest.cpp) + +target_link_libraries(qmltest + PRIVATE + Qt6::Qml + Qt6::QuickTest + LibNeoChat + LibNeoChatplugin +) + +add_qml_tests( + chatdocumenthelpertest.qml +) diff --git a/autotests/chatdocumenthelpertest.qml b/autotests/chatdocumenthelpertest.qml new file mode 100644 index 000000000..e62d5ffa7 --- /dev/null +++ b/autotests/chatdocumenthelpertest.qml @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2024 Carl Schwan +// SPDX-License-Identifier: LGPL-2.0-or-later + +import QtQuick +import QtTest + +import org.kde.neochat.libneochat as LibNeoChat + +TestCase { + name: "ChatDocumentHandlerTest" + + LibNeoChat.ChatDocumentHandler { + id: documentHandler + } + + TextEdit { + id: TextEdit + } + + function test_empty(): void { + compare(documentHandler.type, LibNeoChat.ChatBarType.None); + compare(documentHandler.room, null); + compare(documentHandler.textItem, null); + compare(documentHandler.completionModel instanceof LibNeoChat.CompletionModel, true); + compare(documentHandler.atFirstLine, false); + compare(documentHandler.atLastLine, false); + compare(documentHandler.bold, false); + compare(documentHandler.italic, false); + compare(documentHandler.underline, false); + compare(documentHandler.strikethrough, false); + compare(documentHandler.style, 0); + compare(documentHandler.currentListStyle, 0); + } +} diff --git a/autotests/qmltest.cpp b/autotests/qmltest.cpp new file mode 100644 index 000000000..c07a73ec4 --- /dev/null +++ b/autotests/qmltest.cpp @@ -0,0 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2020 Arjen Hiemstra + * + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#include + +QUICK_TEST_MAIN(Kirigami) diff --git a/src/libneochat/chatdocumenthandler.cpp b/src/libneochat/chatdocumenthandler.cpp index 558aa44bb..b8fd24226 100644 --- a/src/libneochat/chatdocumenthandler.cpp +++ b/src/libneochat/chatdocumenthandler.cpp @@ -1033,25 +1033,6 @@ void ChatDocumentHandler::setStyleFormat(RichFormat::Format format) Q_EMIT styleChanged(); } -QString ChatDocumentHandler::fileName() const -{ - const QString filePath = QQmlFile::urlToLocalFileOrQrc(m_fileUrl); - const QString fileName = QFileInfo(filePath).fileName(); - if (fileName.isEmpty()) - return QStringLiteral("untitled.txt"); - return fileName; -} - -QString ChatDocumentHandler::fileType() const -{ - return QFileInfo(fileName()).suffix(); -} - -QUrl ChatDocumentHandler::fileUrl() const -{ - return m_fileUrl; -} - void ChatDocumentHandler::tab() { QTextCursor cursor = textCursor(); diff --git a/src/libneochat/chatdocumenthandler.h b/src/libneochat/chatdocumenthandler.h index 21ae7cd21..26327f567 100644 --- a/src/libneochat/chatdocumenthandler.h +++ b/src/libneochat/chatdocumenthandler.h @@ -94,7 +94,7 @@ class ChatDocumentHandler : public QObject Q_PROPERTY(CompletionModel *completionModel READ completionModel CONSTANT) /** - * @brief Whether the cursor is cuurently on the first line. + * @brief Whether the cursor is currently on the first line. */ Q_PROPERTY(bool atFirstLine READ atFirstLine NOTIFY atFirstLineChanged) @@ -112,14 +112,7 @@ class ChatDocumentHandler : public QObject Q_PROPERTY(RichFormat::Format style READ style NOTIFY styleChanged) - // Q_PROPERTY(bool canIndentList READ canIndentList NOTIFY cursorPositionChanged) - // Q_PROPERTY(bool canDedentList READ canDedentList NOTIFY cursorPositionChanged) Q_PROPERTY(int currentListStyle READ currentListStyle NOTIFY currentListStyleChanged) - // Q_PROPERTY(int currentHeadingLevel READ currentHeadingLevel NOTIFY cursorPositionChanged) - - Q_PROPERTY(QString fileName READ fileName NOTIFY fileUrlChanged) - Q_PROPERTY(QString fileType READ fileType NOTIFY fileUrlChanged) - Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY fileUrlChanged) public: enum InsertPosition { @@ -190,10 +183,6 @@ public: RichFormat::Format style() const; - QString fileName() const; - QString fileType() const; - QUrl fileUrl() const; - Q_INVOKABLE void tab(); Q_INVOKABLE void deleteChar(); Q_INVOKABLE void backspace(); @@ -221,7 +210,6 @@ Q_SIGNALS: void checkableChanged(); void currentListStyleChanged(); - void fileUrlChanged(); void formatChanged(); void styleChanged(); @@ -272,7 +260,6 @@ private: QColor linkColor(); QColor mLinkColor; void regenerateColorScheme(); - QUrl m_fileUrl; QString trim(QString string) const;