File indexing completed on 2024-05-12 05:52:02

0001 #include "diffwidget_tests.h"
0002 #include "diffwidget.h"
0003 
0004 #include <QScrollBar>
0005 #include <QTest>
0006 
0007 QTEST_MAIN(DiffWidgetTests)
0008 
0009 void DiffWidgetTests::test_scrollbarAtTopOnOpen()
0010 {
0011     QFile f(QStringLiteral(":/katetest/test.diff"));
0012     QVERIFY(f.open(QFile::ReadOnly));
0013     const auto diff = f.readAll();
0014 
0015     DiffWidget dw(DiffParams{});
0016     dw.show();
0017     dw.m_style = SideBySide;
0018 
0019     dw.openDiff(diff);
0020 
0021     qApp->processEvents();
0022 
0023     // Test not empty
0024     QVERIFY(!dw.m_left->document()->isEmpty());
0025     QVERIFY(!dw.m_right->document()->isEmpty());
0026 
0027     // Scrollbar should be at the top
0028     QCOMPARE(dw.m_left->verticalScrollBar()->value(), 0);
0029     QCOMPARE(dw.m_right->verticalScrollBar()->value(), 0);
0030 
0031     // Clear
0032     dw.clearData();
0033     // After clear both should be empty
0034     QVERIFY(dw.m_left->document()->isEmpty());
0035     QVERIFY(dw.m_right->document()->isEmpty());
0036 
0037     // Change to unified
0038     dw.m_style = Unified;
0039     dw.openDiff(diff);
0040     qApp->processEvents();
0041 
0042     QVERIFY(!dw.m_left->document()->isEmpty());
0043     QVERIFY(dw.m_right->document()->isEmpty()); // In Unified, right is empty
0044 
0045     QCOMPARE(dw.m_left->verticalScrollBar()->value(), 0);
0046 }
0047 
0048 #include "moc_diffwidget_tests.cpp"