|
|
|
|
@ -18,6 +18,7 @@ extern "C" {
|
|
|
|
|
class InviteLinksTest : public QObject { |
|
|
|
|
Q_OBJECT |
|
|
|
|
private slots: |
|
|
|
|
void initTestCase() { debug_config_init(); } |
|
|
|
|
void pollLeftClick_data() { |
|
|
|
|
QTest::addColumn<bool>("outgoing"); QTest::addColumn<int>("width"); |
|
|
|
|
for (bool outgoing : {false, true}) for (int width : {280, 600}) |
|
|
|
|
@ -38,7 +39,7 @@ private slots:
|
|
|
|
|
ChatView view; MessageDelegate delegate; |
|
|
|
|
view.setModel(&model); view.setItemDelegate(&delegate); view.setFrameShape(QFrame::NoFrame); |
|
|
|
|
view.setSelectionMode(QAbstractItemView::NoSelection); view.setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
|
|
|
QFont font = view.font(); font.setPixelSize(14); view.setFont(font); |
|
|
|
|
QFont font = view.font(); font.setPointSize(10); view.setFont(font); |
|
|
|
|
view.resize(width, 400); view.show(); QTest::qWait(20); |
|
|
|
|
QSignalSpy polls(&delegate, &MessageDelegate::pollRequested); |
|
|
|
|
const QModelIndex index = model.index(0, 0); |
|
|
|
|
@ -76,6 +77,32 @@ private slots:
|
|
|
|
|
QCOMPARE(polls.count(), 2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void pollEmojiQuestion() { |
|
|
|
|
QStandardItemModel model; |
|
|
|
|
auto* message = new QStandardItem; |
|
|
|
|
const QString key(64, 'a'); |
|
|
|
|
message->setData(QString::fromUtf8("😀"), MsgTextRole); message->setData("poll", MsgContentTypeRole); |
|
|
|
|
message->setData("1001", MsgChannelIdRole); message->setData(key, MsgMessageKeyRole); |
|
|
|
|
model.appendRow(message); |
|
|
|
|
ChatView view; MessageDelegate delegate; |
|
|
|
|
view.setModel(&model); view.setItemDelegate(&delegate); view.setFrameShape(QFrame::NoFrame); |
|
|
|
|
view.setSelectionMode(QAbstractItemView::NoSelection); view.resize(300, 250); view.show(); QTest::qWait(20); |
|
|
|
|
QStyleOptionViewItem option; option.initFrom(&view); option.widget = &view; option.rect = view.visualRect(model.index(0, 0)); |
|
|
|
|
const QColor background(1, 2, 3); |
|
|
|
|
QImage image(option.rect.size(), QImage::Format_ARGB32); image.fill(background); |
|
|
|
|
QPainter painter(&image); delegate.paint(&painter, option, model.index(0, 0)); painter.end(); |
|
|
|
|
qint64 xTotal = 0, yTotal = 0, pixels = 0; |
|
|
|
|
for (int y = 0; y < image.height(); ++y) for (int x = 0; x < image.width(); ++x) { |
|
|
|
|
if (image.pixelColor(x, y) == background) continue; |
|
|
|
|
xTotal += x; yTotal += y; ++pixels; |
|
|
|
|
} |
|
|
|
|
QVERIFY(pixels > 0); |
|
|
|
|
QSignalSpy polls(&delegate, &MessageDelegate::pollRequested); |
|
|
|
|
const QPoint question(int(xTotal / pixels), int(yTotal / pixels)); // Нажимаем на реально нарисованный вопрос.
|
|
|
|
|
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, question); |
|
|
|
|
QCOMPARE(polls.count(), 1); QCOMPARE(polls.first().first().toString(), key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void reactionFooter_data() { |
|
|
|
|
QTest::addColumn<QString>("type"); QTest::addColumn<bool>("outgoing"); QTest::addColumn<int>("width"); |
|
|
|
|
for (const auto& type : {"text/plain", "audio/opus", "image/png", "video/mp4", "application/octet-stream", "poll"}) |
|
|
|
|
|