Skip to content

Commit f8c7b4c

Browse files
committed
fix(challenge-listing): fix failing test
1 parent 5cd686e commit f8c7b4c

File tree

5 files changed

+48
-39
lines changed

5 files changed

+48
-39
lines changed

src/shared/components/challenge-listing/ChallengeCard/Status/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import LeaderboardAvatar from 'components/challenge-listing/LeaderboardAvatar';
66
import { config, Link } from 'topcoder-react-utils';
77
import { TABS as DETAIL_TABS } from 'actions/page/challenge-details';
88
import 'moment-duration-format';
9+
import { phaseEndDate } from 'utils/challenge-listing/helper';
910
import {
10-
getTimeLeft, phaseEndDate,
11+
getTimeLeft,
1112
} from 'utils/challenge-detail/helper';
1213

1314
import ChallengeProgressBar from '../../ChallengeProgressBar';

src/shared/components/challenge-listing/Tooltips/ProgressBarTooltip/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import _ from 'lodash';
1717
import React from 'react';
1818
import PT from 'prop-types';
1919
import Tooltip from 'components/Tooltip';
20+
import { phaseStartDate, phaseEndDate } from 'utils/challenge-listing/helper';
2021
import LoaderIcon from '../../../Loader/Loader';
21-
import { phaseStartDate, phaseEndDate } from '../../../../utils/challenge-detail/helper';
2222
import './style.scss';
2323

2424
const getDate = date => moment(date).format('MMM DD');

src/shared/utils/challenge-detail/helper.jsx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { challenge as challengeUtils } from 'topcoder-react-lib';
99
import { config } from 'topcoder-react-utils';
1010
import Prize from 'components/challenge-listing/ChallengeCard/Prize';
1111
import { BUCKETS, getBuckets } from 'utils/challenge-listing/buckets';
12+
import { phaseEndDate } from 'utils/challenge-listing/helper';
1213

1314
const Filter = challengeUtils.filter;
1415

@@ -32,36 +33,6 @@ export function getChallengeTypeAbbr(track, challengeTypes) {
3233
return null;
3334
}
3435

35-
/**
36-
* Returns phase's end date.
37-
* @param {Object} phase
38-
* @return {Date}
39-
*/
40-
export function phaseEndDate(phase) {
41-
// Case 1: phase is still open. take the `scheduledEndDate`
42-
// Case 2: phase is not open but `scheduledStartDate` is a future date.
43-
// This means phase is not yet started. So take the `scheduledEndDate`
44-
if (phase.isOpen || moment(phase.scheduledStartDate).isAfter()) {
45-
return new Date(phase.scheduledEndDate);
46-
}
47-
// for other cases, take the `actualEndDate` as phase is already closed
48-
return new Date(phase.actualEndDate);
49-
}
50-
51-
/**
52-
* Returns phase's start date.
53-
* @param {Object} phase
54-
* @return {Date}
55-
*/
56-
export function phaseStartDate(phase) {
57-
// Case 1: Phase is not yet started. take the `scheduledStartDate`
58-
if (phase.isOpen !== true && moment(phase.scheduledStartDate).isAfter()) {
59-
return new Date(phase.scheduledStartDate);
60-
}
61-
// For all other cases, take the `actualStartDate` as phase is already started
62-
return new Date(phase.actualStartDate);
63-
}
64-
6536
/**
6637
* Get end date
6738
* @param {Object} challenge challenge info
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import moment from 'moment';
2+
3+
/**
4+
* Returns phase's end date.
5+
* @param {Object} phase
6+
* @return {Date}
7+
*/
8+
export function phaseEndDate(phase) {
9+
// Case 1: phase is still open. take the `scheduledEndDate`
10+
// Case 2: phase is not open but `scheduledStartDate` is a future date.
11+
// This means phase is not yet started. So take the `scheduledEndDate`
12+
if (phase.isOpen || moment(phase.scheduledStartDate).isAfter()) {
13+
return new Date(phase.scheduledEndDate);
14+
}
15+
// for other cases, take the `actualEndDate` as phase is already closed
16+
return new Date(phase.actualEndDate);
17+
}
18+
19+
/**
20+
* Returns phase's start date.
21+
* @param {Object} phase
22+
* @return {Date}
23+
*/
24+
export function phaseStartDate(phase) {
25+
// Case 1: Phase is not yet started. take the `scheduledStartDate`
26+
if (phase.isOpen !== true && moment(phase.scheduledStartDate).isAfter()) {
27+
return new Date(phase.scheduledStartDate);
28+
}
29+
// For all other cases, take the `actualStartDate` as phase is already started
30+
return new Date(phase.actualStartDate);
31+
}

src/shared/utils/challenge-listing/sort.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import moment from 'moment';
66
import { find, sumBy } from 'lodash';
7-
import { phaseStartDate, phaseEndDate } from '../challenge-detail/helper';
7+
import { phaseStartDate, phaseEndDate } from './helper';
88

99
export const SORTS = {
1010
CURRENT_PHASE: 'current-phase',
@@ -27,15 +27,21 @@ export default {
2727
},
2828
[SORTS.MOST_RECENT]: {
2929
func: (a, b) => {
30-
const getRegistrationStartDate = (challenge) => {
31-
// extract the registration phase from `challenge.phases`,
30+
const getChallengeStartDate = (challenge) => {
31+
// extract the phases from `challenge.phases`,
3232
// as `challenge.registrationStartDate` returned from API is not reliable
3333
const registrationPhase = find(challenge.phases, p => p.name === 'Registration');
34-
return moment(phaseStartDate(registrationPhase));
34+
const submissionPhase = find(challenge.phases, p => p.name === 'Submission');
35+
// registration phase exists
36+
if (registrationPhase) {
37+
return moment(phaseStartDate(registrationPhase));
38+
}
39+
// registration phase doesnt exist, This is possibly a F2F or TSK. Take submission phase
40+
return moment(phaseStartDate(submissionPhase));
3541
};
36-
const aRegistrationStartDate = getRegistrationStartDate(a);
37-
const bRegistrationStartDate = getRegistrationStartDate(b);
38-
return bRegistrationStartDate.diff(aRegistrationStartDate);
42+
const aChallengeStartDate = getChallengeStartDate(a);
43+
const bChallengeStartDate = getChallengeStartDate(b);
44+
return bChallengeStartDate.diff(aChallengeStartDate);
3945
},
4046
name: 'Most recent',
4147
},

0 commit comments

Comments
 (0)