Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 92c7b6a

Browse files
committed
Tidy up various things in the tests
1 parent 23461ba commit 92c7b6a

File tree

4 files changed

+93
-127
lines changed

4 files changed

+93
-127
lines changed

test/DOM/HTML/Document.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ domHtmlDocumentTests = do
1515
describe "readyState" do
1616
it "should return a sensible readyState" do
1717
rs <- liftEff $ readyState =<< document =<< window
18-
rs `shouldEqual` Interactive
18+
rs `shouldEqual` Complete

test/DOM/HTML/Window.purs

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,39 @@
11
module Test.DOM.HTML.Window where
22

3-
import Prelude (Unit, bind, (<<<), discard)
3+
import Prelude
4+
5+
import Control.Monad.Eff.Class (liftEff)
46
import DOM (DOM)
57
import DOM.HTML (window)
68
import DOM.HTML.Types (WINDOW)
7-
import DOM.HTML.Window
8-
import Control.Monad.Free (Free)
9-
import Control.Monad.Aff (Aff)
10-
import Control.Monad.Aff.Console (CONSOLE)
11-
import Control.Monad.Eff (Eff)
12-
import Control.Monad.Eff.Class (liftEff) as EffClass
13-
import Test.Unit (TestF, describe, it)
14-
import Test.Unit.Assert (shouldEqual)
9+
import DOM.HTML.Window as Window
1510
import Data.Maybe (isJust)
16-
import Data.Traversable (class Traversable, sequence)
17-
18-
19-
liftEff :: forall eff a. Eff eff a -> Aff eff a
20-
liftEff = EffClass.liftEff
21-
22-
liftSeq :: forall eff m a. Traversable m => m (Eff eff a) -> Aff eff (m a)
23-
liftSeq = liftEff <<< sequence
11+
import Test.Unit (TestSuite, describe, it)
12+
import Test.Unit.Assert (shouldEqual)
2413

25-
domHtmlWindowTests
26-
:: forall eff. Free (TestF (dom :: DOM, console :: CONSOLE, window :: WINDOW | eff)) Unit
14+
domHtmlWindowTests :: forall eff. TestSuite (dom :: DOM, window :: WINDOW | eff)
2715
domHtmlWindowTests = do
2816
describe "innerHeight" do
2917
it "should return the default inner height" do
30-
windowHeight <- liftEff do
31-
window' <- window
32-
innerHeight window'
18+
windowHeight <- liftEff $ Window.innerHeight =<< window
3319
windowHeight `shouldEqual` 300
3420

3521
describe "innerWidth" do
3622
it "should return the default inner width" do
37-
windowWidth <- liftEff do
38-
window' <- window
39-
innerWidth window'
23+
windowWidth <- liftEff $ Window.innerWidth =<< window
4024
windowWidth `shouldEqual` 400
4125

4226
describe "screenX" do
4327
it "should get the X coordinate of the window" do
44-
x <- liftEff do
45-
window' <- window
46-
screenX window'
28+
x <- liftEff $ Window.screenX =<< window
4729
x `shouldEqual` 0
4830

4931
describe "screenY" do
5032
it "should get the Y coordinate of the window" do
51-
y <- liftEff do
52-
window' <- window
53-
screenY window'
33+
y <- liftEff $ Window.screenY =<< window
5434
y `shouldEqual` 0
5535

5636
describe "open" do
5737
it "should open a new window" do
58-
newWindow' <- liftEff do
59-
window' <- window
60-
open "about:blank" "foobar" "" window'
38+
newWindow' <- liftEff $ Window.open "about:blank" "foobar" "" =<< window
6139
isJust newWindow' `shouldEqual` true

test/DOM/Node/DomTokenList.purs

Lines changed: 71 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,154 +2,139 @@ module Test.DOM.Node.DOMTokenList where
22

33
import Prelude
44

5-
import Control.Monad.Aff.Console (CONSOLE)
65
import Control.Monad.Eff.Class (liftEff)
7-
import Control.Monad.Free (Free)
86
import DOM (DOM)
97
import DOM.HTML (window)
108
import DOM.HTML.Document (body)
119
import DOM.HTML.HTMLElement (classList, className, setClassName)
12-
import DOM.HTML.Types (WINDOW)
1310
import DOM.HTML.Window (document)
14-
import DOM.Node.ClassList (add, contains, remove, toggle, toggleForce, item) as CL
11+
import DOM.Node.ClassList as CL
1512
import Data.Maybe (Maybe(..), fromMaybe)
16-
import Test.Unit (TestF, describe, it)
13+
import Test.Unit (TestSuite, describe, it)
1714
import Test.Unit.Assert (shouldEqual)
1815

