keepassxc/tests/gui/attachments/TestTextAttachmentsEditWidget.cpp
Kuznetsov Oleg f2a4cc7e66
Refactor attachment handling system with enhanced UI (#12085)
* Renamed NewEntryAttachmentsDialog to EditEntryAttachmentsDialog for clarity.
* Introduced EditEntryAttachmentsDialog class to manage editing of existing attachments.
* Added functionality to preview attachments while editing them.
* Enhanced EntryAttachmentsModel with rowByKey method for better key management.
* Add image attachment support with zoom functionality.
* Add html and markdown detection.
* Improve button layout on the attachment section when editing an entry
2025-06-19 13:27:23 -04:00

49 lines
1.4 KiB
C++

#include "TestTextAttachmentsEditWidget.h"
#include <attachments/TextAttachmentsEditWidget.h>
#include <QComboBox>
#include <QMouseEvent>
#include <QPushButton>
#include <QSignalSpy>
#include <QTest>
#include <QTestMouseEvent>
#include <QTextEdit>
void TestTextAttachmentsEditWidget::initTestCase()
{
m_widget.reset(new TextAttachmentsEditWidget());
}
void TestTextAttachmentsEditWidget::testEmitTextChanged()
{
QSignalSpy textChangedSignal(m_widget.data(), &TextAttachmentsEditWidget::textChanged);
m_widget->openAttachment({.name = "test.txt", .data = {}}, attachments::OpenMode::ReadWrite);
QCoreApplication::processEvents();
auto textEdit = m_widget->findChild<QTextEdit*>("attachmentsTextEdit");
QVERIFY(textEdit);
const QByteArray NewText = "New test text";
textEdit->setText(NewText);
QVERIFY(textChangedSignal.count() > 0);
}
void TestTextAttachmentsEditWidget::testEmitPreviewButtonClicked()
{
QSignalSpy previwButtonClickedSignal(m_widget.data(), &TextAttachmentsEditWidget::previewButtonClicked);
m_widget->openAttachment({.name = "test.txt", .data = {}}, attachments::OpenMode::ReadWrite);
QCoreApplication::processEvents();
auto previewButton = m_widget->findChild<QPushButton*>("previewPushButton");
QVERIFY(previewButton);
QTest::mouseClick(previewButton, Qt::LeftButton);
QCOMPARE(previwButtonClickedSignal.count(), 1);
}