#include "tray_visuals.h"

#include <QtTest/QtTest>

class TrayVisualsTest : public QObject {
    Q_OBJECT

private slots:
    void backendUnavailableUsesIssueIcon();
    void runningExitNodeUsesExitIcon();
    void runningAdvertiseExitUsesAsExitIcon();
    void startingAlternatesConnectingIcons();
    void stoppedUsesDisconnectedIcon();
};

void TrayVisualsTest::backendUnavailableUsesIssueIcon()
{
    QCOMPARE(trayIconStateForSnapshot(QJsonObject{}, false, true), TrayIconState::Issue);
}

void TrayVisualsTest::runningExitNodeUsesExitIcon()
{
    const QJsonObject snapshot{
        {QStringLiteral("backendState"), QStringLiteral("Running")},
        {QStringLiteral("prefs"),
         QJsonObject{
             {QStringLiteral("advertisesExitNode"), false},
             {QStringLiteral("exitNodeID"), QStringLiteral("node-123")},
         }},
    };

    QCOMPARE(trayIconStateForSnapshot(snapshot, true, true), TrayIconState::ExitNode);
}

void TrayVisualsTest::runningAdvertiseExitUsesAsExitIcon()
{
    const QJsonObject snapshot{
        {QStringLiteral("backendState"), QStringLiteral("Running")},
        {QStringLiteral("prefs"),
         QJsonObject{
             {QStringLiteral("advertisesExitNode"), true},
         }},
    };

    QCOMPARE(trayIconStateForSnapshot(snapshot, true, true), TrayIconState::AsExitNode);
}

void TrayVisualsTest::startingAlternatesConnectingIcons()
{
    const QJsonObject snapshot{
        {QStringLiteral("backendState"), QStringLiteral("Starting")},
    };

    QCOMPARE(trayIconStateForSnapshot(snapshot, true, true), TrayIconState::ConnectingA);
    QCOMPARE(trayIconStateForSnapshot(snapshot, true, false), TrayIconState::ConnectingB);
}

void TrayVisualsTest::stoppedUsesDisconnectedIcon()
{
    const QJsonObject snapshot{
        {QStringLiteral("backendState"), QStringLiteral("Stopped")},
    };

    QCOMPARE(trayIconStateForSnapshot(snapshot, true, true), TrayIconState::Disconnected);
}

QTEST_MAIN(TrayVisualsTest)

#include "tray_visuals_test.moc"
