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

     1  module Data exposing
     2      ( build
     3      , dashboardPipeline
     4      , elementPosition
     5      , httpForbidden
     6      , httpInternalServerError
     7      , httpNotFound
     8      , httpNotImplemented
     9      , httpUnauthorized
    10      , job
    11      , jobBuild
    12      , jobBuildId
    13      , jobId
    14      , jobName
    15      , leftClickEvent
    16      , longJobBuildId
    17      , pipeline
    18      , pipelineId
    19      , pipelineName
    20      , resource
    21      , resourceId
    22      , resourceName
    23      , resourceVersionId
    24      , shortJobId
    25      , shortPipelineId
    26      , shortResourceId
    27      , teamName
    28      , version
    29      , versionedResource
    30      , withArchived
    31      , withBackgroundImage
    32      , withBuildName
    33      , withDisableManualTrigger
    34      , withGroups
    35      , withJobName
    36      , withName
    37      , withPaused
    38      , withPipelineName
    39      , withPublic
    40      , withResourceName
    41      , withShortJobId
    42      , withShortPipelineId
    43      , withShortResourceId
    44      , withTeamName
    45      )
    46  
    47  import Browser.Dom
    48  import Concourse
    49  import Concourse.BuildStatus as BuildStatus
    50  import Dashboard.Group.Models
    51  import Dict exposing (Dict)
    52  import Http
    53  import Json.Encode
    54  import Test.Html.Event as Event
    55  import Time
    56  
    57  
    58  httpUnauthorized : Result Http.Error a
    59  httpUnauthorized =
    60      Err <|
    61          Http.BadStatus
    62              { url = "http://example.com"
    63              , status =
    64                  { code = 401
    65                  , message = ""
    66                  }
    67              , headers = Dict.empty
    68              , body = ""
    69              }
    70  
    71  
    72  httpForbidden : Result Http.Error a
    73  httpForbidden =
    74      Err <|
    75          Http.BadStatus
    76              { url = "http://example.com"
    77              , status =
    78                  { code = 403
    79                  , message = ""
    80                  }
    81              , headers = Dict.empty
    82              , body = ""
    83              }
    84  
    85  
    86  httpNotFound : Result Http.Error a
    87  httpNotFound =
    88      Err <|
    89          Http.BadStatus
    90              { url = "http://example.com"
    91              , status =
    92                  { code = 404
    93                  , message = "not found"
    94                  }
    95              , headers = Dict.empty
    96              , body = ""
    97              }
    98  
    99  
   100  httpNotImplemented : Result Http.Error a
   101  httpNotImplemented =
   102      Err <|
   103          Http.BadStatus
   104              { url = "http://example.com"
   105              , status =
   106                  { code = 501
   107                  , message = "not implemented"
   108                  }
   109              , headers = Dict.empty
   110              , body = ""
   111              }
   112  
   113  
   114  httpInternalServerError : Result Http.Error a
   115  httpInternalServerError =
   116      Err <|
   117          Http.BadStatus
   118              { url = "http://example.com"
   119              , status =
   120                  { code = 500
   121                  , message = "internal server error"
   122                  }
   123              , headers = Dict.empty
   124              , body = ""
   125              }
   126  
   127  
   128  resource : String -> Concourse.Resource
   129  resource pinnedVersion =
   130      { teamName = teamName
   131      , pipelineName = pipelineName
   132      , name = resourceName
   133      , lastChecked = Nothing
   134      , pinnedVersion = Just <| version pinnedVersion
   135      , pinnedInConfig = False
   136      , pinComment = Nothing
   137      , icon = Nothing
   138      , build = Nothing
   139      }
   140  
   141  
   142  pipeline : String -> Int -> Concourse.Pipeline
   143  pipeline team id =
   144      { id = id
   145      , name = "pipeline-" ++ String.fromInt id
   146      , paused = False
   147      , archived = False
   148      , public = True
   149      , teamName = team
   150      , groups = []
   151      , backgroundImage = Maybe.Nothing
   152      }
   153  
   154  
   155  dashboardPipeline : Int -> Bool -> Dashboard.Group.Models.Pipeline
   156  dashboardPipeline id public =
   157      { id = id
   158      , name = pipelineName
   159      , teamName = teamName
   160      , public = public
   161      , isToggleLoading = False
   162      , isVisibilityLoading = False
   163      , paused = False
   164      , archived = False
   165      , stale = False
   166      , jobsDisabled = False
   167      }
   168  
   169  
   170  withPaused : Bool -> { r | paused : Bool } -> { r | paused : Bool }
   171  withPaused paused p =
   172      { p | paused = paused }
   173  
   174  
   175  withArchived : Bool -> { r | archived : Bool } -> { r | archived : Bool }
   176  withArchived archived p =
   177      { p | archived = archived }
   178  
   179  
   180  withPublic : Bool -> { r | public : Bool } -> { r | public : Bool }
   181  withPublic public p =
   182      { p | public = public }
   183  
   184  
   185  withName : String -> { r | name : String } -> { r | name : String }
   186  withName name p =
   187      { p | name = name }
   188  
   189  
   190  withGroups : List Concourse.PipelineGroup -> { r | groups : List Concourse.PipelineGroup } -> { r | groups : List Concourse.PipelineGroup }
   191  withGroups groups p =
   192      { p | groups = groups }
   193  
   194  
   195  withBackgroundImage : String -> { r | backgroundImage : Maybe String } -> { r | backgroundImage : Maybe String }
   196  withBackgroundImage bg p =
   197      { p | backgroundImage = Just bg }
   198  
   199  
   200  job : Int -> Concourse.Job
   201  job pipelineID =
   202      { name = jobName
   203      , pipelineName = "pipeline-" ++ String.fromInt pipelineID
   204      , teamName = teamName
   205      , nextBuild = Nothing
   206      , finishedBuild = Nothing
   207      , transitionBuild = Nothing
   208      , paused = False
   209      , disableManualTrigger = False
   210      , inputs = []
   211      , outputs = []
   212      , groups = []
   213      }
   214  
   215  
   216  withDisableManualTrigger : Bool -> { r | disableManualTrigger : Bool } -> { r | disableManualTrigger : Bool }
   217  withDisableManualTrigger disableManualTrigger p =
   218      { p | disableManualTrigger = disableManualTrigger }
   219  
   220  
   221  withTeamName : String -> { r | teamName : String } -> { r | teamName : String }
   222  withTeamName name p =
   223      { p | teamName = name }
   224  
   225  
   226  withPipelineName : String -> { r | pipelineName : String } -> { r | pipelineName : String }
   227  withPipelineName name p =
   228      { p | pipelineName = name }
   229  
   230  
   231  withJobName : String -> { r | jobName : String } -> { r | jobName : String }
   232  withJobName name p =
   233      { p | jobName = name }
   234  
   235  
   236  withResourceName : String -> { r | resourceName : String } -> { r | resourceName : String }
   237  withResourceName name p =
   238      { p | resourceName = name }
   239  
   240  
   241  withBuildName : String -> { r | buildName : String } -> { r | buildName : String }
   242  withBuildName name p =
   243      { p | buildName = name }
   244  
   245  
   246  jobName =
   247      "job"
   248  
   249  
   250  teamName =
   251      "team"
   252  
   253  
   254  pipelineName =
   255      "pipeline"
   256  
   257  
   258  resourceName =
   259      "resource"
   260  
   261  
   262  buildName =
   263      "1"
   264  
   265  
   266  withShortPipelineId =
   267      withPipelineName "p"
   268          >> withTeamName "t"
   269  
   270  
   271  withShortJobId =
   272      withShortPipelineId >> withJobName "j"
   273  
   274  
   275  withShortResourceId =
   276      withShortPipelineId >> withResourceName "r"
   277  
   278  
   279  versionedResource : String -> Int -> Concourse.VersionedResource
   280  versionedResource v id =
   281      { id = id
   282      , version = version v
   283      , metadata = []
   284      , enabled = True
   285      }
   286  
   287  
   288  version : String -> Dict String String
   289  version v =
   290      Dict.fromList [ ( "version", v ) ]
   291  
   292  
   293  pipelineId : Concourse.PipelineIdentifier
   294  pipelineId =
   295      { teamName = teamName
   296      , pipelineName = pipelineName
   297      }
   298  
   299  
   300  shortPipelineId : Concourse.PipelineIdentifier
   301  shortPipelineId =
   302      pipelineId |> withShortPipelineId
   303  
   304  
   305  jobId : Concourse.JobIdentifier
   306  jobId =
   307      { teamName = teamName
   308      , pipelineName = pipelineName
   309      , jobName = jobName
   310      }
   311  
   312  
   313  shortJobId : Concourse.JobIdentifier
   314  shortJobId =
   315      jobId |> withShortJobId
   316  
   317  
   318  resourceId : Concourse.ResourceIdentifier
   319  resourceId =
   320      { teamName = teamName
   321      , pipelineName = pipelineName
   322      , resourceName = resourceName
   323      }
   324  
   325  
   326  shortResourceId : Concourse.ResourceIdentifier
   327  shortResourceId =
   328      resourceId |> withShortResourceId
   329  
   330  
   331  resourceVersionId : Int -> Concourse.VersionedResourceIdentifier
   332  resourceVersionId v =
   333      { teamName = teamName
   334      , pipelineName = pipelineName
   335      , resourceName = resourceName
   336      , versionID = v
   337      }
   338  
   339  
   340  
   341  -- jobBuildId is really shortJobBuildId, but since jobBuild returns a short jobId,
   342  -- it would be weird for jobBuildId to not represent jobBuild
   343  
   344  
   345  jobBuildId : Concourse.JobBuildIdentifier
   346  jobBuildId =
   347      longJobBuildId |> withShortJobId
   348  
   349  
   350  longJobBuildId : Concourse.JobBuildIdentifier
   351  longJobBuildId =
   352      { teamName = teamName
   353      , pipelineName = pipelineName
   354      , jobName = jobName
   355      , buildName = buildName
   356      }
   357  
   358  
   359  build : BuildStatus.BuildStatus -> Concourse.Build
   360  build status =
   361      { id = 1
   362      , name = buildName
   363      , job = Nothing
   364      , status = status
   365      , duration =
   366          { startedAt =
   367              case status of
   368                  BuildStatus.BuildStatusPending ->
   369                      Nothing
   370  
   371                  _ ->
   372                      Just <| Time.millisToPosix 0
   373          , finishedAt =
   374              if BuildStatus.isRunning status then
   375                  Nothing
   376  
   377              else
   378                  Just <| Time.millisToPosix 0
   379          }
   380      , reapTime = Nothing
   381      }
   382  
   383  
   384  jobBuild : BuildStatus.BuildStatus -> Concourse.Build
   385  jobBuild status =
   386      { id = 1
   387      , name = buildName
   388      , job = Just (jobId |> withShortJobId)
   389      , status = status
   390      , duration =
   391          { startedAt =
   392              case status of
   393                  BuildStatus.BuildStatusPending ->
   394                      Nothing
   395  
   396                  _ ->
   397                      Just <| Time.millisToPosix 0
   398          , finishedAt =
   399              if BuildStatus.isRunning status then
   400                  Nothing
   401  
   402              else
   403                  Just <| Time.millisToPosix 0
   404          }
   405      , reapTime = Nothing
   406      }
   407  
   408  
   409  elementPosition : Browser.Dom.Element
   410  elementPosition =
   411      { scene =
   412          { width = 0
   413          , height = 0
   414          }
   415      , viewport =
   416          { width = 0
   417          , height = 0
   418          , x = 0
   419          , y = 0
   420          }
   421      , element =
   422          { x = 0
   423          , y = 0
   424          , width = 1
   425          , height = 1
   426          }
   427      }
   428  
   429  
   430  leftClickEvent : ( String, Json.Encode.Value )
   431  leftClickEvent =
   432      Event.custom "click" <|
   433          Json.Encode.object
   434              [ ( "ctrlKey", Json.Encode.bool False )
   435              , ( "altKey", Json.Encode.bool False )
   436              , ( "metaKey", Json.Encode.bool False )
   437              , ( "shiftKey", Json.Encode.bool False )
   438              , ( "button", Json.Encode.int 0 )
   439              ]