// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>

#include <QMap>
#include <QTestEventList>
#include <QObject>
#include <QDialog>
#include <QStringList>

#include <DSearchEdit>
#include <DFileDialog>

#define private public
#define protected public

#include "mainwindow.h"
#include "importtimelineview.h"
#include "albumcreatedialog.h"
#include "test_qtestDefine.h"
#include "imginfodialog.h"
#include "imageengine/imageengineapi.h"
#include "ac-desktop-define.h"

#include <stub-tool/cpp-stub/stub.h>
#include <stub-tool/stub-ext/stubext.h>


TEST(ImportTimeLineView, getIBaseHeight_test)
{
    TEST_CASE_NAME("getIBaseHeight_test")
    MainWindow *w = dApp->getMainWindow();
    w->albumBtnClicked();
    QTest::qWait(500);

    ImportTimeLineView *impTimeline = w->m_pAlbumview->m_pImpTimeLineView;
    int a = 0;
    stub_ext::StubExt stu;
    stu.set_lamda(ADDR(DSlider, value), [&a]() {
        return a++;
    });
    for (int i = 0; i < 10; i++) {
        impTimeline->getIBaseHeight();
    }
    impTimeline->onSuspensionChoseBtnClicked();
    impTimeline->slotNoPicOrNoVideo(true);
    impTimeline->selectPaths();
    QTest::qWait(500);
}


TEST(ImportTimeLineView, test_func)
{
    TEST_CASE_NAME("test_func")
    MainWindow *w = dApp->getMainWindow();
    w->albumBtnClicked();
    QTest::qWait(500);

    w->allPicBtnClicked();
    w->albumBtnClicked();
    QTest::qWait(500);
}

TEST(ImportTimeLineView, on_KeyEvent_test)
{
    TEST_CASE_NAME("on_KeyEvent_test")
    MainWindow *w = dApp->getMainWindow();
    w->albumBtnClicked();
    QTest::qWait(500);
//todo
//    ImportTimeLineView *impTimeline = w->m_pAlbumview->m_pImpTimeLineView;
//    impTimeline->on_KeyEvent(Qt::Key_PageDown);
//    QTest::qWait(100);
//    impTimeline->on_KeyEvent(Qt::Key_PageUp);
//    QTest::qWait(500);
}

TEST(ImportTimeLineView, resizeHand_test)
{
    TEST_CASE_NAME("resizeHand_test")
    MainWindow *w = dApp->getMainWindow();
    w->albumBtnClicked();
    QTest::qWait(500);
    ImportTimeLineView *impTimeline = w->m_pAlbumview->m_pImpTimeLineView;
}

TEST(ImportTimeLineView, thumbnaillistViewSlot_test)
{
    TEST_CASE_NAME("thumbnaillistViewSlot_test")
    QTest::qWait(500);
    MainWindow *w = dApp->getMainWindow();
    QTestEventList event;
    event.addMouseClick(Qt::MouseButton::LeftButton);
    event.simulate(w->getButG()->button(2));
    event.clear();
    QTest::qWait(300);
    AlbumView *a = w->m_pAlbumview;
    event.addMousePress(Qt::MouseButton::LeftButton, Qt::NoModifier, QPoint(10, 10));
    event.addMouseRelease(Qt::MouseButton::LeftButton, Qt::NoModifier, QPoint(10, 10));
    event.simulate(a->m_pLeftListView->m_pPhotoLibListView->viewport());
    QTest::qWait(1000);
}

//已导入页面再次导入图片
TEST(ImportTimeLineView, Picimport)
{
    TEST_CASE_NAME("Picimport")
    QStringList list;
    QStringList listtemp = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
    if (listtemp.size() > 0) {
        list << listtemp.at(0) + "/second";
    }

    qDebug() << "Picture count = " << list.size() << (list.isEmpty() ? QString("") : list.at(0));
    MainWindow *w = dApp->getMainWindow();
    w->getButG();
    w->allPicBtnClicked();

    AllPicView *allpicview = w->m_pAllPicView;
    ImageEngineApi::instance()->ImportImagesFromFileList(list, "", -1, allpicview, true);
    allpicview->update();
    QTest::qWait(2000);

    QTestEventList event;

    event.addMouseClick(Qt::MouseButton::LeftButton);
    event.simulate(w->getButG()->button(1));
    QTest::qWait(300);
    event.simulate(w->getButG()->button(2));
    QTest::qWait(300);
    event.simulate(w->getButG()->button(0));
    event.clear();
    QTest::qWait(300);
    ASSERT_TRUE(w != nullptr);
}
