Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock Assessment API calls #113

Merged
merged 30 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
54b8ffe
Add /missions result
remo5000 Jun 18, 2018
d945ea1
Add closed and all missions
remo5000 Jun 18, 2018
f21e6ee
Add mock questions
remo5000 Jun 18, 2018
c3b731e
Make assessment folder
remo5000 Jun 18, 2018
91c9b8e
Add types and interfaces for assessment api calls
remo5000 Jun 18, 2018
172fb7d
Match mock data to updated fields
remo5000 Jun 18, 2018
25fbe93
Make Questions use inheritence
remo5000 Jun 18, 2018
51bbfe3
Use IAssessment in Assessment component
remo5000 Jun 19, 2018
e136c98
Change dispatch name in component
remo5000 Jun 19, 2018
67c5896
Use proper variable names in AssessmentContainer
remo5000 Jun 19, 2018
0995a31
Change state to use IAssessment
remo5000 Jun 19, 2018
fc8f9d4
Use IAssessmentOverview in academy/missions
remo5000 Jun 19, 2018
3c01610
Use IAssessmentOverview for Missions
remo5000 Jun 19, 2018
8fcce49
Fix mission tests
remo5000 Jun 19, 2018
a10ac0f
Use assessment-related names in MissionsContainer
remo5000 Jun 19, 2018
f3080de
Modify state to use IAssessmentOverview
remo5000 Jun 19, 2018
21cf1d7
Modify mission info fetch action to assessment
remo5000 Jun 19, 2018
402787d
Fix linting and tests
remo5000 Jun 19, 2018
534e56d
Fix filtering issue for missions
remo5000 Jun 19, 2018
c5a10c1
Use enum category values
remo5000 Jun 19, 2018
388ff58
Arrange fields in alphabetical order
remo5000 Jun 19, 2018
41b60d8
Format mockAPI
remo5000 Jun 19, 2018
651a7d1
Make fetchAssessmentOverviews general
remo5000 Jun 19, 2018
3874ffd
Add saga for assessment overview fetching
remo5000 Jun 19, 2018
4a5fa48
Add mock API fetch for assessment overviews
remo5000 Jun 19, 2018
9569116
Format some files
remo5000 Jun 19, 2018
66807b6
Add API call for fetching assessment
remo5000 Jun 19, 2018
637d534
Format and update test files
remo5000 Jun 19, 2018
28b5452
Add historyHelper to state
remo5000 Jun 20, 2018
167b38c
Use typed Map instead of Object for IAssessments
remo5000 Jun 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/actions/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export const INTERRUPT_EXECUTION = 'INTERRUPT_EXECUTION'
export const CHANGE_TOKEN = 'CHANGE_TOKEN'
export const FETCH_ANNOUNCEMENTS = 'FETCH_ANNOUNCEMENTS'
export const FETCH_ASSESSMENT = 'FETCH_ASSESSMENT'
export const FETCH_MISSIONS_INFO = 'FETCH_MISSIONS_INFO'
export const FETCH_ASSESSMENT_OVERVIEWS = 'FETCH_ASSESSMENT_OVERVIEWS'
export const FETCH_USERNAME = 'FETCH_USERNAME'
export const LOGIN = 'LOGIN'
export const SET_USERNAME = 'SET_USERNAME'
export const UPDATE_HISTORY_HELPERS = 'UPDATE_HISTORY_HELPERS'
export const UPDATE_ASSESSMENT_OVERVIEWS = 'UPDATE_ASSESSMENT_OVERVIEWS'
export const UPDATE_ASSESSMENT = 'UPDATE_ASSESSMENT'
20 changes: 16 additions & 4 deletions src/actions/session.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ActionCreator } from 'redux'

import { IAssessment, IAssessmentOverview } from '../components/assessment/assessmentShape'
import * as actionTypes from './actionTypes'

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

