Skip to content

Commit

Permalink
refactor: cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Feb 7, 2024
1 parent db9f35d commit 5779ecb
Show file tree
Hide file tree
Showing 35 changed files with 468 additions and 258 deletions.
52 changes: 35 additions & 17 deletions src/elm/Components/Form.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import Vela


viewInput :
{ title : Maybe String
{ id_ : String
, title : Maybe String
, subtitle : Maybe (Html msg)
, id_ : String
, val : String
, placeholder_ : String
, classList_ : List ( String, Bool )
Expand All @@ -31,7 +31,7 @@ viewInput :
, disabled_ : Bool
}
-> Html msg
viewInput { title, subtitle, id_, val, placeholder_, classList_, rows_, wrap_, msg, disabled_ } =
viewInput { id_, title, subtitle, val, placeholder_, classList_, rows_, wrap_, msg, disabled_ } =
section
[ class "form-control"
, class "-stack"
Expand All @@ -51,15 +51,16 @@ viewInput { title, subtitle, id_, val, placeholder_, classList_, rows_, wrap_, m
, Maybe.Extra.unwrap Util.attrNone wrap wrap_
, onInput msg
, disabled disabled_
, Util.testAttribute id_
]
[]
]


viewTextarea :
{ title : Maybe String
{ id_ : String
, title : Maybe String
, subtitle : Maybe (Html msg)
, id_ : String
, val : String
, placeholder_ : String
, classList_ : List ( String, Bool )
Expand All @@ -69,7 +70,7 @@ viewTextarea :
, disabled_ : Bool
}
-> Html msg
viewTextarea { title, subtitle, id_, val, placeholder_, classList_, rows_, wrap_, msg, disabled_ } =
viewTextarea { id_, title, subtitle, val, placeholder_, classList_, rows_, wrap_, msg, disabled_ } =
section
[ class "form-control"
, class "-stack"
Expand All @@ -89,21 +90,23 @@ viewTextarea { title, subtitle, id_, val, placeholder_, classList_, rows_, wrap_
, Maybe.Extra.unwrap Util.attrNone wrap wrap_
, onInput msg
, disabled disabled_
, Util.testAttribute id_
]
[]
]


viewCheckbox :
{ title : String
{ id_ : String
, title : String
, subtitle : Maybe (Html msg)
, field : String
, state : Bool
, msg : Bool -> msg
, disabled_ : Bool
}
-> Html msg
viewCheckbox { title, subtitle, field, state, msg, disabled_ } =
viewCheckbox { id_, title, subtitle, field, state, msg, disabled_ } =
div
[ class "form-control"
, Util.testAttribute <| "checkbox-" ++ field
Expand All @@ -114,6 +117,7 @@ viewCheckbox { title, subtitle, field, state, msg, disabled_ } =
, checked state
, onCheck msg
, disabled disabled_
, Util.testAttribute id_
]
[]
, label [ class "form-label", for <| "checkbox-" ++ field ]
Expand All @@ -122,46 +126,49 @@ viewCheckbox { title, subtitle, field, state, msg, disabled_ } =


viewRadio :
{ title : String
{ id_ : String
, title : String
, subtitle : Maybe (Html msg)
, value : String
, field : String
, msg : msg
, disabled_ : Bool
}
-> Html msg
viewRadio { title, subtitle, value, field, msg, disabled_ } =
viewRadio { id_, title, subtitle, value, field, msg, disabled_ } =
div [ class "form-control", Util.testAttribute <| "radio-" ++ field ]
[ input
[ type_ "radio"
, id <| "radio-" ++ field
, checked (value == field)
, onClick msg
, disabled disabled_
, Util.testAttribute id_
]
[]
, label [ class "form-label", for <| "radio-" ++ field ]
[ strong [] [ text title ], viewSubtitle subtitle ]
]


viewSubtitle : Maybe (Html msg) -> Html msg
viewSubtitle subtitle =
Maybe.Extra.unwrap (text "") (\s -> span [] [ text <| " ", s ]) subtitle


viewButton : { msg : msg, text_ : String, classList_ : List ( String, Bool ), disabled_ : Bool } -> Html msg
viewButton { msg, text_, classList_, disabled_ } =
viewButton : { id_ : String, msg : msg, text_ : String, classList_ : List ( String, Bool ), disabled_ : Bool } -> Html msg
viewButton { id_, msg, text_, classList_, disabled_ } =
button
[ class "button"
, class "-outline"
, onClick msg
, disabled disabled_
, classList classList_
, Util.testAttribute id_
]
[ text text_ ]


viewSubtitle : Maybe (Html msg) -> Html msg
viewSubtitle subtitle =
Maybe.Extra.unwrap (text "") (\s -> span [] [ text <| " ", s ]) subtitle


viewAllowEvents :
Shared.Model
->
Expand All @@ -180,6 +187,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.push.branch
, msg = msg { allowEvents = allowEvents, event = "allow_push_branch" }
, disabled_ = False
, id_ = "allow-events-push-branch"
}
, viewCheckbox
{ title = "Tag"
Expand All @@ -188,6 +196,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.push.tag
, msg = msg { allowEvents = allowEvents, event = "allow_push_tag" }
, disabled_ = False
, id_ = "allow-events-push-tag"
}
]
, h3 [ class "settings-subtitle" ] [ text "Delete" ]
Expand All @@ -199,6 +208,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.push.deleteBranch
, msg = msg { allowEvents = allowEvents, event = "allow_push_delete_branch" }
, disabled_ = False
, id_ = "allow-events-push-delete-branch"
}
, viewCheckbox
{ title = "Tag"
Expand All @@ -207,6 +217,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.push.deleteTag
, msg = msg { allowEvents = allowEvents, event = "allow_push_delete_tag" }
, disabled_ = False
, id_ = "allow-events-push-delete-tag"
}
]
, h3 [ class "settings-subtitle" ] [ text "Pull Request" ]
Expand All @@ -218,6 +229,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.pull.opened
, msg = msg { allowEvents = allowEvents, event = "allow_pull_opened" }
, disabled_ = False
, id_ = "allow-events-pull-opened"
}
, viewCheckbox
{ title = "Synchronize"
Expand All @@ -226,6 +238,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.pull.synchronize
, msg = msg { allowEvents = allowEvents, event = "allow_pull_synchronize" }
, disabled_ = False
, id_ = "allow-events-pull-synchronize"
}
, viewCheckbox
{ title = "Edited"
Expand All @@ -234,6 +247,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.pull.edited
, msg = msg { allowEvents = allowEvents, event = "allow_pull_edited" }
, disabled_ = False
, id_ = "allow-events-pull-edited"
}
, viewCheckbox
{ title = "Reopened"
Expand All @@ -242,6 +256,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.pull.reopened
, msg = msg { allowEvents = allowEvents, event = "allow_pull_reopened" }
, disabled_ = False
, id_ = "allow-events-pull-reopened"
}
]
, h3 [ class "settings-subtitle" ] [ text "Deployments" ]
Expand All @@ -253,6 +268,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.deploy.created
, msg = msg { allowEvents = allowEvents, event = "allow_deploy_created" }
, disabled_ = False
, id_ = "allow-events-deploy-created"
}
]
, h3 [ class "settings-subtitle" ] [ text "Comment" ]
Expand All @@ -264,6 +280,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.comment.created
, msg = msg { allowEvents = allowEvents, event = "allow_comment_created" }
, disabled_ = False
, id_ = "allow-events-comment-created"
}
, viewCheckbox
{ title = "Edited"
Expand All @@ -272,6 +289,7 @@ viewAllowEvents shared { msg, allowEvents } =
, state = allowEvents.comment.edited
, msg = msg { allowEvents = allowEvents, event = "allow_comment_edited" }
, disabled_ = False
, id_ = "allow-events-comment-edited"
}
]
]
30 changes: 15 additions & 15 deletions src/elm/Components/Logs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ viewLine pushUrlHashMsg resourceType resourceNumber shift focus logLine lineNumb
]
[ div
[ class "wrapper"
, Util.testAttribute <| String.join "-" [ "log", "line", resourceType, resourceNumber, String.fromInt lineNumber ]
, Util.testAttribute <| String.join "-" [ "log", "line", resourceNumber, String.fromInt lineNumber ]
, class <| Focus.lineRangeStyles (String.toInt resourceNumber) lineNumber focus
]
[ td []
Expand All @@ -173,7 +173,7 @@ viewLine pushUrlHashMsg resourceType resourceNumber shift focus logLine lineNumb
{ hash =
Focus.toString <| Focus.updateLineRange shift (String.toInt resourceNumber) lineNumber focus
}
, Util.testAttribute <| String.join "-" [ "log", "line", "num", resourceType, resourceNumber, String.fromInt lineNumber ]
, Util.testAttribute <| String.join "-" [ "log", "line", "num", resourceNumber, String.fromInt lineNumber ]
, Focus.toAttr
{ group = String.toInt resourceNumber
, a = Just lineNumber
Expand All @@ -182,12 +182,12 @@ viewLine pushUrlHashMsg resourceType resourceNumber shift focus logLine lineNumb
, class "line-number"
, class "button"
, class "-link"
, attribute "aria-label" <| "focus " ++ resourceType ++ " " ++ resourceNumber
, attribute "aria-label" <| "focus log for resource " ++ resourceNumber
]
[ span [] [ text <| String.fromInt lineNumber ] ]
]
, td [ class "break-text", class "overflow-auto" ]
[ code [ Util.testAttribute <| String.join "-" [ "log", "data", resourceType, resourceNumber, String.fromInt lineNumber ] ]
[ code [ Util.testAttribute <| String.join "-" [ "log", "data", resourceNumber, String.fromInt lineNumber ] ]
[ logLine.view
]
]
Expand Down Expand Up @@ -356,12 +356,12 @@ viewJumpToBottomButton props =
, attribute "data-tooltip" "jump to bottom"
, Util.testAttribute <| "jump-to-bottom-" ++ props.resourceNumber
, onClick <| props.msgs.focusOn { target = Logs.bottomTrackerFocusId props.resourceNumber }
, attribute "aria-label" <| "jump to bottom of logs for " ++ props.resourceType ++ " " ++ props.resourceNumber
, attribute "aria-label" <| "jump to bottom of logs for resource " ++ props.resourceNumber
]
[ FeatherIcons.arrowDown
|> FeatherIcons.toHtml
[ attribute "role" "img"
, attribute "aria-label" <| "jump to the bottom of logs for " ++ props.resourceType ++ " " ++ props.resourceNumber
, attribute "aria-label" <| "jump to the bottom of logs for resource " ++ props.resourceNumber
]
]

Expand All @@ -377,12 +377,12 @@ viewJumpToTopButton props =
, attribute "data-tooltip" "jump to top"
, Util.testAttribute <| "jump-to-top-" ++ props.resourceNumber
, onClick <| props.msgs.focusOn { target = Logs.topTrackerFocusId props.resourceNumber }
, attribute "aria-label" <| "jump to top of logs for " ++ props.resourceType ++ " " ++ props.resourceNumber
, attribute "aria-label" <| "jump to top of logs for resource " ++ props.resourceNumber
]
[ FeatherIcons.arrowUp
|> FeatherIcons.toHtml
[ attribute "role" "img"
, attribute "aria-label" <| "jump to the top of logs for " ++ props.resourceType ++ " " ++ props.resourceNumber
, attribute "aria-label" <| "jump to the top of logs for resource " ++ props.resourceNumber
]
]

