github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/tests/SideBar/PipelineTests.elm (about) 1 module SideBar.PipelineTests exposing (all) 2 3 import Assets 4 import Colors 5 import Common 6 import Concourse 7 import Data 8 import Expect 9 import HoverState exposing (TooltipPosition(..)) 10 import Html exposing (Html) 11 import Message.Message exposing (DomID(..), Message, PipelinesSection(..)) 12 import Set 13 import SideBar.Pipeline as Pipeline 14 import SideBar.Styles as Styles 15 import SideBar.Views as Views 16 import Test exposing (Test, describe, test) 17 import Test.Html.Query as Query 18 import Test.Html.Selector exposing (style) 19 20 21 defaultState = 22 { active = False 23 , hovered = False 24 , favorited = False 25 , isFavoritesSection = False 26 } 27 28 29 all : Test 30 all = 31 describe "sidebar pipeline" 32 [ describe "when active" 33 [ describe "when hovered" 34 [ test "pipeline background is dark with bright border" <| 35 \_ -> 36 pipeline 37 |> viewPipeline { defaultState | active = True, hovered = True } 38 |> .background 39 |> Expect.equal Styles.Dark 40 , test "pipeline icon is white" <| 41 \_ -> 42 pipeline 43 |> viewPipeline { defaultState | active = True, hovered = True } 44 |> .icon 45 |> Expect.equal Assets.PipelineIconWhite 46 , describe "when not favorited" 47 [ test "displays a bright unfilled star icon when hovered" <| 48 \_ -> 49 pipeline 50 |> viewPipeline { defaultState | active = True, hovered = True } 51 |> .starIcon 52 |> Expect.equal { filled = False, isBright = True } 53 ] 54 , describe "when favorited" 55 [ test "displays a bright filled star icon" <| 56 \_ -> 57 pipeline 58 |> viewPipeline 59 { defaultState 60 | active = True 61 , hovered = True 62 , favorited = True 63 } 64 |> .starIcon 65 |> Expect.equal { filled = True, isBright = True } 66 ] 67 ] 68 , describe "when unhovered" 69 [ test "pipeline background is dark" <| 70 \_ -> 71 pipeline 72 |> viewPipeline { defaultState | active = True, hovered = False } 73 |> .background 74 |> Expect.equal Styles.Dark 75 , test "pipeline icon is bright" <| 76 \_ -> 77 pipeline 78 |> viewPipeline { defaultState | active = True, hovered = False } 79 |> .icon 80 |> Expect.equal Assets.PipelineIconLightGrey 81 , describe "when unfavorited" 82 [ test "displays a dim unfilled star icon" <| 83 \_ -> 84 pipeline 85 |> viewPipeline { defaultState | active = True, hovered = False } 86 |> .starIcon 87 |> Expect.equal { filled = False, isBright = True } 88 ] 89 , describe "when favorited" 90 [ test "displays a bright filled star icon" <| 91 \_ -> 92 pipeline 93 |> viewPipeline 94 { defaultState 95 | active = True 96 , hovered = True 97 , favorited = True 98 } 99 |> .starIcon 100 |> Expect.equal { filled = True, isBright = True } 101 ] 102 ] 103 , test "font weight is bold" <| 104 \_ -> 105 pipeline 106 |> viewPipeline { defaultState | active = True } 107 |> .name 108 |> .weight 109 |> Expect.equal Styles.Bold 110 ] 111 , describe "when inactive" 112 [ describe "when hovered" 113 [ test "pipeline background is light" <| 114 \_ -> 115 pipeline 116 |> viewPipeline { defaultState | active = False, hovered = True } 117 |> .background 118 |> Expect.equal Styles.Light 119 , test "pipeline icon is white" <| 120 \_ -> 121 pipeline 122 |> viewPipeline { defaultState | active = False, hovered = True } 123 |> .icon 124 |> Expect.equal Assets.PipelineIconWhite 125 ] 126 , describe "when unhovered" 127 [ test "pipeline name is grey" <| 128 \_ -> 129 pipeline 130 |> viewPipeline { defaultState | active = False, hovered = False } 131 |> .name 132 |> .pipelineColor 133 |> Expect.equal Styles.Grey 134 , test "pipeline has no background" <| 135 \_ -> 136 pipeline 137 |> viewPipeline { defaultState | active = False, hovered = False } 138 |> .background 139 |> Expect.equal Styles.Invisible 140 , test "pipeline icon is dim" <| 141 \_ -> 142 pipeline 143 |> viewPipeline { defaultState | active = False, hovered = False } 144 |> .icon 145 |> Expect.equal Assets.PipelineIconGrey 146 ] 147 , test "font weight is default" <| 148 \_ -> 149 pipeline 150 |> viewPipeline { defaultState | active = False } 151 |> .name 152 |> .weight 153 |> Expect.equal Styles.Default 154 ] 155 , describe "when archived" 156 [ test "pipeline icon is archived" <| 157 \_ -> 158 pipeline 159 |> Data.withArchived True 160 |> viewPipeline defaultState 161 |> .icon 162 |> Expect.equal Assets.ArchivedPipelineIcon 163 ] 164 , describe "when in all pipelines section" 165 [ test "domID is for AllPipelines section" <| 166 \_ -> 167 pipeline 168 |> viewPipeline { defaultState | isFavoritesSection = False } 169 |> .domID 170 |> Expect.equal 171 (SideBarPipeline AllPipelinesSection Data.pipelineId) 172 ] 173 , describe "when in favorites section" 174 [ test "domID is for Favorites section" <| 175 \_ -> 176 pipeline 177 |> viewPipeline { defaultState | isFavoritesSection = True } 178 |> .domID 179 |> Expect.equal 180 (SideBarPipeline FavoritesSection Data.pipelineId) 181 ] 182 ] 183 184 185 viewPipeline : 186 { active : Bool 187 , hovered : Bool 188 , favorited : Bool 189 , isFavoritesSection : Bool 190 } 191 -> Concourse.Pipeline 192 -> Views.Pipeline 193 viewPipeline { active, hovered, favorited, isFavoritesSection } p = 194 let 195 hoveredDomId = 196 if hovered then 197 HoverState.Hovered (SideBarPipeline AllPipelinesSection Data.pipelineId) 198 199 else 200 HoverState.NoHover 201 202 activePipeline = 203 if active then 204 Just Data.pipelineId 205 206 else 207 Nothing 208 209 favoritedPipelines = 210 if favorited then 211 Set.singleton p.id 212 213 else 214 Set.empty 215 in 216 Pipeline.pipeline 217 { hovered = hoveredDomId 218 , currentPipeline = activePipeline 219 , favoritedPipelines = favoritedPipelines 220 , isFavoritesSection = isFavoritesSection 221 } 222 p 223 224 225 pipeline = 226 Data.pipeline "team" 0 |> Data.withName "pipeline" 227 228 229 pipelineIcon : Html Message -> Query.Single Message 230 pipelineIcon = 231 Query.fromHtml 232 >> Query.children [] 233 >> Query.index 0 234 235 236 pipelineName : Html Message -> Query.Single Message 237 pipelineName = 238 Query.fromHtml 239 >> Query.children [] 240 >> Query.index 1