github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/tests/Common.elm (about) 1 module Common exposing 2 ( and 3 , contains 4 , defineHoverBehaviour 5 , given 6 , iOpenTheBuildPage 7 , init 8 , isColorWithStripes 9 , myBrowserFetchedTheBuild 10 , notContains 11 , pipelineRunningKeyframes 12 , queryView 13 , then_ 14 , when 15 ) 16 17 import Application.Application as Application 18 import Concourse 19 import Concourse.BuildStatus exposing (BuildStatus(..)) 20 import Data 21 import Expect exposing (Expectation) 22 import Html 23 import List.Extra 24 import Message.Callback as Callback 25 import Message.Effects exposing (Effect) 26 import Message.Message exposing (DomID, Message(..)) 27 import Message.TopLevelMessage exposing (TopLevelMessage(..)) 28 import Test exposing (Test, describe, test) 29 import Test.Html.Event as Event 30 import Test.Html.Query as Query 31 import Test.Html.Selector exposing (Selector, style) 32 import Url 33 34 35 queryView : Application.Model -> Query.Single TopLevelMessage 36 queryView = 37 Application.view 38 >> .body 39 >> Html.div [] 40 >> Query.fromHtml 41 42 43 contains : a -> List a -> Expect.Expectation 44 contains x xs = 45 if List.member x xs then 46 Expect.pass 47 48 else 49 Expect.fail <| 50 "Expected \n[ " 51 ++ String.join "\n, " (List.map Debug.toString xs) 52 ++ "\n] to contain " 53 ++ Debug.toString x 54 55 56 notContains : a -> List a -> Expect.Expectation 57 notContains x xs = 58 if List.member x xs then 59 Expect.fail <| 60 "Expected " 61 ++ Debug.toString xs 62 ++ " not to contain " 63 ++ Debug.toString x 64 65 else 66 Expect.pass 67 68 69 isColorWithStripes : 70 { thick : String, thin : String } 71 -> Query.Single msg 72 -> Expectation 73 isColorWithStripes { thick, thin } = 74 Query.has 75 [ style "background-image" <| 76 "repeating-linear-gradient(-115deg," 77 ++ thin 78 ++ " 0px," 79 ++ thick 80 ++ " 1px," 81 ++ thick 82 ++ " 10px," 83 ++ thin 84 ++ " 11px," 85 ++ thin 86 ++ " 16px)" 87 , style "background-size" "106px 114px" 88 , style "animation" <| 89 pipelineRunningKeyframes 90 ++ " 3s linear infinite" 91 ] 92 93 94 pipelineRunningKeyframes : String 95 pipelineRunningKeyframes = 96 "pipeline-running" 97 98 99 init : String -> Application.Model 100 init path = 101 Application.init 102 { turbulenceImgSrc = "" 103 , notFoundImgSrc = "notfound.svg" 104 , csrfToken = "csrf_token" 105 , authToken = "" 106 , pipelineRunningKeyframes = "pipeline-running" 107 } 108 { protocol = Url.Http 109 , host = "" 110 , port_ = Nothing 111 , path = path 112 , query = Nothing 113 , fragment = Nothing 114 } 115 |> Tuple.first 116 117 118 given = 119 identity 120 121 122 and = 123 identity 124 125 126 when = 127 identity 128 129 130 then_ = 131 identity 132 133 134 iOpenTheBuildPage _ = 135 Application.init 136 { turbulenceImgSrc = "" 137 , notFoundImgSrc = "" 138 , csrfToken = "" 139 , authToken = "" 140 , pipelineRunningKeyframes = "" 141 } 142 { protocol = Url.Http 143 , host = "" 144 , port_ = Nothing 145 , path = "/builds/1" 146 , query = Nothing 147 , fragment = Nothing 148 } 149 150 151 myBrowserFetchedTheBuild = 152 Tuple.first 153 >> Application.handleCallback 154 (Callback.BuildFetched <| 155 Ok 156 { id = 1 157 , name = "1" 158 , job = 159 Just 160 (Data.jobId 161 |> Data.withTeamName "other-team" 162 |> Data.withPipelineName "yet-another-pipeline" 163 |> Data.withJobName "job" 164 ) 165 , status = BuildStatusStarted 166 , duration = 167 { startedAt = Nothing 168 , finishedAt = Nothing 169 } 170 , reapTime = Nothing 171 } 172 ) 173 174 175 defineHoverBehaviour : 176 { name : String 177 , setup : Application.Model 178 , query : Application.Model -> Query.Single TopLevelMessage 179 , unhoveredSelector : { description : String, selector : List Selector } 180 , hoverable : DomID 181 , hoveredSelector : { description : String, selector : List Selector } 182 } 183 -> Test 184 defineHoverBehaviour { name, setup, query, unhoveredSelector, hoverable, hoveredSelector } = 185 describe (name ++ " hover behaviour") 186 [ test (name ++ " is " ++ unhoveredSelector.description) <| 187 \_ -> 188 setup 189 |> query 190 |> Query.has unhoveredSelector.selector 191 , test ("mousing over " ++ name ++ " triggers Hover msg") <| 192 \_ -> 193 setup 194 |> query 195 |> Event.simulate Event.mouseEnter 196 |> Event.expect (Update <| Hover <| Just hoverable) 197 , test 198 ("Hover msg causes " 199 ++ name 200 ++ " to become " 201 ++ hoveredSelector.description 202 ) 203 <| 204 \_ -> 205 setup 206 |> Application.update (Update <| Hover <| Just hoverable) 207 |> Tuple.first 208 |> query 209 |> Query.has hoveredSelector.selector 210 , test ("mousing off " ++ name ++ " triggers unhover msg") <| 211 \_ -> 212 setup 213 |> Application.update (Update <| Hover <| Just hoverable) 214 |> Tuple.first 215 |> query 216 |> Event.simulate Event.mouseLeave 217 |> Event.expect (Update <| Hover Nothing) 218 , test 219 ("unhover msg causes " 220 ++ name 221 ++ " to become " 222 ++ unhoveredSelector.description 223 ) 224 <| 225 \_ -> 226 setup 227 |> Application.update (Update <| Hover <| Just hoverable) 228 |> Tuple.first 229 |> Application.update (Update <| Hover Nothing) 230 |> Tuple.first 231 |> query 232 |> Query.has unhoveredSelector.selector 233 ] 234 235 236 237 -- 6 places where Application.init is used with a query 238 -- 6 places where Application.init is used with a fragment 239 -- 1 place where Application.init is used with an instance name