Skip to content

Commit

Permalink
feat(dashboard): render dashboard page and repo cards (#796)
Browse files Browse the repository at this point in the history
Co-authored-by: wass3rw3rk <[email protected]>
Co-authored-by: david may <[email protected]>
  • Loading branch information
3 people committed May 30, 2024
1 parent e2aa22c commit d0dd9e9
Show file tree
Hide file tree
Showing 25 changed files with 1,696 additions and 73 deletions.
149 changes: 149 additions & 0 deletions cypress/fixtures/dashboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"dashboard": {
"id": "86671eb5-a3ff-49e1-ad85-c3b2f648dcb2",
"name": "example",
"created_at": 1715749911,
"created_by": "CookieCat",
"updated_at": 1715749911,
"updated_by": "CookieCat",
"admins": [
{
"id": 1,
"name": "CookieCat",
"active": true
}
],
"repos": [
{
"id": 2,
"name": "github/repo1"
},
{
"id": 1,
"name": "github/repo2"
}
]
},
"repos": [
{
"org": "github",
"name": "repo1",
"counter": 25,
"active": true,
"builds": [
{
"number": 25,
"started": 1715965620,
"finished": 1715965674,
"sender": "github",
"status": "success",
"event": "push",
"branch": "main",
"link": "/github/repo1/25"
},
{
"number": 24,
"started": 1715965597,
"finished": 1715965620,
"sender": "github",
"status": "canceled",
"event": "push",
"branch": "main",
"link": "/github/repo1/24"
},
{
"number": 23,
"started": 1715964030,
"finished": 1715964083,
"sender": "github",
"status": "success",
"event": "push",
"branch": "main",
"link": "/github/repo1/23"
},
{
"number": 22,
"started": 1715963978,
"finished": 1715964028,
"sender": "github",
"status": "success",
"event": "push",
"branch": "main",
"link": "/github/repo1/22"
},
{
"number": 21,
"started": 1715919426,
"finished": 1715919479,
"sender": "github",
"status": "success",
"event": "push",
"branch": "main",
"link": "/github/repo1/21"
}
]
},
{
"org": "github",
"name": "repo2",
"active": true,
"builds": [
{
"number": 15,
"started": 1715965620,
"finished": 1715965674,
"sender": "github",
"status": "failure",
"event": "push",
"branch": "main",
"link": "/github/repo2/15"
},
{
"number": 14,
"started": 1715965597,
"finished": 1715965620,
"sender": "github",
"status": "canceled",
"event": "push",
"branch": "main",
"link": "/github/repo2/14"
},
{
"number": 13,
"started": 1715964030,
"finished": 1715964083,
"sender": "github",
"status": "success",
"event": "push",
"branch": "main",
"link": "/github/repo2/13"
},
{
"number": 12,
"started": 1715963978,
"finished": 1715964028,
"sender": "github",
"status": "success",
"event": "push",
"branch": "main",
"link": "/github/repo2/12"
},
{
"number": 11,
"started": 1715919426,
"finished": 1715919479,
"sender": "github",
"status": "success",
"event": "push",
"branch": "main",
"link": "/github/repo2/11"
}
]
},
{
"org": "github",
"name": "repo3",
"active": true
}
]
}
18 changes: 18 additions & 0 deletions cypress/fixtures/dashboard_no_repos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"dashboard": {
"id": "86671eb5-a3ff-49e1-ad85-c3b2f648dcb2",
"name": "example2",
"created_at": 1715749911,
"created_by": "CookieCat",
"updated_at": 1715749911,
"updated_by": "CookieCat",
"admins": [
{
"id": 1,
"name": "CookieCat",
"active": true
}
],
"repos": []
}
}
126 changes: 126 additions & 0 deletions cypress/integration/dashboards.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/

