File indexing completed on 2025-01-19 04:57:00
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Kevin Ottens <ervin@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 #include <testlib/qtest_gui_zanshin.h> 0008 0009 #include <KMessageWidget> 0010 0011 #include "widgets/pageviewerrorhandler.h" 0012 #include "widgets/pageview.h" 0013 0014 #include "testlib/fakejob.h" 0015 0016 class PageViewErrorHandlerTest : public QObject 0017 { 0018 Q_OBJECT 0019 private slots: 0020 void shouldHaveDefaultState() 0021 { 0022 Widgets::PageViewErrorHandler errorHandler; 0023 QVERIFY(!errorHandler.pageView()); 0024 } 0025 0026 void shouldHaveAPageView() 0027 { 0028 // GIVEN 0029 Widgets::PageViewErrorHandler errorHandler; 0030 Widgets::PageView page; 0031 0032 // WHEN 0033 errorHandler.setPageView(&page); 0034 0035 // THEN 0036 QCOMPARE(errorHandler.pageView(), &page); 0037 } 0038 0039 void shouldDisplayMessageOnJobError() 0040 { 0041 // GIVEN 0042 Widgets::PageViewErrorHandler errorHandler; 0043 Widgets::PageView page; 0044 page.show(); 0045 QVERIFY(QTest::qWaitForWindowExposed(&page)); 0046 QTest::qWait(100); 0047 0048 errorHandler.setPageView(&page); 0049 0050 auto messageWidget = page.findChild<KMessageWidget*>(QStringLiteral("messageWidget")); 0051 QVERIFY(messageWidget); 0052 QVERIFY(!messageWidget->isVisibleTo(&page)); 0053 0054 // WHEN 0055 auto job = new FakeJob(this); 0056 job->setExpectedError(1, "Bar's fault"); 0057 errorHandler.installHandler(job, "Foo Failed"); 0058 QSignalSpy spy(job, &KJob::result); 0059 QVERIFY(spy.wait(FakeJob::DURATION * 2)); 0060 0061 // THEN 0062 QVERIFY(messageWidget->isVisibleTo(&page)); 0063 QVERIFY(messageWidget->isShowAnimationRunning()); 0064 QCOMPARE(messageWidget->text(), QStringLiteral("Foo Failed: Bar's fault")); 0065 } 0066 0067 void shouldNotCrashWhenNoViewIsAvailable() 0068 { 0069 // GIVEN 0070 Widgets::PageViewErrorHandler errorHandler; 0071 0072 // WHEN 0073 auto job = new FakeJob(this); 0074 job->setExpectedError(1, "Bar's fault"); 0075 errorHandler.installHandler(job, "Foo Failed"); 0076 QSignalSpy spy(job, &KJob::result); 0077 QVERIFY(spy.wait(FakeJob::DURATION * 2)); 0078 0079 // THEN 0080 // We survive this test 0081 } 0082 }; 0083 0084 ZANSHIN_TEST_MAIN(PageViewErrorHandlerTest) 0085 0086 #include "pageviewerrorhandlertest.moc"