Add qml test for chatdocumenthandler
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
34
autotests/chatdocumenthelpertest.qml
Normal file
34
autotests/chatdocumenthelpertest.qml
Normal file
@@ -0,0 +1,34 @@
|
||||
// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
9
autotests/qmltest.cpp
Normal file
9
autotests/qmltest.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <quicktest.h>
|
||||
|
||||
QUICK_TEST_MAIN(Kirigami)
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user