-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathWidgetSpec.purs
47 lines (43 loc) · 1.56 KB
/
WidgetSpec.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Test.WidgetSpec where
import Prelude
import Concur.Core.Discharge (dischargeAll)
import Concur.Core.Types (affAction)
import Control.MultiAlternative (orr)
import Data.Time.Duration (Milliseconds(..))
import Effect.Aff (delay, never)
import Effect.Class (liftEffect)
import Effect.Ref as Ref
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual, shouldReturn)
widgetSpec :: Spec Unit
widgetSpec =
describe "Widget" do
describe "orr" do
it "should cancel running effects when the widget returns a value" do
ref <- liftEffect $ Ref.new ""
{ views } <- dischargeAll $ orr
[ affAction "a" do
delay (Milliseconds 100.0)
liftEffect $ Ref.write "a" ref
, affAction "b" do
delay (Milliseconds 150.0)
liftEffect $ Ref.write "b" ref
]
views `shouldEqual` [ "ab" ]
liftEffect (Ref.read ref) `shouldReturn` "a"
delay (Milliseconds 100.0)
liftEffect (Ref.read ref) `shouldReturn` "a"
it "should start all the widgets only once" do
ref <- liftEffect (Ref.new 0)
{ result, views } <- dischargeAll $ orr
[ do
affAction "a0" $ delay (Milliseconds 100.0)
affAction "a1" $ delay (Milliseconds 100.0)
pure "a"
, affAction "b" do
liftEffect $ Ref.modify_ (_ + 1) ref
never
]
result `shouldEqual` "a"
views `shouldEqual` [ "a0b", "a1b" ]
liftEffect (Ref.read ref) `shouldReturn` 1