/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include namespace O3DE::ProjectManager { class TextOverflowWidgetTests : public ::UnitTest::LeakDetectionFixture { public: static bool EndsWithOverflowLink(const QString& str) { return str.endsWith(" Read More..."); } static const int s_testLength = 10; }; TEST_F(TextOverflowWidgetTests, ElideText_UnderMaxLength_NoOverflow) { QString testStr = ""; QString resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_FALSE(EndsWithOverflowLink(resultStr)); testStr = "1234567890"; resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_FALSE(EndsWithOverflowLink(resultStr)); testStr = "1234567890"; resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_FALSE(EndsWithOverflowLink(resultStr)); } TEST_F(TextOverflowWidgetTests, ElideText_UnderMaxLength_NoTruncation) { QString testStr = ""; QString resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_TRUE(testStr == resultStr); testStr = "1234567890"; resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_TRUE(testStr == resultStr); testStr = "1234567890"; resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_TRUE(testStr == resultStr); } TEST_F(TextOverflowWidgetTests, ElideText_OverMaxLength_ShowOverflow) { QString testStr = "12345678901"; QString resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_TRUE(EndsWithOverflowLink(resultStr)); testStr = "12345678901234567890"; resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_TRUE(EndsWithOverflowLink(resultStr)); } TEST_F(TextOverflowWidgetTests, ElideText_OverMaxLength_CorrectTruncation) { QString testStr = "12345678901234567890"; QString resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_TRUE(resultStr.startsWith(QString("1234567890 "))); testStr = "12345678901234567890"; resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_TRUE(resultStr.startsWith(QString("1234567890 "))); } TEST_F(TextOverflowWidgetTests, ElideText_OverMaxLengthAtOpeningTag_OpeningTagNotIncluded) { QString testStr = "12345678901"; QString resultStr = TextOverflowLabel::ElideLinkedText(testStr, s_testLength); EXPECT_FALSE(resultStr.startsWith(QString("123456789090 "))); } } // namespace O3DE::ProjectManager