diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -1066,6 +1066,7 @@ { // setup 'File' menu m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this); + m_newFileMenu->setObjectName("newFileMenu"); QMenu* menu = m_newFileMenu->menu(); menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -18,6 +18,7 @@ ***************************************************************************/ #include "dolphinmainwindow.h" +#include "dolphinnewfilemenu.h" #include "dolphintabpage.h" #include "dolphintabwidget.h" #include "dolphinviewcontainer.h" @@ -39,6 +40,8 @@ void testActiveViewAfterClosingSplitView_data(); void testActiveViewAfterClosingSplitView(); void testUpdateWindowTitleAfterClosingSplitView(); + void testNewFileMenuEnabled_data(); + void testNewFileMenuEnabled(); private: QScopedPointer m_mainWindow; @@ -170,6 +173,31 @@ QCOMPARE(currentUrlChangedSpy.count(), 1); } +void DolphinMainWindowTest::testNewFileMenuEnabled_data() +{ + QTest::addColumn("activeViewUrl"); + QTest::addColumn("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("newFileMenu"); + QVERIFY(newFileMenu); + + QFETCH(bool, expectedEnabled); + QCOMPARE(newFileMenu->isEnabled(), expectedEnabled); +} + QTEST_MAIN(DolphinMainWindowTest) #include "dolphinmainwindowtest.moc"