export const fetchAssessment = (missionId: number) => ({
export const fetchAssessment = (id: number) => ({
type: actionTypes.FETCH_ASSESSMENT,
payload: missionId
payload: id
})

export const fetchMissionsInfo = () => ({
type: actionTypes.FETCH_MISSIONS_INFO
export const fetchAssessmentOverviews = () => ({
type: actionTypes.FETCH_ASSESSMENT_OVERVIEWS
})

export const fetchUsername = () => ({
Expand All @@ -36,3 +38,13 @@ export const updateHistoryHelpers: ActionCreator<actionTypes.IAction> = (loc: st
type: actionTypes.UPDATE_HISTORY_HELPERS,
payload: loc
})

export const updateAssessmentOverviews = (overviews: IAssessmentOverview[]) => ({
type: actionTypes.UPDATE_ASSESSMENT_OVERVIEWS,
payload: overviews
})

export const updateAssessment = (assessment: IAssessment) => ({
type: actionTypes.UPDATE_ASSESSMENT,
payload: assessment
})
39 changes: 17 additions & 22 deletions src/components/academy/Missions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@ import { RouteComponentProps } from 'react-router'
import { NavLink } from 'react-router-dom'

import AssessmentContainer from '../../containers/AssessmentContainer'
import { OwnProps as AssessmentProps } from '../Assessment'
import { OwnProps as AssessmentProps } from '../assessment'
import { IAssessmentOverview } from '../assessment/assessmentShape'
import ContentDisplay, { IContentDisplayProps } from '../commons/ContentDisplay'

export type MissionInfo = {
id: number
title: string
description: string
}

export interface IMissionParams {
missionId?: string
}

export interface IMissionsProps extends RouteComponentProps<IMissionParams> {
missionsInfo?: MissionInfo[]
handleMissionsInfoFetch: () => void
assessmentOverviews?: IAssessmentOverview[]
handleAssessmentOverviewFetch: () => void
}

export type StateProps = Pick<IMissionsProps, 'missionsInfo'>
export type DispatchProps = Pick<IMissionsProps, 'handleMissionsInfoFetch'>
export type StateProps = Pick<IMissionsProps, 'assessmentOverviews'>
export type DispatchProps = Pick<IMissionsProps, 'handleAssessmentOverviewFetch'>

class Missions extends React.Component<IMissionsProps, {}> {
public render() {
Expand All @@ -39,8 +34,8 @@ class Missions extends React.Component<IMissionsProps, {}> {
// if there is no mission specified, Render only information.
if (missionIdParam === null) {
const props: IContentDisplayProps = {
display: <MissionInfoCard missionsInfo={this.props.missionsInfo} />,
loadContentDispatch: this.props.handleMissionsInfoFetch
display: <AssessmentOverviewCard assessmentOverviews={this.props.assessmentOverviews} />,
loadContentDispatch: this.props.handleAssessmentOverviewFetch
}
return (
<div className="Missions">
Expand All @@ -56,17 +51,17 @@ class Missions extends React.Component<IMissionsProps, {}> {
}
}

interface IMissionInfoCardProps {
missionsInfo?: MissionInfo[]
interface IAssessmentOverviewCardProps {
assessmentOverviews?: IAssessmentOverview[]
}

export const MissionInfoCard: React.SFC<IMissionInfoCardProps> = props => {
if (props.missionsInfo === undefined) {
return <NonIdealState description="Fetching missions..." visual={<Spinner />} />
} else if (props.missionsInfo.length === 0) {
return <NonIdealState title="There are no missions." visual={IconNames.FLAME} />
export const AssessmentOverviewCard: React.SFC<IAssessmentOverviewCardProps> = props => {
if (props.assessmentOverviews === undefined) {
return <NonIdealState description="Fetching assessment..." visual={<Spinner />} />
} else if (props.assessmentOverviews.length === 0) {
return <NonIdealState title="There are no assessments." visual={IconNames.FLAME} />
}
const cards = props.missionsInfo.map((mission, index) => (
const cards = props.assessmentOverviews.map((mission, index) => (
<div key={index}>
<Card className="row mission-info">
<div className="col-xs-3 mission-info-picture">PICTURE</div>
Expand All @@ -78,7 +73,7 @@ export const MissionInfoCard: React.SFC<IMissionInfoCardProps> = props => {
<h6>Mission 0 : 123123 XP (hardcoded)</h6>
</div>
<div className="row mission-info-description">
<p className="col-xs-12">{mission.description}</p>
<p className="col-xs-12">{mission.shortSummary}</p>
</div>
<div className="row between-xs middle-xs mission-info-controls">
<div className="col-xs-8 mission-info-due-date-parent">
Expand Down
24 changes: 6 additions & 18 deletions src/components/academy/__tests__/Missions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,25 @@ import { mount } from 'enzyme'
import * as React from 'react'
import { MemoryRouter } from 'react-router'

import { mockAssessmentOverviews } from '../../../mocks/api'
import { mockRouterProps } from '../../../mocks/components'
import Missions, { IMissionsProps } from '../Missions'

const mockUndefinedMissions: IMissionsProps = {
...mockRouterProps('/academy/missions', {}),
handleMissionsInfoFetch: () => {}
handleAssessmentOverviewFetch: () => {}
}

const mockEmptyMissions: IMissionsProps = {
...mockRouterProps('/academy/missions', {}),
missionsInfo: [],
handleMissionsInfoFetch: () => {}
assessmentOverviews: [],
handleAssessmentOverviewFetch: () => {}
}

const mockPresentMissions: IMissionsProps = {
...mockRouterProps('/academy/missions', {}),
missionsInfo: [
{
id: 0,
title: 'An Odessey to Runes',
description:
'Once upon a time, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nec vulputate sapien. Fusce vel lacus fermentum, efficitur ipsum in'
},
{
id: 1,
title: 'The Secret to Streams',
description:
'Once upon a time, () => { Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nec vulputate sapien. Fusce vel lacus fermentum, efficitur ipsum in }'
}
],
handleMissionsInfoFetch: () => {}
assessmentOverviews: mockAssessmentOverviews,
handleAssessmentOverviewFetch: () => {}
}

test('Missions page "loading" content renders correctly', () => {
Expand Down
Loading