2018-12-13 02:22:04 +03:00
|
|
|
//
|
|
|
|
// Copyright (c) 2016, Scientific Toolworks, Inc.
|
|
|
|
//
|
|
|
|
// This software is licensed under the MIT License. The LICENSE.md file
|
|
|
|
// describes the conditions under which this software may be distributed.
|
|
|
|
//
|
|
|
|
// Author: Jason Haslam
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Test.h"
|
|
|
|
#include "editor/TextEditor.h"
|
|
|
|
#include "ui/BlameEditor.h"
|
|
|
|
#include "ui/EditorWindow.h"
|
|
|
|
#include "ui/FindWidget.h"
|
|
|
|
#include "ui/MenuBar.h"
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
using namespace QTest;
|
|
|
|
|
2022-05-01 10:51:34 +03:00
|
|
|
class TestEditor : public QObject {
|
2018-12-13 02:22:04 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
void insertText();
|
|
|
|
void copyPaste();
|
|
|
|
void find();
|
|
|
|
void cleanupTestCase();
|
|
|
|
|
|
|
|
private:
|
|
|
|
EditorWindow *mWindow = nullptr;
|
|
|
|
BlameEditor *mBlameEditor = nullptr;
|
|
|
|
TextEditor *mEditor = nullptr;
|
|
|
|
};
|
|
|
|
|
2022-05-01 10:51:34 +03:00
|
|
|
void TestEditor::initTestCase() {
|
2018-12-13 02:22:04 +03:00
|
|
|
mWindow = new EditorWindow;
|
|
|
|
mBlameEditor = mWindow->widget();
|
|
|
|
mEditor = mBlameEditor->editor();
|
|
|
|
mWindow->show();
|
|
|
|
QVERIFY(qWaitForWindowActive(mWindow));
|
|
|
|
}
|
|
|
|
|
2022-05-01 10:51:34 +03:00
|
|
|
void TestEditor::insertText() {
|
2018-12-13 02:22:04 +03:00
|
|
|
keyClicks(mEditor, "This is a test.");
|
|
|
|
keyClick(mEditor, Qt::Key_Return);
|
|
|
|
}
|
|
|
|
|
2022-05-01 10:51:34 +03:00
|
|
|
void TestEditor::copyPaste() {
|
2018-12-13 02:22:04 +03:00
|
|
|
keyClick(mEditor, 'A', Qt::ControlModifier);
|
|
|
|
keyClick(mEditor, 'C', Qt::ControlModifier);
|
|
|
|
keyClick(mEditor, Qt::Key_Down);
|
|
|
|
keyClick(mEditor, 'V', Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
2022-05-01 10:51:34 +03:00
|
|
|
void TestEditor::find() {
|
2022-06-19 16:33:16 +03:00
|
|
|
// It's difficult to trigger the shortcut on macOS.
|
2018-12-13 02:22:04 +03:00
|
|
|
MenuBar *menuBar = MenuBar::instance(mWindow);
|
|
|
|
QAction *findAction = menuBar->findChild<QAction *>("Find");
|
|
|
|
QVERIFY(findAction);
|
|
|
|
findAction->trigger();
|
|
|
|
|
|
|
|
FindWidget *find = mBlameEditor->findChild<FindWidget *>();
|
|
|
|
QVERIFY(find);
|
|
|
|
|
|
|
|
QLineEdit *field = find->findChild<QLineEdit *>();
|
|
|
|
QVERIFY(field && field->hasFocus());
|
|
|
|
|
|
|
|
keyClicks(field, "test");
|
|
|
|
QLabel *label = find->findChild<QLabel *>();
|
|
|
|
QCOMPARE(label->text(), QString("2 matches"));
|
|
|
|
}
|
|
|
|
|
2022-05-01 10:51:34 +03:00
|
|
|
void TestEditor::cleanupTestCase() {
|
2018-12-13 02:22:04 +03:00
|
|
|
// Set up timer to dismiss the dialog.
|
|
|
|
QTimer::singleShot(0, [] {
|
|
|
|
QMessageBox *dialog =
|
2022-05-01 10:51:34 +03:00
|
|
|
qobject_cast<QMessageBox *>(QApplication::activeModalWidget());
|
2018-12-13 02:22:04 +03:00
|
|
|
QVERIFY(dialog && qWaitForWindowActive(dialog));
|
|
|
|
|
|
|
|
QDialogButtonBox *buttons = dialog->findChild<QDialogButtonBox *>();
|
|
|
|
QVERIFY(buttons);
|
|
|
|
|
|
|
|
QPushButton *discard = buttons->button(QDialogButtonBox::Discard);
|
|
|
|
QVERIFY(discard);
|
|
|
|
|
|
|
|
mouseClick(discard, Qt::LeftButton);
|
|
|
|
QVERIFY(!dialog->isVisible());
|
|
|
|
});
|
|
|
|
|
|
|
|
mWindow->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_MAIN(TestEditor)
|
|
|
|
|
|
|
|
#include "editor.moc"
|