github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/tests/DashboardSearchTests.elm (about) 1 module DashboardSearchTests exposing (hasData, missingData) 2 3 import Application.Application as Application 4 import Common exposing (queryView) 5 import Concourse 6 import Concourse.BuildStatus exposing (BuildStatus(..)) 7 import DashboardTests exposing (whenOnDashboard) 8 import Data 9 import Expect exposing (Expectation) 10 import Message.Callback as Callback 11 import Message.Message 12 import Message.Subscription as Subscription 13 import Message.TopLevelMessage as Msgs 14 import Set 15 import Test exposing (Test) 16 import Test.Html.Query as Query 17 import Test.Html.Selector exposing (class, id, style, text) 18 19 20 describe : String -> model -> List (model -> Test) -> Test 21 describe description beforeEach subTests = 22 Test.describe description 23 (subTests |> List.map (\f -> f beforeEach)) 24 25 26 context : String -> (a -> b) -> List (b -> Test) -> (a -> Test) 27 context description setup subTests beforeEach = 28 Test.describe description 29 (subTests |> List.map (\f -> f <| setup beforeEach)) 30 31 32 it : String -> (model -> Expectation) -> model -> Test 33 it desc expectationFunc model = 34 Test.test desc <| 35 \_ -> expectationFunc model 36 37 38 hasData : Test 39 hasData = 40 describe "dashboard search" 41 (whenOnDashboard { highDensity = False } 42 |> Application.handleCallback 43 (Callback.AllJobsFetched <| 44 Ok 45 [ { name = "job" 46 , pipelineName = "pipeline1" 47 , teamName = "team1" 48 , nextBuild = 49 Just 50 { id = 1 51 , name = "1" 52 , job = 53 Just 54 (Data.jobId 55 |> Data.withTeamName "team1" 56 |> Data.withPipelineName "pipeline1" 57 ) 58 , status = BuildStatusStarted 59 , duration = 60 { startedAt = Nothing 61 , finishedAt = Nothing 62 } 63 , reapTime = Nothing 64 } 65 , finishedBuild = Nothing 66 , transitionBuild = Nothing 67 , paused = False 68 , disableManualTrigger = False 69 , inputs = [] 70 , outputs = [] 71 , groups = [] 72 } 73 ] 74 ) 75 |> Tuple.first 76 |> Application.handleCallback 77 (Callback.AllTeamsFetched <| 78 Ok 79 [ Concourse.Team 1 "team1" 80 , Concourse.Team 2 "team2" 81 ] 82 ) 83 |> Tuple.first 84 |> Application.handleCallback 85 (Callback.AllPipelinesFetched <| 86 Ok 87 [ Data.pipeline "team1" 0 |> Data.withName "pipeline1" 88 , Data.pipeline "team1" 1 |> Data.withName "pipeline2" 89 ] 90 ) 91 |> Tuple.first 92 ) 93 [ context "after focusing the search bar" 94 (Application.update 95 (Msgs.Update <| 96 Message.Message.FocusMsg 97 ) 98 >> Tuple.first 99 ) 100 [ it "dropdown appears with a 'status:' option" <| 101 queryView 102 >> Query.find [ id "search-dropdown" ] 103 >> Query.has [ text "status:" ] 104 , context "after clicking 'status:' in the dropdown" 105 (Application.update 106 (Msgs.Update <| 107 Message.Message.FilterMsg "status:" 108 ) 109 >> Tuple.first 110 ) 111 [ it "a 'status: paused' option appears" <| 112 queryView 113 >> Query.find [ id "search-dropdown" ] 114 >> Query.has [ text "status: paused" ] 115 , it "a 'status: running' option appears" <| 116 queryView 117 >> Query.find [ id "search-dropdown" ] 118 >> Query.has [ text "status: running" ] 119 , context "after clicking 'status: paused'" 120 (Application.update 121 (Msgs.Update <| 122 Message.Message.FilterMsg "status: paused" 123 ) 124 >> Tuple.first 125 ) 126 [ it "the dropdown is gone" <| 127 queryView 128 >> Query.find [ id "search-dropdown" ] 129 >> Query.children [] 130 >> Query.count (Expect.equal 0) 131 ] 132 , context "after clicking 'status: running'" 133 (Application.update 134 (Msgs.Update <| 135 Message.Message.FilterMsg "status: running" 136 ) 137 >> Tuple.first 138 ) 139 [ it "shows the running pipeline" <| 140 queryView 141 >> Query.find [ class "card" ] 142 >> Query.has [ text "pipeline1" ] 143 ] 144 ] 145 ] 146 , it "shows empty teams when only filtering on team name" <| 147 Application.update 148 (Msgs.Update <| 149 Message.Message.FilterMsg "team: team2" 150 ) 151 >> Tuple.first 152 >> queryView 153 >> Query.find [ class "dashboard-team-group" ] 154 >> Query.has [ text "team2" ] 155 , it "fuzzy matches team name" <| 156 Application.update 157 (Msgs.Update <| 158 Message.Message.FilterMsg "team: team" 159 ) 160 >> Tuple.first 161 >> queryView 162 >> Query.findAll [ class "dashboard-team-group" ] 163 >> Expect.all 164 [ Query.index 0 165 >> Query.has [ text "team1" ] 166 , Query.index 1 167 >> Query.has [ text "team2" ] 168 ] 169 , it "centers 'no results' message when typing a string with no hits" <| 170 Application.handleCallback 171 (Callback.AllTeamsFetched <| 172 Ok 173 [ { name = "team", id = 0 } ] 174 ) 175 >> Tuple.first 176 >> Application.handleCallback 177 (Callback.AllPipelinesFetched <| 178 Ok 179 [ Data.pipeline "team" 0 |> Data.withName "pipeline" ] 180 ) 181 >> Tuple.first 182 >> Application.update 183 (Msgs.Update <| 184 Message.Message.FilterMsg "asdf" 185 ) 186 >> Tuple.first 187 >> queryView 188 >> Query.find [ class "no-results" ] 189 >> Query.has 190 [ style "text-align" "center" 191 , style "font-size" "13px" 192 , style "margin-top" "20px" 193 ] 194 , context "when there are favorited pipelines" 195 (Application.handleDelivery 196 (Subscription.FavoritedPipelinesReceived <| 197 Ok <| 198 Set.fromList [ 0, 1 ] 199 ) 200 ) 201 [ it "applies the filter to the favorites section" <| 202 Tuple.first 203 >> Application.update 204 (Msgs.Update <| 205 Message.Message.FilterMsg "pipeline1" 206 ) 207 >> Tuple.first 208 >> queryView 209 >> Query.find [ id "dashboard-favorite-pipelines" ] 210 >> Query.hasNot [ text "pipeline2" ] 211 ] 212 ] 213 214 215 missingData : Test 216 missingData = 217 Test.describe "when not all data has come in" <| 218 [ Test.test "does not render 'no results' when awaiting pipelines" <| 219 \_ -> 220 whenOnDashboard { highDensity = False } 221 |> Application.handleCallback 222 (Callback.AllJobsFetched <| 223 Ok [] 224 ) 225 |> Tuple.first 226 |> Application.update 227 (Msgs.Update <| 228 Message.Message.FilterMsg "asdf" 229 ) 230 |> Tuple.first 231 |> queryView 232 |> Query.hasNot [ class "no-results" ] 233 ]