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

     1  module DashboardCacheTests exposing (all)
     2  
     3  import Application.Application as Application
     4  import Common
     5  import Concourse.BuildStatus exposing (BuildStatus(..))
     6  import DashboardTests exposing (whenOnDashboard)
     7  import Data
     8  import Message.Callback exposing (Callback(..))
     9  import Message.Effects exposing (Effect(..))
    10  import Message.Message as Message exposing (DropTarget(..))
    11  import Message.Subscription as Subscription exposing (Delivery(..))
    12  import Message.TopLevelMessage as TopLevelMessage
    13  import Test exposing (Test, describe, test)
    14  import Test.Html.Query as Query
    15  import Test.Html.Selector exposing (class, containing, text)
    16  import Url
    17  
    18  
    19  all : Test
    20  all =
    21      describe "dashboard cache tests"
    22          [ test "requests the cached jobs on page load" <|
    23              \_ ->
    24                  Application.init
    25                      { turbulenceImgSrc = ""
    26                      , notFoundImgSrc = "notfound.svg"
    27                      , csrfToken = "csrf_token"
    28                      , authToken = ""
    29                      , pipelineRunningKeyframes = ""
    30                      }
    31                      { protocol = Url.Http
    32                      , host = ""
    33                      , port_ = Nothing
    34                      , path = "/"
    35                      , query = Nothing
    36                      , fragment = Nothing
    37                      }
    38                      |> Tuple.second
    39                      |> Common.contains LoadCachedJobs
    40          , test "requests the cached pipelines on page load" <|
    41              \_ ->
    42                  Application.init
    43                      { turbulenceImgSrc = ""
    44                      , notFoundImgSrc = "notfound.svg"
    45                      , csrfToken = "csrf_token"
    46                      , authToken = ""
    47                      , pipelineRunningKeyframes = ""
    48                      }
    49                      { protocol = Url.Http
    50                      , host = ""
    51                      , port_ = Nothing
    52                      , path = "/"
    53                      , query = Nothing
    54                      , fragment = Nothing
    55                      }
    56                      |> Tuple.second
    57                      |> Common.contains LoadCachedPipelines
    58          , test "requests the cached teams on page load" <|
    59              \_ ->
    60                  Application.init
    61                      { turbulenceImgSrc = ""
    62                      , notFoundImgSrc = "notfound.svg"
    63                      , csrfToken = "csrf_token"
    64                      , authToken = ""
    65                      , pipelineRunningKeyframes = ""
    66                      }
    67                      { protocol = Url.Http
    68                      , host = ""
    69                      , port_ = Nothing
    70                      , path = "/"
    71                      , query = Nothing
    72                      , fragment = Nothing
    73                      }
    74                      |> Tuple.second
    75                      |> Common.contains LoadCachedTeams
    76          , test "subscribes to receive cached jobs" <|
    77              \_ ->
    78                  whenOnDashboard { highDensity = False }
    79                      |> Application.subscriptions
    80                      |> Common.contains Subscription.OnCachedJobsReceived
    81          , test "subscribes to receive cached pipelines" <|
    82              \_ ->
    83                  whenOnDashboard { highDensity = False }
    84                      |> Application.subscriptions
    85                      |> Common.contains Subscription.OnCachedPipelinesReceived
    86          , test "subscribes to receive cached teams" <|
    87              \_ ->
    88                  whenOnDashboard { highDensity = False }
    89                      |> Application.subscriptions
    90                      |> Common.contains Subscription.OnCachedTeamsReceived
    91          , test "renders pipelines when receive cached pipelines delivery" <|
    92              \_ ->
    93                  whenOnDashboard { highDensity = False }
    94                      |> Application.handleDelivery
    95                          (CachedPipelinesReceived <|
    96                              Ok <|
    97                                  [ Data.pipeline "team" 0 ]
    98                          )
    99                      |> Tuple.first
   100                      |> Common.queryView
   101                      |> Query.has [ class "pipeline-wrapper", containing [ text "pipeline-0" ] ]
   102          , test "renders jobs in pipelines when receive cached jobs delivery" <|
   103              \_ ->
   104                  whenOnDashboard { highDensity = False }
   105                      |> Application.handleDelivery
   106                          (CachedPipelinesReceived <|
   107                              Ok <|
   108                                  [ Data.pipeline "team" 0 ]
   109                          )
   110                      |> Tuple.first
   111                      |> Application.handleDelivery
   112                          (CachedJobsReceived <|
   113                              Ok <|
   114                                  [ Data.job 0 ]
   115                          )
   116                      |> Tuple.first
   117                      |> Common.queryView
   118                      |> Query.find [ class "pipeline-wrapper" ]
   119                      |> Query.has [ class "parallel-grid" ]
   120          , test "ignores the job cache after fetching successfully" <|
   121              \_ ->
   122                  whenOnDashboard { highDensity = False }
   123                      |> Application.handleDelivery
   124                          (CachedPipelinesReceived <|
   125                              Ok <|
   126                                  [ Data.pipeline "team" 0 ]
   127                          )
   128                      |> Tuple.first
   129                      |> Application.handleCallback
   130                          (AllJobsFetched <|
   131                              Ok <|
   132                                  [ Data.job 0 ]
   133                          )
   134                      |> Tuple.first
   135                      |> Application.handleDelivery
   136                          (CachedJobsReceived <|
   137                              Ok <|
   138                                  []
   139                          )
   140                      |> Tuple.first
   141                      |> Common.queryView
   142                      |> Query.find [ class "pipeline-wrapper" ]
   143                      |> Query.has [ class "parallel-grid" ]
   144          , test "saves jobs to cache when fetched" <|
   145              \_ ->
   146                  whenOnDashboard { highDensity = False }
   147                      |> Application.handleCallback
   148                          (AllJobsFetched <|
   149                              Ok <|
   150                                  [ Data.job 0 ]
   151                          )
   152                      |> Tuple.second
   153                      |> Common.contains (SaveCachedJobs [ Data.job 0 ])
   154          , test "removes build information from jobs when saving to cache" <|
   155              \_ ->
   156                  let
   157                      jobWithoutBuild =
   158                          Data.job 0
   159  
   160                      jobWithBuild =
   161                          { jobWithoutBuild
   162                              | finishedBuild = Just <| Data.jobBuild BuildStatusSucceeded
   163                              , transitionBuild = Just <| Data.jobBuild BuildStatusSucceeded
   164                              , nextBuild = Just <| Data.jobBuild BuildStatusSucceeded
   165                          }
   166                  in
   167                  whenOnDashboard { highDensity = False }
   168                      |> Application.handleCallback
   169                          (AllJobsFetched <|
   170                              Ok <|
   171                                  [ jobWithBuild ]
   172                          )
   173                      |> Tuple.second
   174                      |> Common.contains (SaveCachedJobs [ jobWithoutBuild ])
   175          , test "does not save jobs to cache when fetched with no change" <|
   176              \_ ->
   177                  whenOnDashboard { highDensity = False }
   178                      |> Application.handleDelivery
   179                          (CachedJobsReceived <|
   180                              Ok <|
   181                                  [ Data.job 0 ]
   182                          )
   183                      |> Tuple.first
   184                      |> Application.handleCallback
   185                          (AllJobsFetched <|
   186                              Ok <|
   187                                  [ Data.job 0 ]
   188                          )
   189                      |> Tuple.second
   190                      |> Common.notContains (SaveCachedJobs [ Data.job 0 ])
   191          , test "bounds the number of cached jobs to 1000" <|
   192              \_ ->
   193                  let
   194                      firstNJobs n =
   195                          List.range 0 (n - 1) |> List.map Data.job
   196                  in
   197                  whenOnDashboard { highDensity = False }
   198                      |> Application.handleCallback
   199                          (AllJobsFetched <|
   200                              Ok <|
   201                                  firstNJobs 2000
   202                          )
   203                      |> Tuple.second
   204                      |> Common.contains (SaveCachedJobs <| firstNJobs 1000)
   205          , test "saves pipelines to cache when fetched" <|
   206              \_ ->
   207                  whenOnDashboard { highDensity = False }
   208                      |> Application.handleCallback
   209                          (AllPipelinesFetched <|
   210                              Ok <|
   211                                  [ Data.pipeline "team" 0 ]
   212                          )
   213                      |> Tuple.second
   214                      |> Common.contains (SaveCachedPipelines [ Data.pipeline "team" 0 ])
   215          , test "ignores cached pipelines if we've already fetched from network" <|
   216              \_ ->
   217                  whenOnDashboard { highDensity = False }
   218                      |> Application.handleCallback
   219                          (AllPipelinesFetched <|
   220                              Ok <|
   221                                  [ Data.pipeline "team" 0 ]
   222                          )
   223                      |> Tuple.first
   224                      |> Application.handleDelivery
   225                          (CachedPipelinesReceived <|
   226                              Ok <|
   227                                  []
   228                          )
   229                      |> Tuple.first
   230                      |> Common.queryView
   231                      |> Query.has [ class "pipeline-wrapper", containing [ text "pipeline-0" ] ]
   232          , test "does not save pipelines to cache when fetched with no change" <|
   233              \_ ->
   234                  whenOnDashboard { highDensity = False }
   235                      |> Application.handleDelivery
   236                          (CachedPipelinesReceived <|
   237                              Ok <|
   238                                  [ Data.pipeline "team" 0 ]
   239                          )
   240                      |> Tuple.first
   241                      |> Application.handleCallback
   242                          (AllPipelinesFetched <|
   243                              Ok <|
   244                                  [ Data.pipeline "team" 0 ]
   245                          )
   246                      |> Tuple.second
   247                      |> Common.notContains (SaveCachedPipelines [ Data.pipeline "team" 0 ])
   248          , test "saves pipelines to cache when re-ordered" <|
   249              \_ ->
   250                  whenOnDashboard { highDensity = False }
   251                      |> Application.handleCallback
   252                          (AllPipelinesFetched <|
   253                              Ok <|
   254                                  [ Data.pipeline "team" 0, Data.pipeline "team" 1 ]
   255                          )
   256                      |> Tuple.first
   257                      |> Application.update
   258                          (TopLevelMessage.Update <| Message.DragStart "team" "pipeline-0")
   259                      |> Tuple.first
   260                      |> Application.update
   261                          (TopLevelMessage.Update <| Message.DragOver <| After "pipeline-1")
   262                      |> Tuple.first
   263                      |> Application.update
   264                          (TopLevelMessage.Update <| Message.DragEnd)
   265                      |> Tuple.second
   266                      |> Common.contains (SaveCachedPipelines [ Data.pipeline "team" 1, Data.pipeline "team" 0 ])
   267          , test "saves teams to cache when fetched" <|
   268              \_ ->
   269                  whenOnDashboard { highDensity = False }
   270                      |> Application.handleCallback
   271                          (AllTeamsFetched <|
   272                              Ok <|
   273                                  [ { id = 0, name = "team-0" } ]
   274                          )
   275                      |> Tuple.second
   276                      |> Common.contains (SaveCachedTeams [ { id = 0, name = "team-0" } ])
   277          , test "does not save teams to cache when fetched with no change" <|
   278              \_ ->
   279                  whenOnDashboard { highDensity = False }
   280                      |> Application.handleDelivery
   281                          (CachedTeamsReceived <|
   282                              Ok <|
   283                                  [ { id = 0, name = "team-0" } ]
   284                          )
   285                      |> Tuple.first
   286                      |> Application.handleCallback
   287                          (AllTeamsFetched <|
   288                              Ok <|
   289                                  [ { id = 0, name = "team-0" } ]
   290                          )
   291                      |> Tuple.second
   292                      |> Common.notContains (SaveCachedPipelines [ Data.pipeline "team" 0 ])
   293          , test "deletes cached pipelines on logged out" <|
   294              \_ ->
   295                  whenOnDashboard { highDensity = False }
   296                      |> Application.handleCallback
   297                          (LoggedOut <| Ok ())
   298                      |> Tuple.second
   299                      |> Common.contains DeleteCachedPipelines
   300          , test "deletes cached jobs on logged out" <|
   301              \_ ->
   302                  whenOnDashboard { highDensity = False }
   303                      |> Application.handleCallback
   304                          (LoggedOut <| Ok ())
   305                      |> Tuple.second
   306                      |> Common.contains DeleteCachedJobs
   307          , test "deletes cached teams on logged out" <|
   308              \_ ->
   309                  whenOnDashboard { highDensity = False }
   310                      |> Application.handleCallback
   311                          (LoggedOut <| Ok ())
   312                      |> Tuple.second
   313                      |> Common.contains DeleteCachedTeams
   314          ]