Dupe tests for HIghlighable.V2

This commit is contained in:
Tessa Kelly 2023-03-09 15:29:01 -07:00
parent 33fa68a843
commit afe3cfb8e0

View File

@ -3,7 +3,8 @@ module Spec.Nri.Ui.Highlightable exposing (spec)
import Expect
import Fuzz exposing (..)
import Nri.Ui.Colors.V1 as Colors
import Nri.Ui.Highlightable.V1 as Highlightable
import Nri.Ui.Highlightable.V1 as HighlightableV1
import Nri.Ui.Highlightable.V2 as Highlightable
import Nri.Ui.Highlighter.V2 as Highlighter
import Nri.Ui.HighlighterTool.V1 as Tool
import String.Extra
@ -20,7 +21,7 @@ spec =
fragment =
strings
|> List.map (Tuple.pair [])
|> Highlightable.initFragment Nothing 0
|> HighlightableV1.initFragment Nothing 0
roundtripText =
Highlighter.asFragmentTuples fragment
@ -48,13 +49,78 @@ spec =
)
|> max 0
in
Highlightable.splitWords a
HighlightableV1.splitWords a
|> List.length
|> Expect.equal expected
, describe "HighlightableV1.fromMarkdown" fromMarkdownV1Spec
, describe "fromMarkdown" fromMarkdownSpec
]
fromMarkdownV1Spec : List Test
fromMarkdownV1Spec =
let
testFromMarkdown startingString expected =
HighlightableV1.fromMarkdown startingString
|> List.map (\{ text, marked } -> ( text, marked ))
|> Expect.equal expected
defaultMark =
Tool.buildMarker
{ highlightColor = Colors.highlightYellow
, hoverColor = Colors.highlightYellow
, hoverHighlightColor = Colors.highlightYellow
, kind = ()
, name = Nothing
}
in
[ test "with an empty string, produces empty list of Highlightables" <|
\() ->
testFromMarkdown "" []
, test "does not mark non-highlighted content" <|
\() ->
testFromMarkdown "A sentence without highlighted content"
[ ( "A sentence without highlighted content", Nothing ) ]
, test "does not strip emphasized content" <|
\() ->
testFromMarkdown "A *sentence without* **highlighted content**"
[ ( "A *sentence without* **highlighted content**", Nothing ) ]
, test "marks a single segment as highlighted" <|
\() ->
testFromMarkdown "[fake link]()"
[ ( "fake link", Just defaultMark ) ]
, test "does mark content that's intended to be highlighted" <|
\() ->
testFromMarkdown "A sentence with [highlighted content]()"
[ ( "A sentence with ", Nothing )
, ( "highlighted content", Just defaultMark )
]
, test "marks content that's intended to be highlighted within an emphasis" <|
\() ->
testFromMarkdown "A sentence with *emphasized [highlighted content]()!*"
[ ( "A sentence with *emphasized *", Nothing )
, ( "*highlighted content*", Just defaultMark )
, ( "*!*", Nothing )
]
, test "marks content that's intended to be highlighted that also contains an emphasis" <|
\() ->
testFromMarkdown "A sentence with [highlighted *and partially emphasized* content]()"
[ ( "A sentence with ", Nothing )
, ( "highlighted *and partially emphasized* content", Just defaultMark )
]
, test "does not highlight actual links" <|
\() ->
testFromMarkdown "I am a [real link](google.com)"
[ ( "I am a [real link](google.com)", Nothing )
]
, test "does not get confused by parentheses" <|
\() ->
testFromMarkdown "main thought (parenthetical)"
[ ( "main thought (parenthetical)", Nothing )
]
]
fromMarkdownSpec : List Test
fromMarkdownSpec =
let