-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from googleinterns/feed-trip-data-react
Serve All Trip Details to UI in React
- Loading branch information
Showing
5 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as firebase from 'firebase/app'; | ||
import 'firebase/firebase-firestore'; | ||
|
||
import { getDateRange } from './trip.js' | ||
|
||
test('getDateRange test', () => { | ||
// Dates used for both test and expected date strings. | ||
const startMonth = 12; | ||
const startDay = 17; | ||
const startYear = 1995; | ||
const endMonth = 5; | ||
const endDay = 24; | ||
const endYear = 1996; | ||
|
||
// Note that the months in JS dates are 0 indexed rather than 1 indexed so | ||
// they must be decremented by 1 in order for the month to be correct. | ||
const testStartDate = firebase.firestore.Timestamp.fromDate( | ||
new Date(startYear, startMonth - 1, startDay)); | ||
const testEndDate = firebase.firestore.Timestamp.fromDate( | ||
new Date(endYear, endMonth - 1, endDay)); | ||
const testTripObj = {start_date: testStartDate, end_date: testEndDate}; | ||
const testDateRange = getDateRange(testTripObj); | ||
|
||
const expectedDateRange = `${startMonth}/${startDay}/${startYear} - ` + | ||
`${endMonth}/${endDay}/${endYear}`; | ||
expect(testDateRange).toEqual(expectedDateRange); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
frontend/src/components/ViewTrips/view-activities-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
import Button from 'react-bootstrap/Button'; | ||
|
||
import { VIEW_ACTIVITIES } from '../../constants/routes.js'; | ||
|
||
/** | ||
* Component used for the ViewTrips page to redirect to the ViewActivities page. | ||
*/ | ||
const ViewActivitiesButton = (props) => { | ||
const history = useHistory(); | ||
|
||
function goToViewActivities() { | ||
history.push(`${VIEW_ACTIVITIES}/${props.tripId}`); | ||
} | ||
|
||
return ( | ||
<Button type='button' onClick={goToViewActivities} variant='primary'> | ||
View Activities! | ||
</Button> | ||
); | ||
} | ||
|
||
export default ViewActivitiesButton; |
22 changes: 22 additions & 0 deletions
22
frontend/src/components/ViewTrips/view-activities-button.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
|
||
import ViewActivitiesButton from './view-activities-button.js'; | ||
import { VIEW_ACTIVITIES } from '../../constants/routes.js'; | ||
|
||
// Mock the push function from react-router-dom's useHistory. | ||
const mockHistoryPush = jest.fn(); | ||
jest.mock('react-router-dom', () => ({ | ||
useHistory: () => ({ | ||
push: mockHistoryPush | ||
}) | ||
})); | ||
|
||
describe('SignInButton component', () => { | ||
test('Redirects to ViewActivities page on click', () => { | ||
const testTripId = 'abc123'; | ||
const { getByText } = render(<ViewActivitiesButton tripId={testTripId}/>); | ||
fireEvent.click(getByText('View Activities!')); | ||
expect(mockHistoryPush).toBeCalledWith(`${VIEW_ACTIVITIES}/${testTripId}`); | ||
}) | ||
}); |