@@ -25,6 +25,11 @@ import SnapshotTesting
25
25
@testable import Proton
26
26
27
27
class EditorSnapshotTests : SnapshotTestCase {
28
+ override func setUp( ) {
29
+ super. setUp ( )
30
+ recordMode = false
31
+ }
32
+
28
33
func testRendersPlaceholder( ) {
29
34
let viewController = EditorTestViewController ( height: 80 )
30
35
let editor = viewController. editor
@@ -783,6 +788,134 @@ class EditorSnapshotTests: SnapshotTestCase {
783
788
assertSnapshot ( matching: viewController. view, as: . image, record: recordMode)
784
789
}
785
790
791
+ func testBackgroundStyleWithHeightMatchingText( ) {
792
+ let viewController = EditorTestViewController ( )
793
+ let editor = viewController. editor
794
+
795
+ let text =
796
+ """
797
+ Line 1 Text \n Line 2 Text
798
+ """
799
+
800
+ let rangeToUpdate = NSRange ( location: 5 , length: 14 )
801
+
802
+ editor. appendCharacters ( NSAttributedString ( string: text) )
803
+ viewController. render ( )
804
+ let backgroundStyle = BackgroundStyle ( color: . cyan. withAlphaComponent ( 0.5 ) ,
805
+ roundedCornerStyle: . relative( percent: 50 ) ,
806
+ border: BorderStyle ( lineWidth: 1 , color: . yellow) ,
807
+ hasSquaredOffJoins: true ,
808
+ heightMode: . matchText)
809
+ editor. addAttributes ( [
810
+ . backgroundStyle: backgroundStyle
811
+ ] , at: rangeToUpdate)
812
+
813
+ viewController. render ( size: CGSize ( width: 130 , height: 100 ) )
814
+ assertSnapshot ( matching: viewController. view, as: . image, record: recordMode)
815
+ }
816
+
817
+ func testBackgroundStyleWithTextContainerInsets( ) {
818
+ let viewController = EditorTestViewController ( )
819
+ let editor = viewController. editor
820
+ editor. textContainerInset = UIEdgeInsets ( top: 10 , left: 10 , bottom: 10 , right: 10 )
821
+ let text =
822
+ """
823
+ Line 1 Text \n Line 2 Text
824
+ """
825
+
826
+ let rangeToUpdate = NSRange ( location: 5 , length: 14 )
827
+
828
+ editor. appendCharacters ( NSAttributedString ( string: text) )
829
+ viewController. render ( )
830
+ let backgroundStyle = BackgroundStyle ( color: . cyan,
831
+ roundedCornerStyle: . relative( percent: 50 ) ,
832
+ hasSquaredOffJoins: true ,
833
+ heightMode: . matchText)
834
+ editor. addAttributes ( [
835
+ . backgroundStyle: backgroundStyle
836
+ ] , at: rangeToUpdate)
837
+
838
+ viewController. render ( size: CGSize ( width: 160 , height: 100 ) )
839
+ assertSnapshot ( matching: viewController. view, as: . image, record: recordMode)
840
+ }
841
+
842
+ func testBackgroundStyleWithOverlappingLineNoBorder( ) {
843
+ let viewController = EditorTestViewController ( )
844
+ let editor = viewController. editor
845
+
846
+ let text =
847
+ """
848
+ Line 1 Text \n Line 2 Text
849
+ """
850
+
851
+ let rangeToUpdate = NSRange ( location: 5 , length: 14 )
852
+
853
+ editor. appendCharacters ( NSAttributedString ( string: text) )
854
+ viewController. render ( )
855
+ let backgroundStyle = BackgroundStyle ( color: . cyan,
856
+ roundedCornerStyle: . relative( percent: 50 ) ,
857
+ hasSquaredOffJoins: true ,
858
+ heightMode: . matchText)
859
+ editor. addAttributes ( [
860
+ . backgroundStyle: backgroundStyle
861
+ ] , at: rangeToUpdate)
862
+
863
+ viewController. render ( size: CGSize ( width: 130 , height: 100 ) )
864
+ assertSnapshot ( matching: viewController. view, as: . image, record: recordMode)
865
+ }
866
+
867
+ func testBackgroundStyleWithOverlappingLine( ) {
868
+ let viewController = EditorTestViewController ( )
869
+ let editor = viewController. editor
870
+
871
+ let text =
872
+ """
873
+ Line 1 Text \n Line 2 Text
874
+ """
875
+
876
+ let rangeToUpdate = NSRange ( location: 5 , length: 16 )
877
+
878
+ editor. appendCharacters ( NSAttributedString ( string: text) )
879
+ viewController. render ( )
880
+ let backgroundStyle = BackgroundStyle ( color: . cyan,
881
+ roundedCornerStyle: . relative( percent: 50 ) ,
882
+ border: BorderStyle ( lineWidth: 1 , color: . black) ,
883
+ hasSquaredOffJoins: true ,
884
+ heightMode: . matchText)
885
+ editor. addAttributes ( [
886
+ . backgroundStyle: backgroundStyle
887
+ ] , at: rangeToUpdate)
888
+
889
+ viewController. render ( size: CGSize ( width: 150 , height: 100 ) )
890
+ assertSnapshot ( matching: viewController. view, as: . image, record: recordMode)
891
+ }
892
+
893
+ func testBackgroundStyleWithOverlappingLineExactTextHeight( ) {
894
+ let viewController = EditorTestViewController ( )
895
+ let editor = viewController. editor
896
+
897
+ let text =
898
+ """
899
+ Line 1 Text \n Line 2 Text
900
+ """
901
+
902
+ let rangeToUpdate = NSRange ( location: 5 , length: 16 )
903
+
904
+ editor. appendCharacters ( NSAttributedString ( string: text) )
905
+ viewController. render ( )
906
+ let backgroundStyle = BackgroundStyle ( color: . cyan,
907
+ roundedCornerStyle: . relative( percent: 50 ) ,
908
+ // border: BorderStyle(lineWidth: 1, color: .black),
909
+ hasSquaredOffJoins: true ,
910
+ heightMode: . matchTextExact)
911
+ editor. addAttributes ( [
912
+ . backgroundStyle: backgroundStyle
913
+ ] , at: rangeToUpdate)
914
+
915
+ viewController. render ( size: CGSize ( width: 150 , height: 100 ) )
916
+ assertSnapshot ( matching: viewController. view, as: . image, record: recordMode)
917
+ }
918
+
786
919
func testBackgroundStyleWithVariedFontSizes( ) {
787
920
let viewController = EditorTestViewController ( )
788
921
let editor = viewController. editor
0 commit comments