Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
2,527 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,23 @@ | ||
// @flow | ||
import type { Venue, RawLesson, ModuleCode, DayText, LessonTime } from 'types/modules'; | ||
|
||
// Components within a venue availability class: | ||
export type VenueOccupiedState = 'vacant' | 'occupied'; | ||
export type Availability = { [LessonTime]: VenueOccupiedState } // E.g. { "1000": "vacant", "1030": "occupied", ... } | ||
|
||
// Raw lessons obtained from venue info API includes ModuleCode by default | ||
export type VenueLesson = RawLesson & { | ||
ModuleCode: ModuleCode, | ||
}; | ||
|
||
// A venue's availability info for one day | ||
// E.g. { "Day": "Monday", "Classes": [...], "Availability": {...} } | ||
export type DayAvailability = { | ||
Day: DayText, | ||
Classes: VenueLesson[], | ||
Availability: Availability, | ||
} | ||
|
||
// Describes venueInformation.json | ||
// E.g. { "LT16": [DayAvailability1, DayAvailability2, ...], "LT17": [...], ... } | ||
export type VenueInfo = { [Venue]: DayAvailability[] }; |
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
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
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,68 @@ | ||
// @flow | ||
import React, { PureComponent } from 'react'; | ||
import { flatten, noop } from 'lodash'; | ||
import { arrangeLessonsForWeek, colorLessonsByType } from 'utils/timetables'; | ||
import Timetable from 'views/timetable/Timetable'; | ||
|
||
import type { DayAvailability } from 'types/venues'; | ||
import type { Venue } from 'types/modules'; | ||
|
||
import styles from './VenueDetailRow.scss'; | ||
|
||
type Props = { | ||
name: Venue, | ||
availability: DayAvailability[], | ||
expanded: boolean, | ||
onClick: (Venue, string) => void, | ||
} | ||
|
||
export default class VenueDetailRow extends PureComponent<Props> { | ||
static defaultProps = { | ||
name: '', | ||
availability: [], | ||
expanded: false, | ||
onClick: noop, | ||
}; | ||
|
||
arrangedLessons() { | ||
if (!this.props.expanded) { | ||
return null; | ||
} | ||
|
||
const availability: DayAvailability[] = this.props.availability; | ||
// const lessons = flatMap(availability, a => a.Classes) // Not using flatMap as it results in a Flow error | ||
const lessons = flatten(availability.map(dayAvail => dayAvail.Classes)) | ||
.map(venueLesson => ({ ...venueLesson, ModuleTitle: '' })); | ||
const coloredLessons = colorLessonsByType(lessons); | ||
return arrangeLessonsForWeek(coloredLessons); | ||
} | ||
|
||
render() { | ||
const { name, onClick } = this.props; | ||
const lessons = this.arrangedLessons(); | ||
const venueHref = `/venues/${encodeURIComponent(name)}`; | ||
|
||
return ( | ||
<li className={styles.venueDetailRow}> | ||
<h4> | ||
<a | ||
href={venueHref} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
onClick(name, venueHref); | ||
}} | ||
>{name}</a> | ||
</h4> | ||
{lessons ? ( | ||
<div className={styles.venueTimetable}> | ||
<Timetable | ||
lessons={lessons} | ||
isVerticalOrientation={false} | ||
onModifyCell={noop} | ||
/> | ||
</div> | ||
) : null} | ||
</li> | ||
); | ||
} | ||
} |
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,20 @@ | ||
@import "~styles/utils/modules-entry.scss"; | ||
|
||
.venueDetailRow { | ||
margin-top: 1rem; | ||
border-top: 1px $gray-lighter solid; | ||
|
||
&:first-child { | ||
margin-top: 0.25rem; | ||
border-top: 0; | ||
} | ||
|
||
a { | ||
width: 100%; | ||
} | ||
} | ||
|
||
.venueTimetable { | ||
margin-bottom: 1rem; | ||
overflow: auto; | ||
} |
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 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import venueInfo from '__mocks__/venueInformation.json'; | ||
import VenueDetailRow from './VenueDetailRow'; | ||
|
||
const minProps = { | ||
name: 'CQT/SR0315', | ||
availability: venueInfo['CQT/SR0315'], | ||
}; | ||
|
||
describe('VenueDetailRow', () => { | ||
test('it displays an anchor tag when not expanded', () => { | ||
const wrapper = shallow(<VenueDetailRow {...minProps} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('it displays an anchor tag and a timetable when expanded', () => { | ||
const wrapper = shallow(<VenueDetailRow {...minProps} expanded />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
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,32 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { map } from 'lodash'; | ||
import VenueDetailRow from 'views/venues/VenueDetailRow'; | ||
|
||
import type { VenueInfo } from 'types/venues'; | ||
import type { Venue } from 'types/modules'; | ||
|
||
import styles from './VenueList.scss'; | ||
|
||
type Props = { | ||
venues: VenueInfo, | ||
expandedVenue: Venue, | ||
onSelect: (Venue, string) => void; // Called with venue name and venue URL (/venues/<venue>) | ||
}; | ||
|
||
export default function VenueList(props: Props) { | ||
const lowercaseExpandedVenue = props.expandedVenue.toLowerCase(); | ||
return ( | ||
<ul className={styles.venueList}> | ||
{map(props.venues, (availability, name) => ( | ||
<VenueDetailRow | ||
key={name} | ||
name={name} | ||
availability={availability} | ||
expanded={name.toLowerCase() === lowercaseExpandedVenue} | ||
onClick={props.onSelect} | ||
/> | ||
))} | ||
</ul> | ||
); | ||
} |
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,4 @@ | ||
.venueList { | ||
padding-left: 0; | ||
list-style-type: none; | ||
} |
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,52 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import venueInfo from '__mocks__/venueInformation.json'; | ||
import VenueList from './VenueList'; | ||
|
||
const minProps = { | ||
venues: venueInfo, | ||
expandedVenue: '', | ||
onSelect: () => {}, | ||
}; | ||
|
||
describe('VenueList', () => { | ||
test('it renders all venues as VenueDetailRows', () => { | ||
const wrapper = mount(<VenueList {...minProps} />); | ||
expect(wrapper.find('VenueDetailRow')).toHaveLength(Object.keys(venueInfo).length); | ||
}); | ||
|
||
test('it expands venues appropriately', () => { | ||
let wrapper; | ||
|
||
// Does not expand when there is no expandedVenue | ||
wrapper = mount(<VenueList {...minProps} />); | ||
expect(wrapper.find('VenueDetailRow').filterWhere(r => r.prop('expanded'))).toHaveLength(0); | ||
|
||
// Does not expand when no venue names match | ||
wrapper = mount(<VenueList {...minProps} expandedVenue="covfefe" />); | ||
expect(wrapper.find('VenueDetailRow').filterWhere(r => r.prop('expanded'))).toHaveLength(0); | ||
|
||
// Expands a valid venue | ||
wrapper = mount(<VenueList {...minProps} expandedVenue="LT17" />); | ||
expect(wrapper.find('VenueDetailRow').filterWhere(r => r.prop('expanded'))).toHaveLength(1); | ||
expect(wrapper.find('VenueDetailRow').filterWhere(r => r.prop('name') === 'LT17').first().prop('expanded')).toBe(true); | ||
|
||
// Does not expand partial match | ||
expect(wrapper.find('VenueDetailRow').filterWhere(r => r.prop('name') === 'LT170').first().prop('expanded')).toBe(false); | ||
|
||
// Venue name case insensitivity | ||
wrapper = mount(<VenueList {...minProps} expandedVenue="cqt/SR0622" />); | ||
expect(wrapper.find('VenueDetailRow').filterWhere(r => r.prop('expanded'))).toHaveLength(1); | ||
expect(wrapper.find('VenueDetailRow').filterWhere(r => r.prop('name') === 'CQT/SR0622').first().prop('expanded')).toBe(true); | ||
}); | ||
|
||
test('it calls onSelect when a row is clicked', () => { | ||
const mockOnSelect = jest.fn(); | ||
const wrapper = mount(<VenueList {...minProps} onSelect={mockOnSelect} />); | ||
const lt17Row = wrapper.find('VenueDetailRow').filterWhere(r => r.prop('name') === 'LT17').first(); | ||
lt17Row.find('a').simulate('click'); | ||
expect(mockOnSelect.mock.calls).toHaveLength(1); | ||
expect(mockOnSelect.mock.calls[0]).toEqual(['LT17', '/venues/LT17']); | ||
}); | ||
}); |
Oops, something went wrong.