#include <QCoreApplication>
#include <QQmlContext>
#include <QQmlEngine>
#include <QtQml>
#include <QtTest>

#include "window-thumbnail-config.h"
#include "window-thumbnail-plugin.h"

namespace {

constexpr auto ThumbnailUri = "org.ukui.windowThumbnail";

}

class window_thumbnail_plugin_test : public QObject
{
    Q_OBJECT

private slots:
    void registerTypesExposesExpectedQmlTypes();
    void initializeEngineProvidesConfigContextProperty();
};

void window_thumbnail_plugin_test::registerTypesExposesExpectedQmlTypes()
{
    WindowThumbnailPlugin plugin;

    plugin.registerTypes(ThumbnailUri);

    QVERIFY(qmlTypeId(ThumbnailUri, 1, 0, "XWindowThumbnail") >= 0);
    QVERIFY(qmlTypeId(ThumbnailUri, 1, 0, "WindowThumbnailMprisModel") >= 0);
    QVERIFY(qmlTypeId(ThumbnailUri, 1, 0, "WindowThumbnailItem") >= 0);
    QVERIFY(qmlTypeId(ThumbnailUri, 1, 0, "WorkspaceThumbnailItem") >= 0);
    QVERIFY(qmlTypeId(ThumbnailUri, 1, 0, "MprisProperties") >= 0);
}

void window_thumbnail_plugin_test::initializeEngineProvidesConfigContextProperty()
{
    QQmlEngine engine;
    WindowThumbnailPlugin plugin;

    plugin.initializeEngine(&engine, ThumbnailUri);

    const QVariant property = engine.rootContext()->contextProperty(QStringLiteral("windowThumbnailConfig"));
    auto *config = qobject_cast<WindowThumbnailConfig *>(property.value<QObject *>());
    QVERIFY(config != nullptr);
}

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    window_thumbnail_plugin_test testCase;
    return QTest::qExec(&testCase, argc, argv);
}

#include "test-window-thumbnail-plugin.moc"