Expand All @@ -407,9 +407,9 @@ viewDownloadButton props log =
, Util.attrIf logEmpty <| Util.ariaHidden
, Util.testAttribute <| "download-logs-" ++ props.resourceNumber
, onClick <| props.msgs.download { filename = fileName, content = log.rawData, map = Util.base64Decode }
, attribute "aria-label" <| "download logs for " ++ props.resourceType ++ " " ++ props.resourceNumber
, attribute "aria-label" <| "download logs for resource " ++ props.resourceNumber
]
[ text <| "download " ++ props.resourceType ++ " logs" ]
[ text <| "download resource logs" ]


{-| viewFollowButton : renders button for following logs
Expand All @@ -425,13 +425,13 @@ viewFollowButton props =

( tooltip, icon, toFollow ) =
if following == 0 then
( "start following " ++ props.resourceType ++ " logs", FeatherIcons.play, num )
( "start following resource logs", FeatherIcons.play, num )

else if following == num then
( "stop following " ++ props.resourceType ++ " logs", FeatherIcons.pause, 0 )
( "stop following resource logs", FeatherIcons.pause, 0 )

else
( "start following " ++ props.resourceType ++ " logs", FeatherIcons.play, num )
( "start following resource logs", FeatherIcons.play, num )
in
button
[ class "button"
Expand All @@ -440,11 +440,11 @@ viewFollowButton props =
, attribute "data-tooltip" tooltip
, Util.testAttribute <| "follow-logs-" ++ props.resourceNumber
, onClick <| props.msgs.follow { number = toFollow }
, attribute "aria-label" <| tooltip ++ " for " ++ props.resourceType ++ " " ++ props.resourceNumber
, attribute "aria-label" <| tooltip ++ " for resource " ++ props.resourceNumber
]
[ icon
|> FeatherIcons.toHtml
[ attribute "role" "img"
, attribute "aria-label" <| "follow logs for " ++ props.resourceType ++ " " ++ props.resourceNumber
, attribute "aria-label" <| "follow logs for resource " ++ props.resourceNumber
]
]
2 changes: 1 addition & 1 deletion src/elm/Components/Repo.elm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ view shared { toggleFavoriteMsg, org, repo, favorites, filtered } =
[ class "button"
, class "-outline"
, Util.testAttribute "repo-hooks"
, Route.Path.href <| Route.Path.Org_Repo_Audit { org = org, repo = repo }
, Route.Path.href <| Route.Path.Org_Repo_Hooks { org = org, repo = repo }
]
[ text "Audit" ]
, a
Expand Down
11 changes: 10 additions & 1 deletion src/elm/Components/ScheduleForm.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0
--}