context('Dashboards', () => {
context('server returns dashboard with 3 cards, one without builds', () => {
beforeEach(() => {
cy.server();
cy.route(
'GET',
'*api/v1/dashboards/86671eb5-a3ff-49e1-ad85-c3b2f648dcb2',
'fixture:dashboard.json',
);
cy.login('/dashboards/86671eb5-a3ff-49e1-ad85-c3b2f648dcb2');
});

it('shows 3 dashboard cards', () => {
cy.get('[data-test=dashboard-card]').should('have.length', 3);
});

it('shows an empty state when there are no builds', () => {
cy.get('[data-test=dashboard-card]')
.last()
.contains('waiting for builds');
});

it('shows success build icon in header in the first card', () => {
cy.get('[data-test=dashboard-card]')
.first()
.within(() => {
cy.get('.-icon').should('have.class', '-success');
});
});

it('shows failure build icon in header in the first card', () => {
cy.get('[data-test=dashboard-card]')
.eq(1)
.within(() => {
cy.get('.-icon').should('have.class', '-failure');
});
});

it('org link in card header goes to org page', () => {
cy.get('[data-test=dashboard-card]')
.first()
.within(() => {
cy.get('.card-org').click();
cy.location('pathname').should('eq', '/github');
});
});

it('repo link in card header goes to repo page', () => {
cy.get('[data-test=dashboard-card]')
.first()
.within(() => {
cy.get('.card-repo').click();
cy.location('pathname').should('eq', '/github/repo1');
});
});

it('build link in card goes to build page', () => {
cy.get('[data-test=dashboard-card]')
.first()
.within(() => {
cy.get('.card-build-data li:first-child a').click();
cy.location('pathname').should('eq', '/github/repo1/25');
});
});

it('recent build link goes to respective build page', () => {
cy.get('[data-test=recent-build-link-25]').click();
cy.location('pathname').should('eq', '/github/repo1/25');
});
});

context('server returning dashboard without repos', () => {
beforeEach(() => {
cy.server();
cy.route(
'GET',
'*api/v1/dashboards/86671eb5-a3ff-49e1-ad85-c3b2f648dcb2',
'fixture:dashboard_no_repos.json',
);
cy.login('/dashboards/86671eb5-a3ff-49e1-ad85-c3b2f648dcb2');
});

it('shows message when there are no repositories added', () => {
cy.get('[data-test=dashboard]').contains(
`This dashboard doesn't have repositories added yet`,
);
});
});

context('dashboard not found', () => {
beforeEach(() => {
cy.server();
cy.route({
method: 'GET',
status: 404,
url: '*api/v1/dashboards/deadbeef',
response: {
error:
'unable to read dashboard deadbeef: ERROR: invalid input syntax for type uuid: "deadbeef" (SQLSTATE 22P02)',
},
});
cy.login('/dashboards/deadbeef');
});

it('shows a not found message', () => {
cy.get('[data-test=dashboard]').contains(
'Dashboard "deadbeef" not found. Please check the URL.',
);
});
});

context('main dashboards page shows message', () => {
beforeEach(() => {
cy.server();
cy.login('/dashboards');
});

it('shows the welcome message', () => {
cy.get('[data-test=dashboards]').contains('Welcome to dashboards!');
});
});
});
4 changes: 4 additions & 0 deletions src/elm/Api/Endpoint.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Endpoint
| Login
| Logout
| CurrentUser
| Dashboard String
| Deployment Vela.Org Vela.Repo (Maybe String)
| Deployments (Maybe Pagination.Page) (Maybe Pagination.PerPage) Vela.Org Vela.Repo
| Token
Expand Down Expand Up @@ -163,6 +164,9 @@ toUrl api endpoint =
Deployments maybePage maybePerPage org repo ->
url api [ "deployments", org, repo ] <| Pagination.toQueryParams maybePage maybePerPage

Dashboard dashboard ->
url api [ "dashboards", dashboard ] []

Workers maybePage maybePerPage ->
url api [ "workers" ] <| Pagination.toQueryParams maybePage maybePerPage

Expand Down
13 changes: 13 additions & 0 deletions src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Api.Operations exposing
, getBuildStepLog
, getBuildSteps
, getCurrentUser
, getDashboard
, getOrgBuilds
, getOrgRepos
, getOrgSecret
Expand Down Expand Up @@ -1251,3 +1252,15 @@ deleteSharedSecret baseUrl session options =
)
Json.Decode.string
|> withAuth session


{-| getDashboard : retrieve a dashboard.
-}
getDashboard : String -> Session -> { a | dashboardId : String } -> Request Vela.Dashboard
getDashboard baseUrl session options =
get baseUrl
(Api.Endpoint.Dashboard
options.dashboardId
)
Vela.decodeDashboard
|> withAuth session
Loading

0 comments on commit d0dd9e9

Please sign in to comment.