@@ -2,154 +2,139 @@ module Test.DOM.Node.DOMTokenList where
2
2
3
3
import Prelude
4
4
5
- import Control.Monad.Aff.Console (CONSOLE )
6
5
import Control.Monad.Eff.Class (liftEff )
7
- import Control.Monad.Free (Free )
8
6
import DOM (DOM )
9
7
import DOM.HTML (window )
10
8
import DOM.HTML.Document (body )
11
9
import DOM.HTML.HTMLElement (classList , className , setClassName )
12
- import DOM.HTML.Types (WINDOW )
13
10
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
15
12
import Data.Maybe (Maybe (..), fromMaybe )
16
- import Test.Unit (TestF , describe , it )
13
+ import Test.Unit (TestSuite , describe , it )
17
14
import Test.Unit.Assert (shouldEqual )
18
15
19
- domTokenListTests :: forall eff . Free (TestF (dom :: DOM , console :: CONSOLE ,
20
- window :: WINDOW | eff )) Unit
16
+ domTokenListTests :: forall eff . TestSuite (dom :: DOM | eff )
21
17
domTokenListTests = do
22
18
describe " DOMTokenList of classList" do
23
19
it " contains a token" do
24
20
body' <- liftEff $ window >>= document >>= body
25
21
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
32
27
result `shouldEqual` true
33
28
34
29
it " adds a token" do
35
30
body' <- liftEff $ window >>= document >>= body
36
31
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"
45
39
result `shouldEqual` " a"
46
40
47
41
it " removes a token" do
48
42
body' <- liftEff $ window >>= document >>= body
49
43
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
61
54
result `shouldEqual` true
62
55
63
56
it " toggles a token by removing its value" do
64
57
body' <- liftEff $ window >>= document >>= body
65
58
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"
73
65
result `shouldEqual` " a b"
74
66
75
67
it " toggles a token by adding its value" do
76
68
body' <- liftEff $ window >>= document >>= body
77
69
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"
85
76
result `shouldEqual` " a b c"
86
77
87
78
it " toggles a token by forcing to add its value" do
88
79
body' <- liftEff $ window >>= document >>= body
89
80
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"
97
87
result `shouldEqual` " a b c"
98
88
99
89
it " toggles a token by forcing to add (but not to remove) its value" do
100
90
body' <- liftEff $ window >>= document >>= body
101
91
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"
109
98
result `shouldEqual` " a b c"
110
99
111
100
it " toggles a token by forcing to remove its value" do
112
101
body' <- liftEff $ window >>= document >>= body
113
102
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"
121
109
result `shouldEqual` " a b"
122
110
123
111
it " toggles a token by forcing to remove (but not to add) its value" do
124
112
body' <- liftEff $ window >>= document >>= body
125
113
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"
133
120
result `shouldEqual` " a b"
134
121
135
122
it " returns an item if available" do
136
123
body' <- liftEff $ window >>= document >>= body
137
124
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
144
130
(fromMaybe " not found" result) `shouldEqual` " c"
145
131
146
132
it " returns not an item if it's not available" do
147
133
body' <- liftEff $ window >>= document >>= body
148
134
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
155
140
(fromMaybe " not found" result) `shouldEqual` " not found"
0 commit comments