This commit is contained in:
Martin Marmsoler 2023-01-03 19:18:54 +01:00
parent b20faa52c2
commit 54e2c2a846
4 changed files with 66 additions and 1 deletions

View File

@ -803,4 +803,6 @@ void CommitEditor::updateButtons(bool yieldFocus) {
MenuBar::instance(this)->updateRepository();
}
QTextEdit *CommitEditor::textEdit() const { return mMessage; }
#include "CommitEditor.moc"

View File

@ -11,6 +11,7 @@ class QPushButton;
class QLabel;
class TemplateButton;
class TextEdit;
class QTextEdit;
/*!
* \brief The CommitEditor class
@ -33,7 +34,7 @@ public:
bool isStageEnabled() const;
void unstage();
bool isUnstageEnabled() const;
QString createFileList(const QStringList &list, int maxFiles);
static QString createFileList(const QStringList &list, int maxFiles);
void setMessage(const QStringList &list);
void setMessage(const QString &message);
QString message() const;
@ -45,6 +46,7 @@ public slots:
private:
void updateButtons(bool yieldFocus = true);
QTextEdit *textEdit() const;
git::Repository mRepo;
git::Diff mDiff;
@ -68,6 +70,8 @@ private:
QTextCharFormat mSpellError;
QTextCharFormat mSpellIgnore;
friend class TestCommitEditor;
};
#endif // COMMITEDITOR_H

View File

@ -112,6 +112,7 @@ test(NAME SshConfig)
test(NAME fileContextMenu NO_WIN32_OFFSCREEN)
test(NAME Setting)
test(NAME commitMessageTemplate)
test(NAME commitEditor)
option(GITTYUP_CI_TESTS "Run tests that change global settings" OFF)
if(GITTYUP_CI_TESTS)

58
test/commitEditor.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "Test.h"
#include "ui/CommitEditor.h"
#include <QTextEdit>
class TestCommitEditor : public QObject {
Q_OBJECT
private slots:
void testCreateFileList();
void applyTemplate1();
void applyTemplate2();
};
void TestCommitEditor::testCreateFileList() {
QCOMPARE(CommitEditor::createFileList({"file.txt"}, 1),
QStringLiteral("file.txt"));
QCOMPARE(CommitEditor::createFileList({"file.txt", "file2.txt"}, 1),
QStringLiteral("file.txt, and 1 more file"));
QCOMPARE(
CommitEditor::createFileList({"file.txt", "file2.txt", "file2.txt"}, 1),
QStringLiteral("file.txt, and 2 more files"));
QCOMPARE(CommitEditor::createFileList({"file.txt", "file2.txt"}, 2),
QStringLiteral("file.txt and file2.txt"));
QCOMPARE(
CommitEditor::createFileList({"file.txt", "file2.txt", "file2.txt"}, 2),
QStringLiteral("file.txt, file2.txt, and 1 more file"));
}
void TestCommitEditor::applyTemplate1() {
Test::ScratchRepository repo;
CommitEditor e(repo);
e.applyTemplate(QStringLiteral("Description: %|\nfiles: ${files:3}"),
{"file.txt"});
QCOMPARE(e.textEdit()->toPlainText(),
QStringLiteral("Description: \nfiles: file.txt"));
QCOMPARE(e.textEdit()->textCursor().position(), 13);
}
void TestCommitEditor::applyTemplate2() {
Test::ScratchRepository repo;
CommitEditor e(repo);
// Cursor after inserted files
e.applyTemplate(
QStringLiteral("Description: \nfiles: ${files:3}\nCursorPosition: %|"),
{"reallylongfilename.txt"});
QCOMPARE(
e.textEdit()->toPlainText(),
QStringLiteral(
"Description: \nfiles: reallylongfilename.txt\nCursorPosition: "));
QCOMPARE(e.textEdit()->textCursor().position(), 60);
}
TEST_MAIN(TestCommitEditor)
#include "commitEditor.moc"