github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/tests/PinMenu/PinMenuTests.elm (about)

     1  module PinMenu.PinMenuTests exposing (all)
     2  
     3  import Colors
     4  import Concourse
     5  import Data
     6  import Dict
     7  import Expect
     8  import HoverState
     9  import Json.Encode as JE
    10  import Message.Message exposing (DomID(..), Message(..))
    11  import Pipeline.PinMenu.PinMenu as PinMenu
    12  import Pipeline.PinMenu.Views as Views
    13  import Pipeline.Pipeline as Pipeline
    14  import Routes
    15  import SideBar.Styles as SS
    16  import Test exposing (Test, describe, test)
    17  import Test.Html.Event as Event
    18  import Test.Html.Query as Query
    19  import Test.Html.Selector exposing (id)
    20  import Views.Styles
    21  
    22  
    23  init =
    24      Pipeline.init
    25          { pipelineLocator = Data.pipelineId
    26          , turbulenceImgSrc = ""
    27          , selectedGroups = []
    28          }
    29          |> Tuple.first
    30  
    31  
    32  all : Test
    33  all =
    34      describe "pin menu"
    35          [ test "not clickable if there are no pinned resources" <|
    36              \_ ->
    37                  init
    38                      |> PinMenu.pinMenu { hovered = HoverState.NoHover }
    39                      |> .clickable
    40                      |> Expect.equal False
    41          , test "has dim icon if there are no pinned resources" <|
    42              \_ ->
    43                  init
    44                      |> PinMenu.pinMenu { hovered = HoverState.NoHover }
    45                      |> .opacity
    46                      |> Expect.equal SS.Dim
    47          , test "has dark background" <|
    48              \_ ->
    49                  init
    50                      |> PinMenu.pinMenu { hovered = HoverState.NoHover }
    51                      |> .background
    52                      |> Expect.equal Views.Dark
    53          , test "has no badge if there are no pinned resources" <|
    54              \_ ->
    55                  init
    56                      |> PinMenu.pinMenu { hovered = HoverState.NoHover }
    57                      |> .badge
    58                      |> Expect.equal Nothing
    59          , describe "with pinned resources" <|
    60              let
    61                  model =
    62                      { init
    63                          | fetchedResources =
    64                              Just [ Data.resource "v1" |> Data.withName "test" ]
    65                      }
    66              in
    67              [ test "is hoverable" <|
    68                  \_ ->
    69                      model
    70                          |> PinMenu.pinMenu { hovered = HoverState.NoHover }
    71                          |> .hoverable
    72                          |> Expect.equal True
    73              , test "is clickable" <|
    74                  \_ ->
    75                      model
    76                          |> PinMenu.pinMenu { hovered = HoverState.NoHover }
    77                          |> .clickable
    78                          |> Expect.equal True
    79              , test "has greyed-out icon" <|
    80                  \_ ->
    81                      model
    82                          |> PinMenu.pinMenu { hovered = HoverState.NoHover }
    83                          |> .opacity
    84                          |> Expect.equal SS.GreyedOut
    85              , test "has pin count badge" <|
    86                  \_ ->
    87                      model
    88                          |> PinMenu.pinMenu { hovered = HoverState.NoHover }
    89                          |> .badge
    90                          |> Expect.equal
    91                              (Just
    92                                  { color = Colors.pinned
    93                                  , diameterPx = 15
    94                                  , position =
    95                                      Views.TopRight
    96                                          (Views.Px 10)
    97                                          (Views.Px 10)
    98                                  , text = "1"
    99                                  }
   100                              )
   101              , test "has no dropdown when unhovered" <|
   102                  \_ ->
   103                      model
   104                          |> PinMenu.pinMenu { hovered = HoverState.NoHover }
   105                          |> .dropdown
   106                          |> Expect.equal Nothing
   107              , test "has bright icon when hovered" <|
   108                  \_ ->
   109                      model
   110                          |> PinMenu.pinMenu { hovered = HoverState.Hovered PinIcon }
   111                          |> .opacity
   112                          |> Expect.equal SS.Bright
   113              , test "clicking brightens background" <|
   114                  \_ ->
   115                      ( model, [] )
   116                          |> PinMenu.update (Click PinIcon)
   117                          |> Tuple.first
   118                          |> PinMenu.pinMenu { hovered = HoverState.NoHover }
   119                          |> .background
   120                          |> Expect.equal Views.Light
   121              , test "clicking brightens icon" <|
   122                  \_ ->
   123                      ( model, [] )
   124                          |> PinMenu.update (Click PinIcon)
   125                          |> Tuple.first
   126                          |> PinMenu.pinMenu { hovered = HoverState.NoHover }
   127                          |> .opacity
   128                          |> Expect.equal SS.Bright
   129              , test "clicking reveals dropdown" <|
   130                  \_ ->
   131                      ( model, [] )
   132                          |> PinMenu.update (Click PinIcon)
   133                          |> Tuple.first
   134                          |> PinMenu.pinMenu { hovered = HoverState.NoHover }
   135                          |> .dropdown
   136                          |> Expect.equal
   137                              (Just
   138                                  { position =
   139                                      Views.TopRight
   140                                          (Views.Percent 100)
   141                                          (Views.Percent 0)
   142                                  , items =
   143                                      [ { title =
   144                                              { content = "test"
   145                                              , fontWeight = Views.Styles.fontWeightDefault
   146                                              , color = Colors.text
   147                                              }
   148                                        , table =
   149                                              [ { left = "version"
   150                                                , right = "v1"
   151                                                , color = Colors.text
   152                                                }
   153                                              ]
   154                                        , background = Colors.pinMenuBackground
   155                                        , paddingPx = 10
   156                                        , hoverable = True
   157                                        , onClick =
   158                                              GoToRoute <|
   159                                                  Routes.Resource
   160                                                      { id = Data.resourceId |> Data.withResourceName "test"
   161                                                      , page = Nothing
   162                                                      }
   163                                        }
   164                                      ]
   165                                  }
   166                              )
   167              , test "clicking again dismisses dropdown" <|
   168                  \_ ->
   169                      ( { model | pinMenuExpanded = True }, [] )
   170                          |> PinMenu.update (Click PinIcon)
   171                          |> Tuple.first
   172                          |> PinMenu.pinMenu { hovered = HoverState.NoHover }
   173                          |> .dropdown
   174                          |> Expect.equal Nothing
   175              , test "hovered dropdown item has darker background" <|
   176                  \_ ->
   177                      { model | pinMenuExpanded = True }
   178                          |> PinMenu.pinMenu
   179                              { hovered =
   180                                  HoverState.Hovered <| PinMenuDropDown "test"
   181                              }
   182                          |> .dropdown
   183                          |> Expect.equal
   184                              (Just
   185                                  { position =
   186                                      Views.TopRight
   187                                          (Views.Percent 100)
   188                                          (Views.Percent 0)
   189                                  , items =
   190                                      [ { title =
   191                                              { content = "test"
   192                                              , fontWeight = Views.Styles.fontWeightDefault
   193                                              , color = Colors.text
   194                                              }
   195                                        , table =
   196                                              [ { left = "version"
   197                                                , right = "v1"
   198                                                , color = Colors.text
   199                                                }
   200                                              ]
   201                                        , background = Colors.pinMenuHover
   202                                        , paddingPx = 10
   203                                        , hoverable = True
   204                                        , onClick =
   205                                              GoToRoute <|
   206                                                  Routes.Resource
   207                                                      { id = Data.resourceId |> Data.withResourceName "test"
   208                                                      , page = Nothing
   209                                                      }
   210                                        }
   211                                      ]
   212                                  }
   213                              )
   214              ]
   215          ]