1 /*
2 SPDX-FileCopyrightText: 2017 Csaba Kertesz <csaba.kertesz@gmail.com>
3 SPDX-FileCopyrightText: 2020 Eric Dejouhanet <eric.dejouhanet@gmail.com>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #include "kstars_ui_tests.h"
9
10 #if defined(HAVE_INDI)
11
12 #include "Options.h"
13 #include "test_ekos_wizard.h"
14 #include "test_ekos.h"
15 #include "ekos/manager.h"
16 #include "kswizard.h"
17 #include "auxiliary/kspaths.h"
18 #include "ekos/profilewizard.h"
19
20 #include <KActionCollection>
21
TestEkosWizard(QObject * parent)22 TestEkosWizard::TestEkosWizard(QObject *parent) : QObject(parent)
23 {
24 }
25
init()26 void TestEkosWizard::init()
27 {
28 }
29
cleanup()30 void TestEkosWizard::cleanup()
31 {
32 foreach (QDialog * d, KStars::Instance()->findChildren<QDialog*>())
33 if (d->isVisible())
34 d->hide();
35 }
36
testProfileWizard()37 void TestEkosWizard::testProfileWizard()
38 {
39 // Update our INDI installation specs
40 Options::setIndiDriversAreInternal(true);
41
42 // Locate INDI server - this is highly suspicious, but will cover most of the installation cases I suppose
43 if (QFile("/usr/local/bin/indiserver").exists())
44 Options::setIndiServer("/usr/local/bin/indiserver");
45 else if (QFile("/usr/bin/indiserver").exists())
46 Options::setIndiServer("/usr/bin/indiserver");
47 QVERIFY(QDir(Options::indiDriversDir()).exists());
48
49 // Locate INDI drivers - the XML list of drivers is the generic data path
50 QFile drivers(KSPaths::locate(QStandardPaths::AppDataLocation, "indidrivers.xml"));
51 if (drivers.exists())
52 Options::setIndiDriversDir(QFileInfo(drivers).dir().path());
53 QVERIFY(QDir(Options::indiDriversDir()).exists());
54
55 // The Ekos new profile wizard opens when starting Ekos for the first time
56 bool wizardDone = false;
57 std::function <void()> closeWizard = [&]
58 {
59 KStars * const k = KStars::Instance();
60 QVERIFY(k != nullptr);
61
62 // Wait for the KStars Wizard to appear
63 if(k->findChild <ProfileWizard*>() == nullptr)
64 {
65 QTimer::singleShot(500, KStars::Instance(), closeWizard);
66 return;
67 }
68 ProfileWizard * const w = k->findChild <ProfileWizard*>();
69 QVERIFY(w != nullptr);
70 QTRY_VERIFY_WITH_TIMEOUT(w->isVisible(), 1000);
71
72 // Just dismiss the wizard for now
73 QDialogButtonBox* buttons = w->findChild<QDialogButtonBox*>();
74 QVERIFY(nullptr != buttons);
75 QTest::mouseClick(buttons->button(QDialogButtonBox::Close), Qt::LeftButton);
76 QTRY_VERIFY_WITH_TIMEOUT(!w->isVisible(), 1000);
77 wizardDone = true;
78 };
79 QTimer::singleShot(500, Ekos::Manager::Instance(), closeWizard);
80
81 KTRY_OPEN_EKOS();
82 KVERIFY_EKOS_IS_OPENED();
83 QTRY_VERIFY_WITH_TIMEOUT(wizardDone, 1000);
84
85 KTRY_CLOSE_EKOS();
86 KVERIFY_EKOS_IS_HIDDEN();
87 }
88
89 // There is no test-main macro in this test because that sequence is done systematically
90
91 #endif // HAVE_INDI
92