19-
domTokenListTests :: forall eff. Free (TestF (dom :: DOM, console :: CONSOLE,
20-
window :: WINDOW | eff)) Unit
16+
domTokenListTests :: forall eff. TestSuite (dom :: DOM | eff)
2117
domTokenListTests = do
2218
describe "DOMTokenList of classList" do
2319
it "contains a token" do
2420
body' <- liftEff $ window >>= document >>= body
2521
result <- case body' of
26-
Just body'' -> liftEff do
27-
_ <- setClassName "a b c" body''
28-
list <- classList body''
29-
CL.contains list "a"
30-
Nothing -> pure false
31-
22+
Just body'' -> liftEff do
23+
_ <- setClassName "a b c" body''
24+
list <- classList body''
25+
CL.contains list "a"
26+
Nothing -> pure false
3227
result `shouldEqual` true
3328

3429
it "adds a token" do
3530
body' <- liftEff $ window >>= document >>= body
3631
result <- case body' of
37-
Just body'' -> liftEff do
38-
-- clear class names, first
39-
_ <- setClassName "" body''
40-
list <- classList body''
41-
_ <- CL.add list "a"
42-
className body''
43-
Nothing -> pure "failed"
44-
32+
Just body'' -> liftEff do
33+
-- clear class names, first
34+
_ <- setClassName "" body''
35+
list <- classList body''
36+
_ <- CL.add list "a"
37+
className body''
38+
Nothing -> pure "failed"
4539
result `shouldEqual` "a"
4640

4741
it "removes a token" do
4842
body' <- liftEff $ window >>= document >>= body
4943
result <- case body' of
50-
Just body'' -> liftEff do
51-
_ <- setClassName "a b c" body''
52-
list <- classList body''
53-
_ <- CL.remove list "b"
54-
resultA <- CL.contains list "a"
55-
resultB <- CL.contains list "b"
56-
resultC <- CL.contains list "c"
57-
-- Only "b" should be removed
58-
pure $ resultA && not resultB && resultC
59-
Nothing -> pure false
60-
44+
Just body'' -> liftEff do
45+
_ <- setClassName "a b c" body''
46+
list <- classList body''
47+
_ <- CL.remove list "b"
48+
resultA <- CL.contains list "a"
49+
resultB <- CL.contains list "b"
50+
resultC <- CL.contains list "c"
51+
-- Only "b" should be removed
52+
pure $ resultA && not resultB && resultC
53+
Nothing -> pure false
6154
result `shouldEqual` true
6255

6356
it "toggles a token by removing its value" do
6457
body' <- liftEff $ window >>= document >>= body
6558
result <- case body' of
66-
Just body'' -> liftEff do
67-
_ <- setClassName "a b c" body''
68-
list <- classList body''
69-
_ <- CL.toggle list "c"
70-
className body''
71-
Nothing -> pure "failed"
72-
59+
Just body'' -> liftEff do
60+
_ <- setClassName "a b c" body''
61+
list <- classList body''
62+
_ <- CL.toggle list "c"
63+
className body''
64+
Nothing -> pure "failed"
7365
result `shouldEqual` "a b"
7466

7567
it "toggles a token by adding its value" do
7668
body' <- liftEff $ window >>= document >>= body
7769
result <- case body' of
78-
Just body'' -> liftEff do
79-
_ <- setClassName "a b" body''
80-
list <- classList body''
81-
_ <- CL.toggle list "c"
82-
className body''
83-
Nothing -> pure "failed"
84-
70+
Just body'' -> liftEff do
71+
_ <- setClassName "a b" body''
72+
list <- classList body''
73+
_ <- CL.toggle list "c"
74+
className body''
75+
Nothing -> pure "failed"
8576
result `shouldEqual` "a b c"
8677

8778
it "toggles a token by forcing to add its value" do
8879
body' <- liftEff $ window >>= document >>= body
8980
result <- case body' of
90-
Just body'' -> liftEff do
91-
_ <- setClassName "a b" body''
92-
list <- classList body''
93-
_ <- CL.toggleForce list "c" true
94-
className body''
95-
Nothing -> pure "failed"
96-
81+
Just body'' -> liftEff do
82+
_ <- setClassName "a b" body''
83+
list <- classList body''
84+
_ <- CL.toggleForce list "c" true
85+
className body''
86+
Nothing -> pure "failed"
9787
result `shouldEqual` "a b c"
9888

