Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3rw3rk committed Sep 19, 2024
1 parent 8df0092 commit e334fe3
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 23 deletions.
63 changes: 63 additions & 0 deletions cypress/fixtures/user_dashboards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[
{
"dashboard": {
"id": "6e26a6d0-2fc3-4531-a04d-678a58135288",
"name": "demo dashboard",
"created_at": 1726757028,
"created_by": "CookieCat",
"updated_at": 1726757028,
"updated_by": "CookieCat",
"admins": [
{
"id": 1,
"name": "CookieCat",
"active": true
}
],
"repos": [
{
"id": 1,
"name": "github/repo1"
}
]
},
"repos": [
{
"org": "github",
"name": "repo1",
"counter": 1,
"active": true,
"builds": [
{
"number": 1,
"started": 1726757097,
"sender": "CookieCat",
"ref": "refs/heads/main",
"status": "running",
"event": "push",
"branch": "master",
"link": "http://vela.example.com/github/repo1/1"
}
]
}
]
},
{
"dashboard": {
"id": "c4e8f563-4784-4b4b-9534-3007d579dc2a",
"name": "another demo dashboard",
"created_at": 1726757636,
"created_by": "CookieCat",
"updated_at": 1726757636,
"updated_by": "CookieCat",
"admins": [
{
"id": 1,
"name": "CookieCat",
"active": true
}
],
"repos": []
}
}
]
54 changes: 54 additions & 0 deletions cypress/integration/dashboards.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,60 @@
*/

context('Dashboards', () => {
context('main dashboards page shows message', () => {
beforeEach(() => {
cy.server();
cy.route(
'GET',
'*api/v1/user/dashboards',
'fixture:user_dashboards.json',
);
cy.login('/dashboards');
});

it('shows the welcome message', () => {
cy.get('[data-test=dashboards]').contains('Dashboards');
});

it('shows the list of dashboards', () => {
cy.get('[data-test=dashboard-item]').should('have.length', 2);
});

it('shows the repos within a dashboard', () => {
cy.get('[data-test=dashboard-repos]').first().contains('github/repo1');
});

it('shows a message when there are no repos', () => {
cy.get('[data-test=dashboard-repos]')
.eq(1)
.contains('No repositories in this dashboard');
});

it('clicking dashoard name navigates to dashboard page', () => {
cy.get('[data-test=dashboard-item]')
.first()
.within(() => {
cy.get('a').first().click();
cy.location('pathname').should(
'eq',
'/dashboards/6e26a6d0-2fc3-4531-a04d-678a58135288',
);
});
});
});

context('main dashboards page shows message', () => {
beforeEach(() => {
cy.server();
cy.route(
'GET',
'*api/v1/user/dashboards',
'fixture:user_dashboards.json',
);
cy.login('/dashboards');
});
});

context('server returns dashboard with 3 cards, one without builds', () => {
beforeEach(() => {
cy.server();
Expand Down
51 changes: 28 additions & 23 deletions src/elm/Pages/Dashboards.elm
Original file line number Diff line number Diff line change
Expand Up @@ -244,40 +244,45 @@ viewDashboards dashboards =
Route.Path.Dashboards_Dashboard_ { dashboard = dashboard.dashboard.id }
|> Route.Path.href
in
div [ class "item" ]
div [ class "item", Util.testAttribute "dashboard-item" ]
[ span [ class "dashboard-item-title" ]
[ a [ dashboardLink ] [ text dashboard.dashboard.name ]
, code [] [ text dashboard.dashboard.id ]
]
, div [ class "buttons" ]
[ a [ class "button", dashboardLink ] [ text "View" ]
]
, viewDashboardRepos dashboard.repos
, viewDashboardRepos dashboard.repos dashboard.dashboard.id
]
)


{-| viewDashboardRepos : renders a list of repos belonging to a dashboard.
-}
viewDashboardRepos : List Vela.DashboardRepoCard -> Html Msg
viewDashboardRepos repos =
div [ class "dashboard-repos" ]
(repos
|> List.map
(\repo ->
let
statusIcon =
case List.head repo.builds of
Just build ->
Components.Svgs.recentBuildStatusToIcon build.status 0

Nothing ->
Components.Svgs.recentBuildStatusToIcon Vela.Pending 0
in
div
[ class "dashboard-repos-item" ]
[ statusIcon
, text (repo.org ++ "/" ++ repo.name ++ " (" ++ String.fromInt (List.length repo.builds) ++ ")")
]
)
viewDashboardRepos : List Vela.DashboardRepoCard -> String -> Html Msg
viewDashboardRepos repos dashboardId =
div [ class "dashboard-repos", Util.testAttribute "dashboard-repos" ]
(if List.length repos > 0 then
repos
|> List.map
(\repo ->
let
statusIcon =
case List.head repo.builds of
Just build ->
Components.Svgs.recentBuildStatusToIcon build.status 0

Nothing ->
Components.Svgs.recentBuildStatusToIcon Vela.Pending 0
in
div
[ class "dashboard-repos-item" ]
[ statusIcon
, text (repo.org ++ "/" ++ repo.name ++ " (" ++ String.fromInt (List.length repo.builds) ++ ")")
]
)

else
[ text <| "⚠️ No repositories in this dashboard. Use the CLI to add some: vela update dashboard --id "
++ dashboardId ++ " --add-repos org/repo" ]
)

0 comments on commit e334fe3

Please sign in to comment.