Skip to content

Commit b388c03

Browse files
remo5000ning-y
authored andcommitted
Add mock Assessment API calls (#113)
Resolves #74 * Add /missions result * Add closed and all missions Also added a counter for all the ids * Add mock questions * Make assessment folder * Add types and interfaces for assessment api calls * Match mock data to updated fields - Only closed assessment previews available (2 of them) - 3 open assessment previews - Changed dates to string * Make Questions use inheritence The union of interfaces seems to work. * Use IAssessment in Assessment component * Change dispatch name in component * Use proper variable names in AssessmentContainer * Change state to use IAssessment Also: - Used `Array<T>` for definition in mock api - Formatted AssessmentContainer * Use IAssessmentOverview in academy/missions Also removed category-specific assessments * Use IAssessmentOverview for Missions Also added an enum for AssessmentCategory * Fix mission tests * Use assessment-related names in MissionsContainer * Modify state to use IAssessmentOverview * Modify mission info fetch action to assessment * Fix linting and tests * Fix filtering issue for missions The problem was with a faulty dataset.Also added - Fix for not showing "loading" page (which was a mistake I made a few commits ago) - Spacing out for contentdisplay cards * Use enum category values * Arrange fields in alphabetical order * Format mockAPI * Make fetchAssessmentOverviews general This is because the API fetch is to fetch all the previews. Having the parameter for category there, but not using it (or using it, resulting in multiple calls for multiple categories) is not preferred. * Add saga for assessment overview fetching Note that the initial data is still not removed. * Add mock API fetch for assessment overviews The default value for the overviews is now undefined so as to simulate the fetching. * Format some files * Add API call for fetching assessment Moved the fetch dispact in the academy/mission component from the render function to the componentWillMount function, as we should not render (due to content updates) while the render function is running. * Format and update test files * Add historyHelper to state It got lost somewhere in the rebase * Use typed Map instead of Object for IAssessments
1 parent 01fc982 commit b388c03

File tree

14 files changed

+570
-113
lines changed

14 files changed

+570
-113
lines changed

src/actions/actionTypes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export const INTERRUPT_EXECUTION = 'INTERRUPT_EXECUTION'
3434
export const CHANGE_TOKEN = 'CHANGE_TOKEN'
3535
export const FETCH_ANNOUNCEMENTS = 'FETCH_ANNOUNCEMENTS'
3636
export const FETCH_ASSESSMENT = 'FETCH_ASSESSMENT'
37-
export const FETCH_MISSIONS_INFO = 'FETCH_MISSIONS_INFO'
37+
export const FETCH_ASSESSMENT_OVERVIEWS = 'FETCH_ASSESSMENT_OVERVIEWS'
3838
export const FETCH_USERNAME = 'FETCH_USERNAME'
3939
export const LOGIN = 'LOGIN'
4040
export const SET_USERNAME = 'SET_USERNAME'
4141
export const UPDATE_HISTORY_HELPERS = 'UPDATE_HISTORY_HELPERS'
42+
export const UPDATE_ASSESSMENT_OVERVIEWS = 'UPDATE_ASSESSMENT_OVERVIEWS'
43+
export const UPDATE_ASSESSMENT = 'UPDATE_ASSESSMENT'

src/actions/session.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { ActionCreator } from 'redux'
2+
3+
import { IAssessment, IAssessmentOverview } from '../components/assessment/assessmentShape'
24
import * as actionTypes from './actionTypes'
35

46
export const changeToken: ActionCreator<actionTypes.IAction> = (token: string) => ({
@@ -10,13 +12,13 @@ export const fetchAnnouncements = () => ({
1012
type: actionTypes.FETCH_ANNOUNCEMENTS
1113
})
1214

13-
export const fetchAssessment = (missionId: number) => ({
15+
export const fetchAssessment = (id: number) => ({
1416
type: actionTypes.FETCH_ASSESSMENT,
15-
payload: missionId
17+
payload: id
1618
})
1719

18-
export const fetchMissionsInfo = () => ({
19-
type: actionTypes.FETCH_MISSIONS_INFO
20+
export const fetchAssessmentOverviews = () => ({
21+
type: actionTypes.FETCH_ASSESSMENT_OVERVIEWS
2022
})
2123

2224
export const fetchUsername = () => ({
@@ -36,3 +38,13 @@ export const updateHistoryHelpers: ActionCreator<actionTypes.IAction> = (loc: st
3638
type: actionTypes.UPDATE_HISTORY_HELPERS,
3739
payload: loc
3840
})
41+
42+
export const updateAssessmentOverviews = (overviews: IAssessmentOverview[]) => ({
43+
type: actionTypes.UPDATE_ASSESSMENT_OVERVIEWS,
44+
payload: overviews
45+
})
46+
47+
export const updateAssessment = (assessment: IAssessment) => ({
48+
type: actionTypes.UPDATE_ASSESSMENT,
49+
payload: assessment
50+
})

src/components/academy/Missions.tsx

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@ import { RouteComponentProps } from 'react-router'
55
import { NavLink } from 'react-router-dom'
66

77
import AssessmentContainer from '../../containers/AssessmentContainer'
8-
import { OwnProps as AssessmentProps } from '../Assessment'
8+
import { OwnProps as AssessmentProps } from '../assessment'
9+
import { IAssessmentOverview } from '../assessment/assessmentShape'
910
import ContentDisplay, { IContentDisplayProps } from '../commons/ContentDisplay'
1011

11-
export type MissionInfo = {
12-
id: number
13-
title: string
14-
description: string
15-
}
16-
1712
export interface IMissionParams {
1813
missionId?: string
1914
}
2015

2116
export interface IMissionsProps extends RouteComponentProps<IMissionParams> {
22-
missionsInfo?: MissionInfo[]
23-
handleMissionsInfoFetch: () => void
17+
assessmentOverviews?: IAssessmentOverview[]
18+
handleAssessmentOverviewFetch: () => void
2419
}
2520

26-
export type StateProps = Pick<IMissionsProps, 'missionsInfo'>
27-
export type DispatchProps = Pick<IMissionsProps, 'handleMissionsInfoFetch'>
21+
export type StateProps = Pick<IMissionsProps, 'assessmentOverviews'>
22+
export type DispatchProps = Pick<IMissionsProps, 'handleAssessmentOverviewFetch'>
2823

2924
class Missions extends React.Component<IMissionsProps, {}> {
3025
public render() {
@@ -39,8 +34,8 @@ class Missions extends React.Component<IMissionsProps, {}> {
3934
// if there is no mission specified, Render only information.
4035
if (missionIdParam === null) {
4136
const props: IContentDisplayProps = {
42-
display: <MissionInfoCard missionsInfo={this.props.missionsInfo} />,
43-
loadContentDispatch: this.props.handleMissionsInfoFetch
37+
display: <AssessmentOverviewCard assessmentOverviews={this.props.assessmentOverviews} />,
38+
loadContentDispatch: this.props.handleAssessmentOverviewFetch
4439
}
4540
return (
4641
<div className="Missions">
@@ -56,17 +51,17 @@ class Missions extends React.Component<IMissionsProps, {}> {
5651
}
5752
}
5853

59-
interface IMissionInfoCardProps {
60-
missionsInfo?: MissionInfo[]
54+
interface IAssessmentOverviewCardProps {
55+
assessmentOverviews?: IAssessmentOverview[]
6156
}
6257

63-
export const MissionInfoCard: React.SFC<IMissionInfoCardProps> = props => {
64-
if (props.missionsInfo === undefined) {
65-
return <NonIdealState description="Fetching missions..." visual={<Spinner />} />
66-
} else if (props.missionsInfo.length === 0) {
67-
return <NonIdealState title="There are no missions." visual={IconNames.FLAME} />
58+
export const AssessmentOverviewCard: React.SFC<IAssessmentOverviewCardProps> = props => {
59+
if (props.assessmentOverviews === undefined) {
60+
return <NonIdealState description="Fetching assessment..." visual={<Spinner />} />
61+
} else if (props.assessmentOverviews.length === 0) {
62+
return <NonIdealState title="There are no assessments." visual={IconNames.FLAME} />
6863
}
69-
const cards = props.missionsInfo.map((mission, index) => (
64+
const cards = props.assessmentOverviews.map((mission, index) => (
7065
<div key={index}>
7166
<Card className="row mission-info">
7267
<div className="col-xs-3 mission-info-picture">PICTURE</div>
@@ -78,7 +73,7 @@ export const MissionInfoCard: React.SFC<IMissionInfoCardProps> = props => {
7873
<h6>Mission 0 : 123123 XP (hardcoded)</h6>
7974
</div>
8075
<div className="row mission-info-description">
81-
<p className="col-xs-12">{mission.description}</p>
76+
<p className="col-xs-12">{mission.shortSummary}</p>
8277
</div>
8378
<div className="row between-xs middle-xs mission-info-controls">
8479
<div className="col-xs-8 mission-info-due-date-parent">

src/components/academy/__tests__/Missions.tsx

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,25 @@ import { mount } from 'enzyme'
22
import * as React from 'react'
33
import { MemoryRouter } from 'react-router'
44

5+
import { mockAssessmentOverviews } from '../../../mocks/api'
56
import { mockRouterProps } from '../../../mocks/components'
67
import Missions, { IMissionsProps } from '../Missions'
78

89
const mockUndefinedMissions: IMissionsProps = {
910
...mockRouterProps('/academy/missions', {}),
10-
handleMissionsInfoFetch: () => {}
11+
handleAssessmentOverviewFetch: () => {}
1112
}
1213

1314
const mockEmptyMissions: IMissionsProps = {
1415
...mockRouterProps('/academy/missions', {}),
15-
missionsInfo: [],
16-
handleMissionsInfoFetch: () => {}
16+
assessmentOverviews: [],
17+
handleAssessmentOverviewFetch: () => {}
1718
}
1819

1920
const mockPresentMissions: IMissionsProps = {
2021
...mockRouterProps('/academy/missions', {}),
21-
missionsInfo: [
22-
{
23-
id: 0,
24-
title: 'An Odessey to Runes',
25-
description:
26-
'Once upon a time, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nec vulputate sapien. Fusce vel lacus fermentum, efficitur ipsum in'
27-
},
28-
{
29-
id: 1,
30-
title: 'The Secret to Streams',
31-
description:
32-
'Once upon a time, () => { Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nec vulputate sapien. Fusce vel lacus fermentum, efficitur ipsum in }'
33-
}
34-
],
35-
handleMissionsInfoFetch: () => {}
22+
assessmentOverviews: mockAssessmentOverviews,
23+
handleAssessmentOverviewFetch: () => {}
3624
}
3725

3826
test('Missions page "loading" content renders correctly', () => {

0 commit comments

Comments
 (0)