Skip to content

Commit

Permalink
Merge pull request #2875 from HSLdevcom/DT-3111
Browse files Browse the repository at this point in the history
DT-3111: Pattern selector missing from stop page stops and disruptions tabs
  • Loading branch information
optionsome authored Jul 17, 2019
2 parents cd699ac + f2bcc6d commit 2999305
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
1 change: 0 additions & 1 deletion app/component/RoutePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ class RoutePage extends React.Component {
route={route}
onSelectChange={this.onPatternChange}
gtfsId={route.gtfsId}
activeTab={activeTab}
className={cx({ 'bp-large': breakpoint === 'large' })}
/>
)}
Expand Down
20 changes: 3 additions & 17 deletions app/component/RoutePatternSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class RoutePatternSelect extends Component {
route: PropTypes.object,
onSelectChange: PropTypes.func.isRequired,
serviceDay: PropTypes.string.isRequired,
activeTab: PropTypes.string.isRequired,
relay: PropTypes.object.isRequired,
gtfsId: PropTypes.string.isRequired,
};
Expand All @@ -49,15 +48,10 @@ class RoutePatternSelect extends Component {
};

getOptions = () => {
const { activeTab, gtfsId, params, route } = this.props;
const { gtfsId, params, route } = this.props;
const { router } = this.context;

const patterns =
activeTab === 'aikataulu'
? route.patterns
: route.patterns.filter(
p => Array.isArray(p.tripsForDate) && p.tripsForDate.length > 0,
);
const { patterns } = route;

if (patterns.length === 0) {
return null;
Expand Down Expand Up @@ -96,14 +90,7 @@ class RoutePatternSelect extends Component {
return this.state.loading === true ? (
<div className={cx('route-pattern-select', this.props.className)} />
) : (
<div
className={cx('route-pattern-select', this.props.className, {
hidden:
this.props.route.patterns.find(
o => o.tripsForDate && o.tripsForDate.length > 0,
) === undefined && this.props.activeTab !== 'aikataulu',
})}
>
<div className={cx('route-pattern-select', this.props.className)}>
{options && (options.length > 2 || options.length === 1) ? (
<React.Fragment>
<Icon img="icon-icon_arrow-dropdown" />
Expand Down Expand Up @@ -163,7 +150,6 @@ class RoutePatternSelect extends Component {
}

const defaultProps = {
activeTab: 'pysakit',
className: 'bp-large',
serviceDay: '20190306',
relay: {
Expand Down
10 changes: 5 additions & 5 deletions test/unit/component/RoutePatternSelect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('<RoutePatternSelect />', () => {
expect(wrapper.find('#select-route-pattern > option')).to.have.lengthOf(3);
});

it('should render a toggle element with divs if there are only 2 patterns with trips', () => {
it('should render a toggle element with divs if there are no patterns with trips', () => {
const props = {
activeTab: 'pysakit',
gtfsId: 'HSL:3002U',
Expand All @@ -51,13 +51,13 @@ describe('<RoutePatternSelect />', () => {
code: 'HSL:3002U:0:01',
headsign: 'Kauklahti',
stops: [{ name: 'Helsinki' }, { name: 'Kauklahti' }],
tripsForDate: [{}],
tripsForDate: [],
},
{
code: 'HSL:3002U:0:02',
headsign: 'Kirkkonummi',
stops: [{ name: 'Helsinki' }, { name: 'Kirkkonummi' }],
tripsForDate: [{}],
tripsForDate: [],
},
{
code: 'HSL:3002U:0:03',
Expand All @@ -71,8 +71,8 @@ describe('<RoutePatternSelect />', () => {
const wrapper = shallowWithIntl(<RoutePatternSelect {...props} />, {
context: { ...mockContext },
});
expect(wrapper.find('option')).to.have.lengthOf(0);
expect(wrapper.find('div.route-option-togglable')).to.have.lengthOf(1);
expect(wrapper.find('option')).to.have.lengthOf(3);
expect(wrapper.find('div.route-option-togglable')).to.have.lengthOf(0);
});

it('should redirect to the first existing pattern if there is no matching pattern available', () => {
Expand Down

0 comments on commit 2999305

Please sign in to comment.