From 314c9037f2869c2076b684a8838e0e01710a88ab Mon Sep 17 00:00:00 2001 From: talksik Date: Tue, 27 Jan 2026 12:43:44 -0800 Subject: [PATCH] tests: add first test for auth --- CMakeLists.txt | 5 +++++ tests/CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ tests/testauthmanager.cpp | 25 +++++++++++++++++++++++++ tests/testauthmanager.h | 26 ++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/testauthmanager.cpp create mode 100644 tests/testauthmanager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ee7098..74d571b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,13 @@ find_package(Qt6 REQUIRED COMPONENTS Gui Widgets Network + Test ) qt_standard_project_setup(REQUIRES 6.8) +enable_testing() + qt_add_executable(llink main.cpp src/MainWindow.cpp @@ -56,6 +59,8 @@ target_link_libraries(llink Qt6::Network ) +add_subdirectory(tests) + include(GNUInstallDirs) install(TARGETS llink BUNDLE DESTINATION . diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..f49d9ca --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,32 @@ + +# Test executable for AuthManager +qt_add_executable(testauthmanager + # Test files + testauthmanager.cpp + testauthmanager.h + + # Source files needed for testing + ../src/authmanager.cpp + ../src/authmanager.h + ../src/networkmanager.cpp + ../src/networkmanager.h +) + +# Link Qt modules +target_link_libraries(testauthmanager + PRIVATE + Qt6::Core + Qt6::Network + Qt6::Test +) + +# Include src directory for headers +target_include_directories(testauthmanager PRIVATE ../src) + +# Enable automoc for Q_OBJECT processing +set_target_properties(testauthmanager PROPERTIES + AUTOMOC ON +) + +# Register with CTest +add_test(NAME testauthmanager COMMAND testauthmanager) diff --git a/tests/testauthmanager.cpp b/tests/testauthmanager.cpp new file mode 100644 index 0000000..e358b70 --- /dev/null +++ b/tests/testauthmanager.cpp @@ -0,0 +1,25 @@ +#include "testauthmanager.h" +#include + +TestAuthManager::TestAuthManager(QObject *parent) : QObject{parent}, m_authManager(new AuthManager(this)) +{ +} + +void TestAuthManager::add() +{ +} + +void TestAuthManager::testSignIn() +{ + QSignalSpy codeSent(m_authManager, &AuthManager::codeSentToEmail); + m_authManager->requestSignInCode("arjun@flowylabs.ai"); + QVERIFY(codeSent.wait(5000)); + QCOMPARE(codeSent.count(), 1); + + QSignalSpy signedIn(m_authManager, &AuthManager::isSignedInChanged); + m_authManager->signIn("0000"); + QVERIFY(signedIn.wait(5000)); + QCOMPARE(signedIn.count(), 1); +} + +QTEST_MAIN(TestAuthManager) diff --git a/tests/testauthmanager.h b/tests/testauthmanager.h new file mode 100644 index 0000000..ab26549 --- /dev/null +++ b/tests/testauthmanager.h @@ -0,0 +1,26 @@ +#ifndef TESTAUTHMANAGER_H +#define TESTAUTHMANAGER_H + +#include "authmanager.h" +#include +#include + +class TestAuthManager : public QObject +{ + Q_OBJECT + +public: + explicit TestAuthManager(QObject *parent = nullptr); + +private slots: + void add(); + + void testSignIn(); + +signals: + +private: + AuthManager *m_authManager; +}; + +#endif // TESTAUTHMANAGER_H