[graphics/drawy/gsoc2026] src/gui/autotests: test: add autotests for text alignment expansion and deserialization

Abdelhadi Wael <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 0b2c3f89e7b3de8716ada143f389e8cb05eab86e by Abdelhadi Wael.
Committed on 16/07/2026 at 07:57.
Pushed by mlaurent into branch 'gsoc2026'.

test: add autotests for text alignment expansion and deserialization

M  +45   -0    src/gui/autotests/textitemtest.cpp
M  +2    -0    src/gui/autotests/textitemtest.hpp

https://invent.kde.org/graphics/drawy/-/commit/0b2c3f89e7b3de8716ada143f389e8cb05eab86e

diff --git a/src/gui/autotests/textitemtest.cpp b/src/gui/autotests/textitemtest.cpp
index fdcaaf16..2c7fff8c 100644
--- a/src/gui/autotests/textitemtest.cpp
+++ b/src/gui/autotests/textitemtest.cpp
@@ -234,4 +234,49 @@ void TextItemTest::shouldTestPerRangeFormatting()
     QCOMPARE(i.property(Property::Type::FontStyle).value<QString>(), u"Normal"_s);
 }
 
+void TextItemTest::shouldTestAlignmentExpansion()
+{
+    TextItem i;
+    i.setMode(TextItem::Mode::Edit);
+    i.createTextBox(QPointF(0, 0));
+
+    QRectF before = i.boundingBox();
+    i.cursor().insertText(u"Hello"_s);
+    QRectF after = i.boundingBox();
+    QCOMPARE(before.left(), after.left());
+    QVERIFY(after.right() > before.right());
+
+    i.setProperty(Property::Type::TextAlignment, Property(u"AlignRight"_s, Property::Type::TextAlignment));
+    before = i.boundingBox();
+    i.cursor().insertText(u"Hello"_s);
+    after = i.boundingBox();
+    QCOMPARE(before.right(), after.right());
+    QVERIFY(after.left() < before.left());
+
+    i.setProperty(Property::Type::TextAlignment, Property(u"AlignCenter"_s, Property::Type::TextAlignment));
+    before = i.boundingBox();
+    i.cursor().insertText(u"Hello"_s);
+    after = i.boundingBox();
+    QCOMPARE(before.center().x(), after.center().x());
+    QVERIFY(after.left() < before.left());
+    QVERIFY(after.right() > before.right());
+}
+
+void TextItemTest::shouldTestAlignmentDeserialization()
+{
+    TextItem i;
+    i.setMode(TextItem::Mode::Edit);
+    i.createTextBox(QPointF(0, 0));
+    i.setProperty(Property::Type::TextAlignment, Property(u"AlignRight"_s, Property::Type::TextAlignment));
+    i.cursor().insertText(u"Hello World"_s);
+
+    const QJsonObject obj = i.serialize(0);
+
+    TextItem i2;
+    i2.deserialize(obj);
+
+    QCOMPARE(i2.boundingBox(), i.boundingBox());
+    QCOMPARE(i2.property(Property::Type::TextAlignment).value<QString>(), u"AlignRight"_s);
+}
+
 #include "moc_textitemtest.cpp"
diff --git a/src/gui/autotests/textitemtest.hpp b/src/gui/autotests/textitemtest.hpp
index 9abb2bc4..373bffb5 100644
--- a/src/gui/autotests/textitemtest.hpp
+++ b/src/gui/autotests/textitemtest.hpp
@@ -30,4 +30,6 @@ private Q_SLOTS:
     void shouldTestLockAspectRatioWhenResizing();
     void shouldTestUpdatePreedit();
     void shouldTestPerRangeFormatting();
+    void shouldTestAlignmentExpansion();
+    void shouldTestAlignmentDeserialization();
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.