diff --git a/packages/react-native/React/Tests/Text/RCTAttributedTextUtilsTest.mm b/packages/react-native/React/Tests/Text/RCTAttributedTextUtilsTest.mm index a02622d5d7d7..242e40e644ae 100644 --- a/packages/react-native/React/Tests/Text/RCTAttributedTextUtilsTest.mm +++ b/packages/react-native/React/Tests/Text/RCTAttributedTextUtilsTest.mm @@ -43,6 +43,15 @@ static NSTextAlignment NSTextAlignmentFromTextAlign(NSString *textAlign, LayoutD return paragraphStyle.alignment; } +static NSParagraphStyle *ParagraphStyleFromLayoutDirection(std::optional layoutDirection) +{ + TextAttributes textAttributes; + textAttributes.layoutDirection = layoutDirection; + + NSDictionary *attributes = RCTNSTextAttributesFromTextAttributes(textAttributes); + return attributes[NSParagraphStyleAttributeName]; +} + static UIFont *FontFromSettings(std::optional settings, std::optional weight = std::nullopt) { TextAttributes textAttributes; @@ -133,6 +142,22 @@ - (void)testTextAlignmentStartAndEndResolveWithLayoutDirection XCTAssertEqual(NSTextAlignmentFromTextAlign(@"end", LayoutDirection::RightToLeft), NSTextAlignmentLeft); } +- (void)testUndeclaredTextAlignmentResolvesWithLayoutDirection +{ + NSParagraphStyle *leftToRight = ParagraphStyleFromLayoutDirection(LayoutDirection::LeftToRight); + XCTAssertNotNil(leftToRight); + XCTAssertEqual(leftToRight.alignment, NSTextAlignmentLeft); + + NSParagraphStyle *rightToLeft = ParagraphStyleFromLayoutDirection(LayoutDirection::RightToLeft); + XCTAssertNotNil(rightToLeft); + XCTAssertEqual(rightToLeft.alignment, NSTextAlignmentRight); +} + +- (void)testUndeclaredTextAlignmentWithoutLayoutDirectionStaysNatural +{ + XCTAssertNil(ParagraphStyleFromLayoutDirection(std::nullopt)); +} + - (void)testSamenessOfEmptyAttributedStrings { NSAttributedString *attributedString1 = [[NSAttributedString alloc] initWithString:@""];