Skip to content

Commit 7e3d1a0

Browse files
committed
Tests for contentEditable
1 parent b526c43 commit 7e3d1a0

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

src/Flame/HTML/Attribute/Event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
exports.nodeValue_ = function (event) {
2-
if (event.target.contentEditable)
2+
if (event.target.contentEditable === true || event.target.contentEditable === "true" || event.target.contentEditable === "")
33
return event.target.innerText;
44

55
return event.target.value;

test/Basic/ContentEditable.purs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module Test.Basic.ContentEditable (mount) where
2+
3+
import Prelude
4+
5+
import Effect (Effect)
6+
import Flame (QuerySelector(..), Html)
7+
import Flame.Application.NoEffects as FAN
8+
import Flame.HTML.Attribute as HA
9+
import Flame.HTML.Element as HE
10+
11+
type Model = String
12+
13+
data Message = SetModel String
14+
15+
init :: Model
16+
init = "start"
17+
18+
update :: Model -> Message -> Model
19+
update _ = case _ of
20+
SetModel newModel -> newModel
21+
22+
view :: Model -> Html Message
23+
view model = HE.main_ [
24+
HE.span "text-output" model,
25+
HE.select [HA.id "content-select", HA.createAttribute "contentEditable" "inherit", HA.onInput SetModel] [
26+
HE.option [HA.value "1"] "1",
27+
HE.option [HA.selected true, HA.value "2"] "2"
28+
],
29+
HE.div [HA.id "content-div", HA.contentEditable true, HA.onInput SetModel] [
30+
HE.text "content"
31+
]
32+
]
33+
34+
mount :: Effect Unit
35+
mount = FAN.mount_ (QuerySelector "#mount-point") {
36+
init,
37+
update,
38+
view
39+
}

test/Main.purs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Effect.Class (liftEffect)
1515
import Flame.Application.DOM as FAD
1616
import Flame.Application.Effectful as FAE
1717
import Flame.HTML.Attribute as HA
18+
import Test.Basic.ContentEditable as TBC
1819
import Flame.HTML.Element as HE
1920
import Flame.Renderer.String as FRS
2021
import Partial.Unsafe (unsafePartial)
@@ -309,6 +310,25 @@ main =
309310
TUA.equal false currentNewChecked
310311
TUA.equal false currentNewDisabled
311312

313+
test "contentEditable" do
314+
--contentEditable is not supported by jsdom
315+
liftEffect do
316+
unsafeCreateEnviroment
317+
TBC.mount
318+
childrenLength <- childrenNodeLength
319+
TUA.equal 3 childrenLength
320+
321+
initialOutput <- textContent "#text-output"
322+
TUA.equal "start" initialOutput
323+
324+
dispatchEvent inputEvent "#content-div"
325+
currentOutput <- textContent "#text-output"
326+
TUA.equal "" currentOutput
327+
328+
dispatchEvent inputEvent "#content-select"
329+
currentOutput2 <- textContent "#text-output"
330+
TUA.equal "2" currentOutput2
331+
312332
suite "Effectful specific" do
313333
test "slower effects" do
314334
liftEffect do

0 commit comments

Comments
 (0)