@@ -27,6 +27,7 @@ final class LCLabelTests: XCTestCase {
2727 matching: label,
2828 as: . image,
2929 snapshotDirectory: path)
30+ XCTAssertEqual ( attStr. string, label. accessibilityIdentifier)
3031 guard let message = failure else { return }
3132 XCTFail ( message)
3233 }
@@ -363,6 +364,64 @@ final class LCLabelTests: XCTestCase {
363364 XCTFail ( message)
364365 }
365366
367+ func testTextString( ) {
368+ let label = LCLabel ( frame: . zero)
369+ label. frame = CGRect ( x: 0 , y: 0 , width: 300 , height: 40 )
370+ label. centeringTextAlignment = . center
371+ label. numberOfLines = 1
372+ label. backgroundColor = . black
373+ label. text = " Welcome "
374+ label. textColor = . red
375+ label. textAlignment = . center
376+ label. font = . systemFont( ofSize: 10 )
377+ let failure = verifySnapshot (
378+ matching: label,
379+ as: . image,
380+ snapshotDirectory: path)
381+ guard let message = failure else { return }
382+ XCTFail ( message)
383+ }
384+
385+ func testMultiLineTextString( ) {
386+ let label = LCLabel ( frame: . zero)
387+ label. frame = CGRect ( x: 0 , y: 0 , width: 300 , height: 40 )
388+ label. centeringTextAlignment = . center
389+ label. numberOfLines = 2
390+ label. backgroundColor = . black
391+ label
392+ . text =
393+ " Welcome to a very long long text that should be added to two different lines "
394+ label. textColor = . red
395+ label. textAlignment = . center
396+ label. font = . systemFont( ofSize: 10 )
397+ let failure = verifySnapshot (
398+ matching: label,
399+ as: . image,
400+ snapshotDirectory: path)
401+ guard let message = failure else { return }
402+ XCTFail ( message)
403+ }
404+
405+ func testMultiLinePreSetupTextString( ) {
406+ let label = LCLabel ( frame: . zero)
407+ label. frame = CGRect ( x: 0 , y: 0 , width: 300 , height: 40 )
408+ label. centeringTextAlignment = . center
409+ label. numberOfLines = 2
410+ label. backgroundColor = . black
411+ label. textColor = . red
412+ label. font = . systemFont( ofSize: 10 )
413+ label. textAlignment = . center
414+ label
415+ . text =
416+ " Welcome to a very long long text that should be added to two different lines "
417+ let failure = verifySnapshot (
418+ matching: label,
419+ as: . image,
420+ snapshotDirectory: path)
421+ guard let message = failure else { return }
422+ XCTFail ( message)
423+ }
424+
366425 func testStringWithoutValidations( ) {
367426 let attStr = NSMutableAttributedString (
368427 string: " LCLabel " ,
@@ -613,6 +672,66 @@ final class LCLabelTests: XCTestCase {
613672 XCTFail ( message)
614673 }
615674
675+ func testURLHitTest( ) {
676+ let attStr = NSMutableAttributedString (
677+ string: " LCLabel " ,
678+ attributes: [
679+ . foregroundColor: UIColor . white,
680+ . font: UIFont . systemFont ( ofSize: 14 ) ,
681+ ] )
682+ attStr. append ( NSAttributedString (
683+ string: " \n @LCLabel " ,
684+ attributes: [
685+ . foregroundColor: UIColor . white,
686+ . font: UIFont . systemFont ( ofSize: 10 ) ,
687+ . link: URL ( string: " lclabel://welcome " ) !,
688+ ] ) )
689+ let rect = CGRect ( x: 0 , y: 0 , width: 300 , height: 40 )
690+ let label = LCLabel ( frame: . zero)
691+ label. isUserInteractionEnabled = true
692+ label. frame = rect
693+ label. centeringTextAlignment = . center
694+ label. numberOfLines = 2
695+ label. linkStyleValidation = . ensure
696+ label. linkAttributes = [
697+ . foregroundColor: UIColor . green,
698+ . font: UIFont . systemFont ( ofSize: 12 ) ,
699+ ]
700+ label. attributedText = attStr
701+ label. drawText ( in: rect)
702+ XCTAssertEqual ( label. hitTest ( CGPoint ( x: 20 , y: 25 ) , with: nil ) , label)
703+ }
704+
705+ func testStringHitTest( ) {
706+ let attStr = NSMutableAttributedString (
707+ string: " LCLabel " ,
708+ attributes: [
709+ . foregroundColor: UIColor . white,
710+ . font: UIFont . systemFont ( ofSize: 14 ) ,
711+ ] )
712+ attStr. append ( NSAttributedString (
713+ string: " \n @LCLabel " ,
714+ attributes: [
715+ . foregroundColor: UIColor . white,
716+ . font: UIFont . systemFont ( ofSize: 10 ) ,
717+ . link: " lclabel://welcome " ,
718+ ] ) )
719+ let rect = CGRect ( x: 0 , y: 0 , width: 300 , height: 40 )
720+ let label = LCLabel ( frame: . zero)
721+ label. isUserInteractionEnabled = true
722+ label. frame = rect
723+ label. centeringTextAlignment = . center
724+ label. numberOfLines = 2
725+ label. linkStyleValidation = . ensure
726+ label. linkAttributes = [
727+ . foregroundColor: UIColor . green,
728+ . font: UIFont . systemFont ( ofSize: 12 ) ,
729+ ]
730+ label. attributedText = attStr
731+ label. drawText ( in: rect)
732+ XCTAssertEqual ( label. hitTest ( CGPoint ( x: 20 , y: 25 ) , with: nil ) , label)
733+ }
734+
616735 // MARK: Private
617736
618737 private func createLabel(
0 commit comments