diff --git a/components/Dashboard/Card.js b/components/Dashboard/Card.js index 0c4bf06..183b115 100644 --- a/components/Dashboard/Card.js +++ b/components/Dashboard/Card.js @@ -25,18 +25,25 @@ const useStyles = makeStyles((theme) => ({ }, })); -function Card({ bridge }) { +function Card({ bridge, index }) { const classes = useStyles(); + const completedAt = (bridge.completedAt + && new Date(bridge.completedAt).toDateString()) + || 'No requests'; + + const updatedAt = new Date(bridge.updatedAt).toDateString(); + return ( - + {bridge.title} @@ -59,12 +66,17 @@ function Card({ bridge }) { - {bridge.lastRequest || 'No requests'} - - {(new Date(bridge.updatedAt)).toUTCString().split(' ').slice(1, 4) - .join(' ')} + + {completedAt} + + + + {updatedAt} + + + + {bridge.eventCount || '0'} - {bridge.requests || '0'} @@ -93,7 +105,8 @@ Card.propTypes = { id: PropTypes.number.isRequired, title: PropTypes.string.isRequired, updatedAt: PropTypes.string.isRequired, - lastRequest: PropTypes.string, - requests: PropTypes.string, + eventCount: PropTypes.number.isRequired, + completedAt: PropTypes.string, }).isRequired, + index: PropTypes.number.isRequired, }; diff --git a/components/Sidebar/ListItem.js b/components/Sidebar/ListItem.js index 70243f6..00e8625 100644 --- a/components/Sidebar/ListItem.js +++ b/components/Sidebar/ListItem.js @@ -6,8 +6,10 @@ import { import PropTypes from 'prop-types'; function ListItem({ - date, statusCode, timestamp, completed, + completedAt, statusCode, completed, }) { + const timestamp = new Date(completedAt).toDateString(); + return ( @@ -16,7 +18,7 @@ function ListItem({ noWrap align="center" > - {completed ? `${timestamp} - ${date} ${statusCode}` : 'Ongoing' } + {completed ? `${timestamp} - ${statusCode}` : 'Ongoing' } @@ -26,8 +28,7 @@ function ListItem({ export default ListItem; ListItem.propTypes = { - date: PropTypes.string.isRequired, statusCode: PropTypes.number.isRequired, - timestamp: PropTypes.string.isRequired, + completedAt: PropTypes.string.isRequired, completed: PropTypes.bool.isRequired, }; diff --git a/components/Sidebar/index.js b/components/Sidebar/index.js index 9d3c2e2..2bcb1a9 100644 --- a/components/Sidebar/index.js +++ b/components/Sidebar/index.js @@ -36,6 +36,7 @@ const useStyles = makeStyles(() => ({ function Sidebar({ events, title }) { const classes = useStyles(); + return (
{title || 'Untitled'} - {events.slice().reverse().map((evt) => { - const { date, statusCode, time } = evt.responses.slice(-1)[0].headers; - return ( - - ); - })} + {events.map((event) => ( + + ))}
diff --git a/pages/dashboard.js b/pages/dashboard.js index 3ad3e53..5f240a6 100644 --- a/pages/dashboard.js +++ b/pages/dashboard.js @@ -29,11 +29,11 @@ function Dashboard({ bridges }) {
- - + + {bridges && bridges.length > 0 - ? (bridges.map((bridge) => )) + ? (bridges.map((bridge, idx) => )) : ( + +describe('Sign Up', () => { + beforeEach(() => { + cy.clearCookies(); + }); + + afterEach(() => { + cy.clearCookies(); + }); + + it('redirects to login with bad token', () => { + cy.setBadToken(); + cy.visit('/dashboard'); + + cy.location().should((location) => { + expect(location.pathname).to.eq('/users/login'); + }); + }); + + it('has 3 bridges displayed', () => { + cy.setToken(); + cy.visit('/dashboard'); + + cy.get('#dashboard-card-container') + .children().should('have.length', 3); + + cy.get('#card-title-0') + .contains('title_0').should('be.visible'); + cy.get('#card-title-0') + .parent().should('have.attr', 'href').and('eq', '/bridge/7'); + cy.get('#card-completedAt-0') + .contains('Wed Nov 25 2020').should('be.visible'); + cy.get('#card-updateAt-0') + .contains('Wed Nov 25 2020').should('be.visible'); + cy.get('#card-eventCount-0') + .contains('1').should('be.visible'); + + cy.get('#card-title-1') + .contains('title_1').should('be.visible'); + cy.get('#card-title-1') + .parent().should('have.attr', 'href').and('eq', '/bridge/4'); + cy.get('#card-completedAt-1') + .contains('No requests').should('be.visible'); + cy.get('#card-updateAt-1') + .contains('Thu Nov 26 2020').should('be.visible'); + cy.get('#card-eventCount-1') + .contains('0').should('be.visible'); + + cy.get('#card-title-2') + .contains('title_2').should('be.visible'); + cy.get('#card-title-2') + .parent().should('have.attr', 'href').and('eq', '/bridge/5'); + cy.get('#card-completedAt-2') + .contains('No requests').should('be.visible'); + cy.get('#card-updateAt-2') + .contains('Thu Nov 26 2020').should('be.visible'); + cy.get('#card-eventCount-2') + .contains('0').should('be.visible'); + }); +}); diff --git a/specs/support/mocks/handlers.js b/specs/support/mocks/handlers.js index 1a1e8c2..b77b858 100644 --- a/specs/support/mocks/handlers.js +++ b/specs/support/mocks/handlers.js @@ -1,6 +1,8 @@ // eslint-disable-next-line import/no-extraneous-dependencies import { rest } from 'msw'; +const bridges = require('../../fixtures/bridges.json'); + // msw doesn't give us a way to stub requests on a per spec basis. Because // of this, we need to make our own way. Use `cy.setToken` to create a // token that will be valid. Use `cy.setBadToken` to create an invalid token. @@ -20,11 +22,7 @@ const handlers = [ ); } - return res( - ctx.json( - { bridges: [] }, - ), - ); + return res(ctx.json(bridges)); }), ];