]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/dolphinmainwindowtest.cpp
[KStandardItemListWidget] Pass icon state to overlay painter
[dolphin.git] / src / tests / dolphinmainwindowtest.cpp
index 70ec8dba04dd91f1e624c1002c6a288b4c608c79..0dc33012418f3aba196f0848c28f8fb22ae51ddb 100644 (file)
@@ -18,6 +18,7 @@
  ***************************************************************************/
 
 #include "dolphinmainwindow.h"
+#include "dolphinnewfilemenu.h"
 #include "dolphintabpage.h"
 #include "dolphintabwidget.h"
 #include "dolphinviewcontainer.h"
@@ -25,6 +26,7 @@
 #include <KActionCollection>
 
 #include <QSignalSpy>
+#include <QStandardPaths>
 #include <QTest>
 
 class DolphinMainWindowTest : public QObject
@@ -32,16 +34,24 @@ class DolphinMainWindowTest : public QObject
     Q_OBJECT
 
 private slots:
+    void initTestCase();
     void init();
     void testClosingTabsWithSearchBoxVisible();
     void testActiveViewAfterClosingSplitView_data();
     void testActiveViewAfterClosingSplitView();
     void testUpdateWindowTitleAfterClosingSplitView();
+    void testNewFileMenuEnabled_data();
+    void testNewFileMenuEnabled();
 
 private:
     QScopedPointer<DolphinMainWindow> m_mainWindow;
 };
 
+void DolphinMainWindowTest::initTestCase()
+{
+    QStandardPaths::setTestModeEnabled(true);
+}
+
 void DolphinMainWindowTest::init()
 {
     m_mainWindow.reset(new DolphinMainWindow());
@@ -163,6 +173,31 @@ void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView()
     QCOMPARE(currentUrlChangedSpy.count(), 1);
 }
 
+void DolphinMainWindowTest::testNewFileMenuEnabled_data()
+{
+    QTest::addColumn<QUrl>("activeViewUrl");
+    QTest::addColumn<bool>("expectedEnabled");
+
+    QTest::newRow("home") << QUrl::fromLocalFile(QDir::homePath()) << true;
+    QTest::newRow("root") << QUrl::fromLocalFile(QDir::rootPath()) << false;
+    QTest::newRow("trash") << QUrl::fromUserInput(QStringLiteral("trash:/")) << false;
+}
+
+void DolphinMainWindowTest::testNewFileMenuEnabled()
+{
+    QFETCH(QUrl, activeViewUrl);
+    m_mainWindow->openDirectories({ activeViewUrl }, false);
+    m_mainWindow->show();
+    QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+    QVERIFY(m_mainWindow->isVisible());
+
+    auto newFileMenu = m_mainWindow->findChild<DolphinNewFileMenu*>("newFileMenu");
+    QVERIFY(newFileMenu);
+
+    QFETCH(bool, expectedEnabled);
+    QCOMPARE(newFileMenu->isEnabled(), expectedEnabled);
+}
+
 QTEST_MAIN(DolphinMainWindowTest)
 
 #include "dolphinmainwindowtest.moc"