Skip to content
Snippets Groups Projects
Commit 47c6a051 authored by Albin Henriksson's avatar Albin Henriksson
Browse files

Fix tests

parent a884400c
No related branches found
No related tags found
1 merge request!97Resolve "Show components in active competition"
Pipeline #42624 passed with warnings
......@@ -2,10 +2,9 @@ import mockedAxios from 'axios'
import expect from 'expect' // You can use any testing library
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import { Slide } from '../interfaces/Slide'
import { Slide } from '../interfaces/ApiModels'
import {
getPresentationCompetition,
getPresentationTeams,
setCurrentSlide,
setCurrentSlideNext,
setCurrentSlidePrevious,
......@@ -26,16 +25,6 @@ it('dispatches no actions when failing to get competitions', async () => {
expect(console.log).toHaveBeenCalled()
})
it('dispatches no actions when failing to get teams', async () => {
console.log = jest.fn()
;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => {
return Promise.reject(new Error('getting teams failed'))
})
const store = mockStore({ competitions: { filterParams: [] } })
await getPresentationTeams('0')(store.dispatch)
expect(store.getActions()).toEqual([])
expect(console.log).toHaveBeenCalled()
})
it('dispatches correct actions when setting slide', () => {
const testSlide: Slide = { competition_id: 0, id: 5, order: 5, timer: 20, title: '' }
const expectedActions = [{ type: Types.SET_PRESENTATION_SLIDE, payload: testSlide }]
......
......@@ -74,10 +74,6 @@ const AdminView: React.FC = () => {
dispatch(getRoles())
dispatch(getTypes())
dispatch(getStatistics())
axios
.get('/api/competitions/1/codes')
.then((resp) => console.log(resp.data))
.catch(console.log)
}, [])
const menuAdminItems = [
......
import React from 'react'
import SlideDisplay from '../presentationEditor/components/SlideDisplay'
import PresentationComponent from './components/PresentationComponent'
import mockedAxios from 'axios'
const AudienceViewPage: React.FC = () => {
const res = {
data: {},
}
;(mockedAxios.get as jest.Mock).mockImplementation(() => {
return Promise.resolve(res)
})
return <SlideDisplay />
}
......
......@@ -36,7 +36,7 @@ it('renders judge view page', () => {
render(
<BrowserRouter>
<Provider store={store}>
<JudgeViewPage />
<JudgeViewPage code={''} competitionId={0} />
</Provider>
</BrowserRouter>
)
......
......@@ -103,12 +103,13 @@ const JudgeViewPage = ({ competitionId, code }: JudgeViewPageProps) => {
>
<div className={classes.toolbar} />
<List>
{teams.map((answer, index) => (
<div key={answer.name}>
<JudgeScoreDisplay teamIndex={index} />
<Divider />
</div>
))}
{teams &&
teams.map((answer, index) => (
<div key={answer.name}>
<JudgeScoreDisplay teamIndex={index} />
<Divider />
</div>
))}
</List>
</RightDrawer>
<div style={{ height: 64 }} />
......
......@@ -4,8 +4,15 @@ import { Provider } from 'react-redux'
import { BrowserRouter } from 'react-router-dom'
import store from '../../store'
import ParticipantViewPage from './ParticipantViewPage'
import mockedAxios from 'axios'
it('renders participant view page', () => {
const res = {
data: {},
}
;(mockedAxios.get as jest.Mock).mockImplementation(() => {
return Promise.resolve(res)
})
render(
<BrowserRouter>
<Provider store={store}>
......
......@@ -4,14 +4,18 @@ import { useHistory } from 'react-router-dom'
import SlideDisplay from '../presentationEditor/components/SlideDisplay'
import { ParticipantContainer } from './styled'
import { socketJoinPresentation, socket_connect } from '../../sockets'
import { useAppSelector } from '../../hooks'
const ParticipantViewPage: React.FC = () => {
const history = useHistory()
const code = useAppSelector((state) => state.presentation.code)
useEffect(() => {
//hides the url so people can't sneak peak
history.push('participant')
socket_connect()
socketJoinPresentation()
if (code && code !== '') {
socket_connect()
socketJoinPresentation()
}
}, [])
return (
<ParticipantContainer>
......
......@@ -211,9 +211,7 @@ const PresenterViewPage: React.FC = () => {
{/** TODO:
* Fix scoreboard
*/}
{teams.map((team) => (
<ListItem key={team.id}>{team.name} score: 20</ListItem>
))}
{teams && teams.map((team) => <ListItem key={team.id}>{team.name} score: 20</ListItem>)}
</List>
</Popover>
</PresenterContainer>
......
......@@ -12,9 +12,18 @@ it('renders view select page', async () => {
const res = {
data: {},
}
const compRes = {
data: {
id: 2,
slides: [{ id: 4 }],
},
}
;(mockedAxios.post as jest.Mock).mockImplementation(() => {
return Promise.resolve(res)
})
;(mockedAxios.get as jest.Mock).mockImplementation(() => {
return Promise.resolve(compRes)
})
render(
<BrowserRouter>
<Provider store={store}>
......
import Types from '../actions/types'
import { RichSlide } from '../interfaces/ApiRichModels'
import { Slide } from '../interfaces/Slide'
import { Slide } from '../interfaces/ApiModels'
import presentationReducer from './presentationReducer'
const initialState = {
......@@ -19,7 +19,6 @@ const initialState = {
timer: 0,
title: '',
},
teams: [],
code: '',
timer: {
enabled: false,
......@@ -41,7 +40,6 @@ it('should handle SET_PRESENTATION_COMPETITION', () => {
},
slides: [{ id: 20 }],
year: 1999,
teams: [],
}
expect(
presentationReducer(initialState, {
......@@ -51,32 +49,6 @@ it('should handle SET_PRESENTATION_COMPETITION', () => {
).toEqual({
competition: testCompetition,
slide: testCompetition.slides[0],
teams: initialState.teams,
code: initialState.code,
timer: initialState.timer,
})
})
it('should handle SET_PRESENTATION_TEAMS', () => {
const testTeams = [
{
name: 'testTeamName1',
id: 3,
},
{
name: 'testTeamName2',
id: 5,
},
]
expect(
presentationReducer(initialState, {
type: Types.SET_PRESENTATION_TEAMS,
payload: testTeams,
})
).toEqual({
competition: initialState.competition,
slide: initialState.slide,
teams: testTeams,
code: initialState.code,
timer: initialState.timer,
})
......@@ -100,7 +72,6 @@ it('should handle SET_PRESENTATION_SLIDE', () => {
).toEqual({
competition: initialState.competition,
slide: testSlide,
teams: initialState.teams,
code: initialState.code,
timer: initialState.timer,
})
......@@ -115,8 +86,8 @@ describe('should handle SET_PRESENTATION_SLIDE_PREVIOUS', () => {
{ competition_id: 0, order: 0 },
{ competition_id: 0, order: 1 },
] as RichSlide[],
teams: [],
},
teams: initialState.teams,
slide: { competition_id: 0, order: 1 } as Slide,
code: initialState.code,
timer: initialState.timer,
......@@ -128,7 +99,7 @@ describe('should handle SET_PRESENTATION_SLIDE_PREVIOUS', () => {
).toEqual({
competition: testPresentationState.competition,
slide: testPresentationState.competition.slides[0],
teams: testPresentationState.teams,
code: initialState.code,
timer: initialState.timer,
})
......@@ -141,8 +112,8 @@ describe('should handle SET_PRESENTATION_SLIDE_PREVIOUS', () => {
{ competition_id: 0, order: 0 },
{ competition_id: 0, order: 1 },
] as RichSlide[],
teams: [],
},
teams: initialState.teams,
slide: { competition_id: 0, order: 0 } as Slide,
code: initialState.code,
timer: initialState.timer,
......@@ -154,7 +125,6 @@ describe('should handle SET_PRESENTATION_SLIDE_PREVIOUS', () => {
).toEqual({
competition: testPresentationState.competition,
slide: testPresentationState.competition.slides[0],
teams: testPresentationState.teams,
code: initialState.code,
timer: initialState.timer,
})
......@@ -170,9 +140,11 @@ describe('should handle SET_PRESENTATION_SLIDE_NEXT', () => {
{ competition_id: 0, order: 0 },
{ competition_id: 0, order: 1 },
] as RichSlide[],
teams: [],
},
teams: initialState.teams,
slide: { competition_id: 0, order: 0 } as Slide,
code: initialState.code,
timer: initialState.timer,
}
expect(
presentationReducer(testPresentationState, {
......@@ -181,7 +153,8 @@ describe('should handle SET_PRESENTATION_SLIDE_NEXT', () => {
).toEqual({
competition: testPresentationState.competition,
slide: testPresentationState.competition.slides[1],
teams: testPresentationState.teams,
code: initialState.code,
timer: initialState.timer,
})
})
it('by not changing slide if there is no next one', () => {
......@@ -192,8 +165,8 @@ describe('should handle SET_PRESENTATION_SLIDE_NEXT', () => {
{ competition_id: 0, order: 0 },
{ competition_id: 0, order: 1 },
] as RichSlide[],
teams: [],
},
teams: initialState.teams,
slide: { competition_id: 0, order: 1 } as Slide,
}
expect(
......@@ -203,7 +176,6 @@ describe('should handle SET_PRESENTATION_SLIDE_NEXT', () => {
).toEqual({
competition: testPresentationState.competition,
slide: testPresentationState.competition.slides[1],
teams: testPresentationState.teams,
})
})
})
......@@ -38,32 +38,26 @@ export const socket_connect = () => {
export const socketStartPresentation = () => {
socket.emit('start_presentation', { competition_id: store.getState().presentation.competition.id })
console.log('START PRESENTATION')
}
export const socketJoinPresentation = () => {
socket.emit('join_presentation', { code: store.getState().presentation.code }) // TODO: Send code gotten from auth/login/<code> api call
console.log('JOIN PRESENTATION')
}
export const socketEndPresentation = () => {
socket.emit('end_presentation', { competition_id: store.getState().presentation.competition.id })
console.log('END PRESENTATION')
}
export const socketSetSlideNext = () => {
socketSetSlide(store.getState().presentation.slide.order + 1) // TODO: Check that this slide exists
console.log('NEXT SLIDE +1')
}
export const socketSetSlidePrev = () => {
socketSetSlide(store.getState().presentation.slide.order - 1) // TODO: Check that this slide exists
console.log('PREVIOUS SLIDE -1')
}
export const socketSetSlide = (slide_order: number) => {
if (slide_order < 0 || store.getState().presentation.competition.slides.length <= slide_order) {
console.log('CANT CHANGE TO NON EXISTENT SLIDE')
return
}
......@@ -74,7 +68,6 @@ export const socketSetSlide = (slide_order: number) => {
}
export const socketSetTimer = (timer: Timer) => {
console.log('SET TIMER')
socket.emit('set_timer', {
competition_id: store.getState().presentation.competition.id,
timer: timer,
......@@ -82,6 +75,5 @@ export const socketSetTimer = (timer: Timer) => {
}
export const socketStartTimer = () => {
console.log('START TIMER')
socketSetTimer({ enabled: true, value: store.getState().presentation.timer.value })
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment