find_package(Qt6 REQUIRED COMPONENTS Test)
add_executable(tilingpopup_test TilingPopupTest.cc ../src/TilingPopup.cc ../src/TilingZoneButton.cc ../src/DrawHelper.cc)
set_target_properties(tilingpopup_test PROPERTIES AUTOMOC ON)
target_include_directories(tilingpopup_test PRIVATE ../src)
target_link_libraries(tilingpopup_test PRIVATE Qt6::Widgets Qt6::Test KF6::I18n)
add_test(NAME tilingpopup COMMAND tilingpopup_test)
set_tests_properties(tilingpopup PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")

find_program(DBUS_RUN_SESSION dbus-run-session)
if(DBUS_RUN_SESSION)
    add_executable(longpressaction_test LongPressActionTest.cc ../src/LongPressAction.cc)
    set_target_properties(longpressaction_test PROPERTIES AUTOMOC ON)
    target_include_directories(longpressaction_test PRIVATE ../src)
    target_link_libraries(longpressaction_test PRIVATE Qt6::Test Qt6::DBus)
    add_test(NAME longpressaction COMMAND ${DBUS_RUN_SESSION} -- $<TARGET_FILE:longpressaction_test>)

    add_executable(tilingcontroller_test TilingControllerTest.cc ../src/TilingController.cc)
    set_target_properties(tilingcontroller_test PROPERTIES AUTOMOC ON)
    target_include_directories(tilingcontroller_test PRIVATE ../src)
    target_link_libraries(tilingcontroller_test PRIVATE Qt6::Widgets Qt6::Test Qt6::DBus)
    add_test(NAME tilingcontroller COMMAND ${DBUS_RUN_SESSION} -- $<TARGET_FILE:tilingcontroller_test>)
    set_tests_properties(tilingcontroller PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
endif()

find_program(NODE_EXECUTABLE node)
if(NODE_EXECUTABLE)
    add_test(NAME tilingscript COMMAND ${NODE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/TilingScriptTest.js)
endif()
