github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/tests/DashboardArchiveTests.elm (about) 1 module DashboardArchiveTests exposing (all) 2 3 import Application.Application as Application 4 import Assets 5 import Colors 6 import Common 7 import Data 8 import Html.Attributes as Attr 9 import Message.Callback as Callback 10 import Message.Message exposing (DomID(..)) 11 import Message.Subscription as Subscription 12 import Routes 13 import Set 14 import Test exposing (Test, describe, test) 15 import Test.Html.Query as Query 16 import Test.Html.Selector exposing (attribute, class, containing, id, style, tag, text) 17 import Url 18 19 20 all : Test 21 all = 22 describe "DashboardArchive" 23 [ describe "toggle switch" <| 24 let 25 toggleSwitch = 26 [ tag "a" 27 , containing [ text "show archived" ] 28 ] 29 30 setupQuery path query = 31 init path query 32 |> Application.handleCallback 33 (Callback.AllPipelinesFetched <| Ok [ Data.pipeline "team" 1 ]) 34 |> Tuple.first 35 |> Common.queryView 36 37 setup path = 38 setupQuery path Nothing 39 in 40 [ test "exists on the normal view" <| 41 \_ -> 42 setup "/" 43 |> Query.has toggleSwitch 44 , test "exists on the hd view" <| 45 \_ -> 46 setup "/hd" 47 |> Query.has toggleSwitch 48 , test "does not exist when there are no pipelines" <| 49 \_ -> 50 Common.init "/" 51 |> Common.queryView 52 |> Query.hasNot toggleSwitch 53 , test "renders label to the left of the button" <| 54 \_ -> 55 setup "/" 56 |> Query.find toggleSwitch 57 |> Query.has [ style "flex-direction" "row-reverse" ] 58 , test "has a margin between the button and the label" <| 59 \_ -> 60 setup "/" 61 |> Query.find toggleSwitch 62 |> Query.children [] 63 |> Query.index 0 64 |> Query.has [ style "margin-left" "10px" ] 65 , test "has a margin to the right of the toggle" <| 66 \_ -> 67 setup "/" 68 |> Query.find toggleSwitch 69 |> Query.has [ style "margin-right" "10px" ] 70 , test "has an offset left border" <| 71 \_ -> 72 setup "/" 73 |> Query.find toggleSwitch 74 |> Query.has 75 [ style "border-left" <| "1px solid " ++ Colors.showArchivedButtonBorder 76 , style "padding-left" "10px" 77 ] 78 , describe "when not enabled" <| 79 [ test "links to 'view all pipelines' route" <| 80 \_ -> 81 setup "/" 82 |> Query.find toggleSwitch 83 |> Query.has 84 [ routeHref <| 85 Routes.Dashboard 86 { searchType = Routes.Normal "" 87 , dashboardView = Routes.ViewAllPipelines 88 } 89 ] 90 , test "displays the off state" <| 91 \_ -> 92 setup "/" 93 |> Query.find toggleSwitch 94 |> Query.has 95 [ style "background-image" <| 96 Assets.backgroundImage <| 97 Just (Assets.ToggleSwitch False) 98 ] 99 ] 100 , describe "when enabled" <| 101 [ test "links to 'view non-archived pipelines' route" <| 102 \_ -> 103 setupQuery "/" (Just "view=all") 104 |> Query.find toggleSwitch 105 |> Query.has 106 [ routeHref <| 107 Routes.Dashboard 108 { searchType = Routes.Normal "" 109 , dashboardView = Routes.ViewNonArchivedPipelines 110 } 111 ] 112 , test "displays the on state" <| 113 \_ -> 114 setupQuery "/" (Just "view=all") 115 |> Query.find toggleSwitch 116 |> Query.has 117 [ style "background-image" <| 118 Assets.backgroundImage <| 119 Just (Assets.ToggleSwitch True) 120 ] 121 ] 122 , describe "when a search query is entered" <| 123 [ test "does not clear the query" <| 124 \_ -> 125 setupQuery "/" (Just "search=test") 126 |> Query.find toggleSwitch 127 |> Query.has 128 [ routeHref <| 129 Routes.Dashboard 130 { searchType = Routes.Normal "test" 131 , dashboardView = Routes.ViewAllPipelines 132 } 133 ] 134 ] 135 , describe "on the HD view" <| 136 [ test "stays in the HD view" <| 137 \_ -> 138 setup "/hd" 139 |> Query.find toggleSwitch 140 |> Query.has 141 [ routeHref <| 142 Routes.Dashboard 143 { searchType = Routes.HighDensity 144 , dashboardView = Routes.ViewAllPipelines 145 } 146 ] 147 ] 148 ] 149 , describe "when viewing only non-archived pipelines" 150 [ test "archived pipelines are not rendered in all pipelines section" <| 151 \_ -> 152 init "/" Nothing 153 |> Application.handleCallback 154 (Callback.AllPipelinesFetched <| 155 Ok 156 [ Data.pipeline "team" 1 157 |> Data.withName "archived-pipeline" 158 |> Data.withArchived True 159 ] 160 ) 161 |> Tuple.first 162 |> Common.queryView 163 |> Query.hasNot [ class "pipeline-wrapper", containing [ text "archived-pipeline" ] ] 164 , describe "when an archived pipeline is favorited" <| 165 let 166 setup = 167 init "/" Nothing 168 |> Application.handleCallback 169 (Callback.AllPipelinesFetched <| 170 Ok 171 [ Data.pipeline "team" 1 172 |> Data.withName "archived-pipeline" 173 |> Data.withArchived True 174 ] 175 ) 176 |> Tuple.first 177 |> Application.handleDelivery 178 (Subscription.FavoritedPipelinesReceived <| 179 Ok <| 180 Set.singleton 1 181 ) 182 |> Tuple.first 183 in 184 [ test "still rendered in favorites section" <| 185 \_ -> 186 setup 187 |> Common.queryView 188 |> Query.find [ id "dashboard-favorite-pipelines" ] 189 |> Query.has [ class "pipeline-wrapper", containing [ text "archived-pipeline" ] ] 190 , test "still rendered in all pipelines section" <| 191 \_ -> 192 setup 193 |> Common.queryView 194 |> Query.find [ class "dashboard-team-group" ] 195 |> Query.has [ class "pipeline-wrapper", containing [ text "archived-pipeline" ] ] 196 ] 197 , describe "when a team has only archived pipelines" 198 [ test "it shows the no pipeline set card" <| 199 \_ -> 200 init "/" Nothing 201 |> Application.handleCallback 202 (Callback.AllPipelinesFetched <| 203 Ok 204 [ Data.pipeline "team" 1 205 |> Data.withName "archived-pipeline" 206 |> Data.withArchived True 207 ] 208 ) 209 |> Tuple.first 210 |> Common.queryView 211 |> Query.has [ text "no pipeline set" ] 212 ] 213 ] 214 , describe "when viewing all pipelines" 215 [ test "archived pipelines are rendered" <| 216 \_ -> 217 init "/" (Just "view=all") 218 |> Application.handleCallback 219 (Callback.AllPipelinesFetched <| 220 Ok 221 [ Data.pipeline "team" 1 222 |> Data.withName "archived-pipeline" 223 |> Data.withArchived True 224 ] 225 ) 226 |> Tuple.first 227 |> Common.queryView 228 |> Query.has [ class "pipeline-wrapper", containing [ text "archived-pipeline" ] ] 229 ] 230 ] 231 232 233 init : String -> Maybe String -> Application.Model 234 init path query = 235 Application.init 236 { turbulenceImgSrc = "" 237 , notFoundImgSrc = "notfound.svg" 238 , csrfToken = "csrf_token" 239 , authToken = "" 240 , pipelineRunningKeyframes = "pipeline-running" 241 } 242 { protocol = Url.Http 243 , host = "" 244 , port_ = Nothing 245 , path = path 246 , query = query 247 , fragment = Nothing 248 } 249 |> Tuple.first 250 |> Application.handleCallback 251 (Callback.GotViewport Dashboard <| 252 Ok <| 253 { scene = 254 { width = 600 255 , height = 600 256 } 257 , viewport = 258 { width = 600 259 , height = 600 260 , x = 0 261 , y = 0 262 } 263 } 264 ) 265 |> Tuple.first 266 267 268 routeHref : Routes.Route -> Test.Html.Selector.Selector 269 routeHref = 270 Routes.toString >> Attr.href >> attribute