module Components.ScheduleForm exposing (viewCronHelp, viewEnabledInput, viewHelp, viewSubmitButton)
module Components.ScheduleForm exposing (viewCronHelp, viewEnabledInput, viewHelp, viewSchedulesNotAllowedWarning, viewSubmitButton)

import Components.Form
import Html
Expand Down Expand Up @@ -75,6 +75,7 @@ viewEnabledInput { msg, value, disabled_ } =
, subtitle = Nothing
, msg = msg "yes"
, disabled_ = disabled_
, id_ = "schedule-active-yes"
}
, Components.Form.viewRadio
{ value = Util.boolToYesNo value
Expand All @@ -83,6 +84,7 @@ viewEnabledInput { msg, value, disabled_ } =
, subtitle = Nothing
, msg = msg "no"
, disabled_ = disabled_
, id_ = "schedule-active-no"
}
]
]
Expand Down Expand Up @@ -112,3 +114,10 @@ viewSubmitButton { msg, disabled_ } =
]
[ text "Submit" ]
]


viewSchedulesNotAllowedWarning : Html msg
viewSchedulesNotAllowedWarning =
span [ class "not-allowed", Util.testAttribute "repo-schedule-not-allowed" ]
[ text "Sorry, Administrators have not enabled Schedules for this repository."
]
2 changes: 2 additions & 0 deletions src/elm/Components/SecretForm.elm
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ viewAllowCommandsInput { msg, value, disabled_ } =
, subtitle = Nothing
, msg = msg "yes"
, disabled_ = disabled_
, id_ = "secret-allow-commands-yes"
}
, Components.Form.viewRadio
{ value = Util.boolToYesNo value
Expand All @@ -155,6 +156,7 @@ viewAllowCommandsInput { msg, value, disabled_ } =
, subtitle = Nothing
, msg = msg "no"
, disabled_ = disabled_
, id_ = "secret-allow-commands-no"
}
]
]
Expand Down
Loading

0 comments on commit 5779ecb

Please sign in to comment.