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

     1  module DashboardPreviewTests exposing (all)
     2  
     3  import Application.Application as Application
     4  import Colors
     5  import Common exposing (defineHoverBehaviour, isColorWithStripes, queryView)
     6  import Concourse
     7  import Concourse.BuildStatus exposing (BuildStatus(..))
     8  import Dashboard.DashboardPreview as DP
     9  import DashboardTests exposing (whenOnDashboard)
    10  import Data
    11  import Expect
    12  import Message.Callback as Callback
    13  import Message.Message exposing (DomID(..), Message(..), PipelinesSection(..))
    14  import Message.Subscription as Subscription
    15  import Message.TopLevelMessage exposing (TopLevelMessage(..))
    16  import Set
    17  import Test exposing (Test, describe, test)
    18  import Test.Html.Query as Query
    19  import Test.Html.Selector exposing (class, containing, id, style, text)
    20  import Time
    21  import Url
    22  
    23  
    24  all : Test
    25  all =
    26      describe "job boxes in dashboard pipeline preview"
    27          [ test "fills available space" <|
    28              \_ ->
    29                  job
    30                      |> viewJob
    31                      |> Query.has [ style "flex-grow" "1" ]
    32          , test "has small separation between adjacent jobs" <|
    33              \_ ->
    34                  job
    35                      |> viewJob
    36                      |> Query.has [ style "margin" "2px" ]
    37          , test "link fills available space" <|
    38              \_ ->
    39                  job
    40                      |> viewJob
    41                      |> Expect.all
    42                          [ Query.has [ style "display" "flex" ]
    43                          , Query.children []
    44                              >> Query.count (Expect.equal 1)
    45                          , Query.children []
    46                              >> Query.first
    47                              >> Query.has [ style "flex-grow" "1" ]
    48                          ]
    49          , defineHoverBehaviour
    50              { name = "pending job"
    51              , setup = dashboardWithJob job
    52              , query = findJobPreview
    53              , unhoveredSelector =
    54                  { description = "light grey background"
    55                  , selector = [ style "background-color" Colors.pending ]
    56                  }
    57              , hoverable = JobPreview AllPipelinesSection jobId
    58              , hoveredSelector =
    59                  { description = "dark grey background"
    60                  , selector = [ style "background-color" Colors.pendingFaded ]
    61                  }
    62              }
    63          , test "pending paused job has blue background" <|
    64              \_ ->
    65                  job
    66                      |> isPaused
    67                      |> viewJob
    68                      |> Query.has [ style "background-color" Colors.paused ]
    69          , test "pending running job has grey striped background" <|
    70              \_ ->
    71                  job
    72                      |> withNextBuild
    73                      |> viewJob
    74                      |> isColorWithStripes
    75                          { thick = Colors.pendingFaded
    76                          , thin = Colors.pending
    77                          }
    78          , test "succeeding job has green background" <|
    79              \_ ->
    80                  job
    81                      |> withStatus BuildStatusSucceeded
    82                      |> viewJob
    83                      |> Query.has [ style "background-color" Colors.success ]
    84          , test "succeeding paused job has blue background" <|
    85              \_ ->
    86                  job
    87                      |> withStatus BuildStatusSucceeded
    88                      |> isPaused
    89                      |> viewJob
    90                      |> Query.has [ style "background-color" Colors.paused ]
    91          , test "succeeding running job has striped green background" <|
    92              \_ ->
    93                  job
    94                      |> withStatus BuildStatusSucceeded
    95                      |> withNextBuild
    96                      |> viewJob
    97                      |> isColorWithStripes
    98                          { thick = Colors.successFaded
    99                          , thin = Colors.success
   100                          }
   101          , test "failing job has red background" <|
   102              \_ ->
   103                  job
   104                      |> withStatus BuildStatusFailed
   105                      |> viewJob
   106                      |> Query.has [ style "background-color" Colors.failure ]
   107          , test "failing paused job has blue background" <|
   108              \_ ->
   109                  job
   110                      |> withStatus BuildStatusFailed
   111                      |> isPaused
   112                      |> viewJob
   113                      |> Query.has [ style "background-color" Colors.paused ]
   114          , test "failing running job has striped red background" <|
   115              \_ ->
   116                  job
   117                      |> withStatus BuildStatusFailed
   118                      |> withNextBuild
   119                      |> viewJob
   120                      |> isColorWithStripes
   121                          { thick = Colors.failureFaded
   122                          , thin = Colors.failure
   123                          }
   124          , test "erroring job has amber background" <|
   125              \_ ->
   126                  job
   127                      |> withStatus BuildStatusErrored
   128                      |> viewJob
   129                      |> Query.has [ style "background-color" Colors.error ]
   130          , test "erroring paused job has blue background" <|
   131              \_ ->
   132                  job
   133                      |> withStatus BuildStatusErrored
   134                      |> isPaused
   135                      |> viewJob
   136                      |> Query.has [ style "background-color" Colors.paused ]
   137          , test "erroring running job has striped amber background" <|
   138              \_ ->
   139                  job
   140                      |> withStatus BuildStatusErrored
   141                      |> withNextBuild
   142                      |> viewJob
   143                      |> isColorWithStripes
   144                          { thick = Colors.errorFaded
   145                          , thin = Colors.error
   146                          }
   147          , test "aborted job has amber background" <|
   148              \_ ->
   149                  job
   150                      |> withStatus BuildStatusAborted
   151                      |> viewJob
   152                      |> Query.has [ style "background-color" Colors.aborted ]
   153          , test "aborted paused job has blue background" <|
   154              \_ ->
   155                  job
   156                      |> withStatus BuildStatusAborted
   157                      |> isPaused
   158                      |> viewJob
   159                      |> Query.has [ style "background-color" Colors.paused ]
   160          , test "aborted running job has striped amber background" <|
   161              \_ ->
   162                  job
   163                      |> withStatus BuildStatusAborted
   164                      |> withNextBuild
   165                      |> viewJob
   166                      |> isColorWithStripes
   167                          { thick = Colors.abortedFaded
   168                          , thin = Colors.aborted
   169                          }
   170          , describe "preview in favorites section" <|
   171              let
   172                  dashboardWithJobInFavoritesSection =
   173                      dashboardWithJob
   174                          >> Application.handleDelivery
   175                              (Subscription.FavoritedPipelinesReceived <| Ok <| Set.singleton 0)
   176                          >> Tuple.first
   177  
   178                  findJobPreviewInFavoritesSection =
   179                      queryView
   180                          >> Query.find [ id "dashboard-favorite-pipelines" ]
   181                          >> Query.find [ class "card", containing [ text "pipeline" ] ]
   182                          >> Query.find [ class "parallel-grid" ]
   183                          >> Query.children []
   184                          >> Query.first
   185              in
   186              [ defineHoverBehaviour
   187                  { name = "pending job"
   188                  , setup = dashboardWithJobInFavoritesSection job
   189                  , query = findJobPreviewInFavoritesSection
   190                  , unhoveredSelector =
   191                      { description = "light grey background"
   192                      , selector = [ style "background-color" Colors.pending ]
   193                      }
   194                  , hoverable = JobPreview FavoritesSection jobId
   195                  , hoveredSelector =
   196                      { description = "dark grey background"
   197                      , selector = [ style "background-color" Colors.pendingFaded ]
   198                      }
   199                  }
   200              , test "hovering over job preview in favorites section does not highlight in all pipelines section" <|
   201                  \_ ->
   202                      dashboardWithJob job
   203                          |> Application.update
   204                              (Update <| Hover <| Just (JobPreview FavoritesSection jobId))
   205                          |> Tuple.first
   206                          |> findJobPreview
   207                          |> Query.has [ style "background-color" Colors.pending ]
   208              ]
   209          ]
   210  
   211  
   212  viewJob : Concourse.Job -> Query.Single TopLevelMessage
   213  viewJob =
   214      dashboardWithJob >> findJobPreview
   215  
   216  
   217  dashboardWithJob : Concourse.Job -> Application.Model
   218  dashboardWithJob j =
   219      whenOnDashboard { highDensity = False }
   220          |> Application.handleCallback
   221              (Callback.AllJobsFetched <|
   222                  Ok
   223                      [ j
   224                      , { j | pipelineName = "other" }
   225                      ]
   226              )
   227          |> Tuple.first
   228          |> Application.handleCallback
   229              (Callback.AllTeamsFetched <|
   230                  Ok
   231                      [ { id = 0, name = "team" }
   232                      ]
   233              )
   234          |> Tuple.first
   235          |> Application.handleCallback
   236              (Callback.AllPipelinesFetched <|
   237                  Ok
   238                      [ Data.pipeline "team" 0 |> Data.withName "pipeline"
   239                      , Data.pipeline "team" 1 |> Data.withName "other"
   240                      ]
   241              )
   242          |> Tuple.first
   243  
   244  
   245  findJobPreview : Application.Model -> Query.Single TopLevelMessage
   246  findJobPreview =
   247      queryView
   248          >> Query.find [ class "dashboard-team-group", containing [ text "team" ] ]
   249          >> Query.find [ class "card", containing [ text "pipeline" ] ]
   250          >> Query.find [ class "parallel-grid" ]
   251          >> Query.children []
   252          >> Query.first
   253  
   254  
   255  job : Concourse.Job
   256  job =
   257      { name = "job"
   258      , pipelineName = "pipeline"
   259      , teamName = "team"
   260      , nextBuild = Nothing
   261      , finishedBuild = Nothing
   262      , transitionBuild = Nothing
   263      , paused = False
   264      , disableManualTrigger = False
   265      , inputs = []
   266      , outputs = []
   267      , groups = []
   268      }
   269  
   270  
   271  withNextBuild : Concourse.Job -> Concourse.Job
   272  withNextBuild j =
   273      { j
   274          | nextBuild =
   275              Just
   276                  { id = 2
   277                  , name = "2"
   278                  , job = Just jobId
   279                  , status = BuildStatusStarted
   280                  , duration = { startedAt = Nothing, finishedAt = Nothing }
   281                  , reapTime = Nothing
   282                  }
   283      }
   284  
   285  
   286  withStatus : BuildStatus -> Concourse.Job -> Concourse.Job
   287  withStatus status j =
   288      { j
   289          | finishedBuild =
   290              Just
   291                  { id = 1
   292                  , name = "1"
   293                  , job = Just jobId
   294                  , status = status
   295                  , duration = { startedAt = Nothing, finishedAt = Nothing }
   296                  , reapTime = Nothing
   297                  }
   298      }
   299  
   300  
   301  isPaused : Concourse.Job -> Concourse.Job
   302  isPaused j =
   303      { j | paused = True }
   304  
   305  
   306  jobId : Concourse.JobIdentifier
   307  jobId =
   308      Data.jobId