|
|
|
|
@ -46,6 +46,47 @@ static bool dropUrls(QWidget* target, const QList<QUrl>& urls, bool process = tr
|
|
|
|
|
class FileDropTest : public QObject { |
|
|
|
|
Q_OBJECT |
|
|
|
|
private slots: |
|
|
|
|
void replyDraftAndLateResults() { |
|
|
|
|
InputBar bar(nullptr, nullptr); bar.resize(600, 160); bar.show(); bar.setRecordingContext("/tmp", "123"); |
|
|
|
|
auto* editor = bar.findChild<QTextEdit*>(); QVERIFY(editor); |
|
|
|
|
QSignalSpy sends(&bar, &InputBar::sendMessage); |
|
|
|
|
const QByteArray first(32, 'a'), second(32, 'b'); |
|
|
|
|
bar.setReply(first, "Alice", "Original"); editor->setPlainText("answer"); |
|
|
|
|
QTest::keyClick(editor, Qt::Key_Return); QCOMPARE(sends.size(), 1); |
|
|
|
|
QCOMPARE(sends[0][1].toByteArray(), first); const quint64 id = sends[0][2].toULongLong(); QVERIFY(id); |
|
|
|
|
QCOMPARE(editor->toPlainText(), QString("answer")); |
|
|
|
|
QTest::keyClick(editor, Qt::Key_Return); QCOMPARE(sends.size(), 1); // Не отправлять повторно до результата.
|
|
|
|
|
bar.submissionResult(id, false); QCOMPARE(editor->toPlainText(), QString("answer")); |
|
|
|
|
QTest::keyClick(editor, Qt::Key_Return); QCOMPARE(sends.size(), 2); |
|
|
|
|
bar.setReply(second, "Bob", "Another original"); editor->setPlainText("new draft"); |
|
|
|
|
bar.submissionResult(sends[1][2].toULongLong(), true); QCOMPARE(editor->toPlainText(), QString("new draft")); |
|
|
|
|
QTest::keyClick(editor, Qt::Key_Return); QCOMPARE(sends.size(), 3); QCOMPARE(sends[2][1].toByteArray(), second); |
|
|
|
|
bar.submissionResult(sends[2][2].toULongLong(), true); QVERIFY(editor->toPlainText().isEmpty()); |
|
|
|
|
editor->setPlainText("ordinary"); QTest::keyClick(editor, Qt::Key_Return); QVERIFY(sends[3][1].toByteArray().isEmpty()); |
|
|
|
|
bar.setReply(first, "Alice", "Original"); QTest::keyClick(editor, Qt::Key_Escape); |
|
|
|
|
editor->setPlainText("cancelled"); QTest::keyClick(editor, Qt::Key_Return); QVERIFY(sends[4][1].toByteArray().isEmpty()); |
|
|
|
|
bar.setReply(first, "Alice", "Original"); bar.setRecordingContext("/tmp", "456"); |
|
|
|
|
editor->setPlainText("other channel"); QTest::keyClick(editor, Qt::Key_Return); QVERIFY(sends[5][1].toByteArray().isEmpty()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void replyAttachmentAndTextHaveIndependentResults() { |
|
|
|
|
QTemporaryDir dir; QVERIFY(dir.isValid()); const QString file = makeFile(dir, "answer.txt"); |
|
|
|
|
InputBar bar(nullptr, nullptr); bar.resize(600, 180); bar.show(); bar.setRecordingContext(dir.path(), "123"); |
|
|
|
|
auto* editor = bar.findChild<QTextEdit*>(); QVERIFY(editor); |
|
|
|
|
const QByteArray original(32, 'a'); bar.setReply(original, "Alice", "original"); |
|
|
|
|
QVERIFY(dropUrls(editor->viewport(), {QUrl::fromLocalFile(file)})); editor->setPlainText("answer"); |
|
|
|
|
QSignalSpy files(&bar, &InputBar::sendFileAttachment), texts(&bar, &InputBar::sendMessage); |
|
|
|
|
QTest::keyClick(editor, Qt::Key_Return); QCOMPARE(files.size(), 1); QCOMPARE(texts.size(), 1); |
|
|
|
|
QCOMPARE(files[0][4].toByteArray(), original); QCOMPARE(texts[0][1].toByteArray(), original); |
|
|
|
|
QVERIFY(files[0][5].toULongLong() != texts[0][2].toULongLong()); |
|
|
|
|
bar.submissionResult(texts[0][2].toULongLong(), true); QVERIFY(editor->toPlainText().isEmpty()); |
|
|
|
|
bar.submissionResult(files[0][5].toULongLong(), false); |
|
|
|
|
QTest::keyClick(editor, Qt::Key_Return); QCOMPARE(files.size(), 2); QCOMPARE(texts.size(), 1); |
|
|
|
|
QCOMPARE(files[1][4].toByteArray(), original); |
|
|
|
|
bar.submissionResult(files[1][5].toULongLong(), true); |
|
|
|
|
editor->setPlainText("next"); QTest::keyClick(editor, Qt::Key_Return); QVERIFY(texts[1][1].toByteArray().isEmpty()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void initTestCase() { |
|
|
|
|
debug_config_init(); debug_set_category_level(DEBUG_CATEGORY_GENERAL, DEBUG_LEVEL_DEBUG); |
|
|
|
|
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs); |
|
|
|
|
|