Adding qml tests to storybook
+ dummy StatusChatInput test
This commit is contained in:
parent
a6c3af97cf
commit
b414a829e8
|
@ -17,12 +17,16 @@ endif()
|
|||
|
||||
find_package(
|
||||
Qt5
|
||||
COMPONENTS Core Quick QuickControls2 Test
|
||||
COMPONENTS Core Quick QuickControls2 Test QuickTest Qml
|
||||
REQUIRED)
|
||||
|
||||
file(GLOB_RECURSE QML_FILES "stubs/*.qml" "mocks/*.qml" "pages/*.qml"
|
||||
"src/*.qml" "src/qmldir" "../ui/StatusQ/*.qml" "../ui/app/*.qml")
|
||||
file(GLOB_RECURSE JS_FILES "../ui/StatusQ/*.js" "../ui/app/*.js")
|
||||
file(GLOB_RECURSE CORE_QML_FILES "../ui/StatusQ/*.qml" "../ui/app/*.qml" "../ui/imports/*.qml")
|
||||
file(GLOB_RECURSE CORE_JS_FILES "../ui/StatusQ/*.js" "../ui/app/*.js")
|
||||
|
||||
file(GLOB_RECURSE STORYBOOK_QML_FILES "stubs/*.qml" "mocks/*.qml" "pages/*.qml"
|
||||
"src/*.qml" "src/qmldir")
|
||||
|
||||
file(GLOB_RECURSE TEST_QML_FILES "qmlTests/*.qml")
|
||||
|
||||
set(PROJECT_LIB "${PROJECT_NAME}Lib")
|
||||
|
||||
|
@ -42,8 +46,9 @@ add_executable(
|
|||
${PROJECT_NAME}
|
||||
main.cpp
|
||||
main.qml PagesModel.qml
|
||||
${QML_FILES}
|
||||
${JS_FILES}
|
||||
${CORE_QML_FILES}
|
||||
${CORE_JS_FILES}
|
||||
${STORYBOOK_QML_FILES}
|
||||
figma.json
|
||||
)
|
||||
|
||||
|
@ -65,6 +70,15 @@ add_executable(FigmaDecoratorModelTest tests/tst_FigmaDecoratorModel.cpp)
|
|||
target_link_libraries(FigmaDecoratorModelTest PRIVATE Qt5::Test ${PROJECT_LIB})
|
||||
add_test(NAME FigmaModelTest COMMAND FigmaModelTest)
|
||||
|
||||
add_executable(QmlTests
|
||||
qmlTests/main.cpp
|
||||
${TEST_QML_FILES})
|
||||
target_compile_definitions(QmlTests
|
||||
PRIVATE QML_IMPORT_ROOT="${CMAKE_CURRENT_LIST_DIR}"
|
||||
PRIVATE -DQUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/qmlTests")
|
||||
target_link_libraries(QmlTests PRIVATE Qt5::QuickTest Qt5::Qml)
|
||||
add_test(NAME QmlTests COMMAND QmlTests)
|
||||
|
||||
list(APPEND QML_DIRS "${CMAKE_SOURCE_DIR}/../ui/StatusQ/src")
|
||||
list(APPEND QML_DIRS "${CMAKE_SOURCE_DIR}/../ui/app")
|
||||
list(APPEND QML_DIRS "${CMAKE_SOURCE_DIR}/../ui/imports")
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
import QtQuick 2.14
|
||||
import QtQml 2.14
|
||||
import QtTest 1.0
|
||||
|
||||
import utils 1.0
|
||||
import shared.status 1.0
|
||||
import shared.stores 1.0
|
||||
|
||||
Item {
|
||||
id: root
|
||||
width: 600
|
||||
height: 400
|
||||
|
||||
QtObject {
|
||||
id: globalUtilsMock
|
||||
|
||||
property var plainText
|
||||
property var isCompressedPubKey: function (publicKey) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
QtObject {
|
||||
id: rootStoreMock
|
||||
|
||||
property ListModel gifColumnA: ListModel {}
|
||||
|
||||
readonly property var formationChars: (["*", "`", "~"])
|
||||
|
||||
function getSelectedTextWithFormationChars(messageInputField) {
|
||||
let i = 1
|
||||
let text = ""
|
||||
while (true) {
|
||||
if (messageInputField.selectionStart - i < 0 && messageInputField.selectionEnd + i > messageInputField.length) {
|
||||
break
|
||||
}
|
||||
|
||||
text = messageInputField.getText(messageInputField.selectionStart - i, messageInputField.selectionEnd + i)
|
||||
|
||||
if (!formationChars.includes(text.charAt(0)) ||
|
||||
!formationChars.includes(text.charAt(text.length - 1))) {
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
RootStore.isGifWidgetEnabled = true
|
||||
RootStore.isWalletEnabled = true
|
||||
RootStore.isTenorWarningAccepted = true
|
||||
RootStore.getSelectedTextWithFormationChars = rootStoreMock.getSelectedTextWithFormationChars
|
||||
RootStore.gifColumnA = rootStoreMock.gifColumnA
|
||||
}
|
||||
}
|
||||
|
||||
StatusChatInput {
|
||||
id: controlUnderTest
|
||||
width: parent.width
|
||||
property var globalUtils: globalUtilsMock
|
||||
Component.onCompleted: {
|
||||
Global.dragArea = root
|
||||
}
|
||||
}
|
||||
|
||||
TestCase {
|
||||
name: "TestChatInputInitialization"
|
||||
when: windowShown
|
||||
|
||||
function test_empty_chat_input() {
|
||||
globalUtilsMock.plainText = (htmlText) => {
|
||||
return ""
|
||||
}
|
||||
verify(controlUnderTest.textInput.length == 0, `Expected 0 text length, received: ${controlUnderTest.textInput.length}`)
|
||||
verify(controlUnderTest.getPlainText() == "", `Expected empty string, received: ${controlUnderTest.getPlainText()}`)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#include <QtQuickTest/quicktest.h>
|
||||
#include <QQmlEngine>
|
||||
|
||||
class Setup : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
void qmlEngineAvailable(QQmlEngine *engine) {
|
||||
// custom code that needs QQmlEngine, register QML types, add import paths,...
|
||||
const QStringList additionalImportPaths {
|
||||
QML_IMPORT_ROOT + QStringLiteral("/../ui/StatusQ/src"),
|
||||
QML_IMPORT_ROOT + QStringLiteral("/../ui/app"),
|
||||
QML_IMPORT_ROOT + QStringLiteral("/../ui/imports"),
|
||||
QML_IMPORT_ROOT + QStringLiteral("/stubs"),
|
||||
QML_IMPORT_ROOT + QStringLiteral("/mocks"),
|
||||
};
|
||||
|
||||
for (const auto& path : additionalImportPaths)
|
||||
engine->addImportPath(path);
|
||||
}
|
||||
};
|
||||
|
||||
QUICK_TEST_MAIN_WITH_SETUP(QmlTests, Setup)
|
||||
|
||||
#include "main.moc"
|
Loading…
Reference in New Issue