9989
it "toggles a token by forcing to add (but not to remove) its value" do
10090
body' <- liftEff $ window >>= document >>= body
10191
result <- case body' of
102-
Just body'' -> liftEff do
103-
_ <- setClassName "a b c" body''
104-
list <- classList body''
105-
_ <- CL.toggleForce list "c" true
106-
className body''
107-
Nothing -> pure "failed"
108-
92+
Just body'' -> liftEff do
93+
_ <- setClassName "a b c" body''
94+
list <- classList body''
95+
_ <- CL.toggleForce list "c" true
96+
className body''
97+
Nothing -> pure "failed"
10998
result `shouldEqual` "a b c"
11099

111100
it "toggles a token by forcing to remove its value" do
112101
body' <- liftEff $ window >>= document >>= body
113102
result <- case body' of
114-
Just body'' -> liftEff do
115-
_ <- setClassName "a b c" body''
116-
list <- classList body''
117-
_ <- CL.toggleForce list "c" false
118-
className body''
119-
Nothing -> pure "failed"
120-
103+
Just body'' -> liftEff do
104+
_ <- setClassName "a b c" body''
105+
list <- classList body''
106+
_ <- CL.toggleForce list "c" false
107+
className body''
108+
Nothing -> pure "failed"
121109
result `shouldEqual` "a b"
122110

123111
it "toggles a token by forcing to remove (but not to add) its value" do
124112
body' <- liftEff $ window >>= document >>= body
125113
result <- case body' of
126-
Just body'' -> liftEff do
127-
_ <- setClassName "a b" body''
128-
list <- classList body''
129-
_ <- CL.toggleForce list "c" false
130-
className body''
131-
Nothing -> pure "failed"
132-
114+
Just body'' -> liftEff do
115+
_ <- setClassName "a b" body''
116+
list <- classList body''
117+
_ <- CL.toggleForce list "c" false
118+
className body''
119+
Nothing -> pure "failed"
133120
result `shouldEqual` "a b"
134121

135122
it "returns an item if available" do
136123
body' <- liftEff $ window >>= document >>= body
137124
result <- case body' of
138-
Just body'' -> liftEff do
139-
_ <- setClassName "a b c" body''
140-
list <- classList body''
141-
CL.item list 2
142-
Nothing -> pure Nothing
143-
125+
Just body'' -> liftEff do
126+
_ <- setClassName "a b c" body''
127+
list <- classList body''
128+
CL.item list 2
129+
Nothing -> pure Nothing
144130
(fromMaybe "not found" result) `shouldEqual` "c"
145131

146132
it "returns not an item if it's not available" do
147133
body' <- liftEff $ window >>= document >>= body
148134
result <- case body' of
149-
Just body'' -> liftEff do
150-
_ <- setClassName "a b c" body''
151-
list <- classList body''
152-
CL.item list 5
153-
Nothing -> pure Nothing
154-
135+
Just body'' -> liftEff do
136+
_ <- setClassName "a b c" body''
137+
list <- classList body''
138+
CL.item list 5
139+
Nothing -> pure Nothing
155140
(fromMaybe "not found" result) `shouldEqual` "not found"

test/Main.purs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ import Prelude
55
import Control.Monad.Aff.AVar (AVAR)
66
import Control.Monad.Aff.Console (CONSOLE)
77
import Control.Monad.Eff (Eff)
8+
import Control.Monad.Eff.Timer (TIMER, setTimeout)
89
import DOM (DOM)
910
import DOM.HTML.Types (WINDOW)
1011
import Test.DOM.HTML.Document (domHtmlDocumentTests)
1112
import Test.DOM.HTML.Window (domHtmlWindowTests)
1213
import Test.DOM.Node.DOMTokenList (domTokenListTests)
1314
import Test.Unit.Console (TESTOUTPUT)
14-
import Test.Unit.Main (runTest)
15+
import Test.Unit.Main (runTest, exit)
1516

16-
main :: forall eff. Eff (console :: CONSOLE, testOutput :: TESTOUTPUT, avar :: AVAR, dom :: DOM, window :: WINDOW | eff) Unit
17-
main = runTest do
18-
domHtmlDocumentTests
19-
domHtmlWindowTests
20-
domTokenListTests
17+
main :: Eff (console :: CONSOLE, testOutput :: TESTOUTPUT, avar :: AVAR, dom :: DOM, window :: WINDOW, timer :: TIMER) Unit
18+
main = do
19+
runTest do
20+
domHtmlDocumentTests
21+
domHtmlWindowTests
22+
domTokenListTests
23+
void $ setTimeout 100 $ exit 0

0 commit comments

Comments
 (0)