Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1031 from uclapi/shu8/start-of-year-fixes
Browse files Browse the repository at this point in the history
Fix crash on first login & scrollToIndex crash
  • Loading branch information
shu8 committed Jan 7, 2022
2 parents 1951067 + d3c7c04 commit ff7aff5
Show file tree
Hide file tree
Showing 8 changed files with 43,675 additions and 51 deletions.
43,158 changes: 43,114 additions & 44 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion redux/actions/userActions.ts
Expand Up @@ -59,7 +59,7 @@ export const signIn = (): UserThunkAction => async (
dispatch: UserDispatch,
): Promise<void> => {
dispatch(isSigningIn())
const returnUrl = `${AuthSession.makeRedirectUri()}${Platform.OS === `ios` ? `/` : ``}redirect`
const returnUrl = AuthSession.makeRedirectUri()
const result = await AuthSession.startAsync({
authUrl: `${ASSISTANT_API_URL}/connect/uclapi?return=${encodeURIComponent(
returnUrl,
Expand Down
Expand Up @@ -65,4 +65,9 @@ describe(`TimetableDetailScreen`, () => {
wrapper = await render(<TimetableDetailScreen {...mockProps} />)
expect(wrapper).toMatchSnapshot()
})

it(`renders the TimetableDetailScreen with no entries`, async () => {
wrapper = await render(<TimetableDetailScreen {...mockProps} timetable={[]} />)
expect(wrapper).toMatchSnapshot()
})
})
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TimetableDetailScreen renders the TimetableDetailScreen 1`] = `"{\\"initialRegion\\":{\\"latitude\\":51.5246586,\\"latitudeDelta\\":0.0012,\\"longitude\\":-0.1339784,\\"longitudeDelta\\":0.0071},\\"date\\":\\"2020-01-01\\",\\"contact\\":\\"Anne Oldman\\",\\"end_time\\":\\"00:01\\",\\"location\\":{\\"address\\":[\\"221C Banana Bread Street\\"],\\"name\\":\\"Waffle House\\"},\\"module\\":{\\"department_name\\":\\"Criminology\\",\\"lecturer\\":{\\"department_id\\":\\"CRIM\\",\\"name\\":\\"Jack Cloth\\"},\\"module_id\\":\\"ABC123\\"},\\"start_time\\":\\"00:00\\",\\"navigation\\":{}}"`;

exports[`TimetableDetailScreen renders the TimetableDetailScreen with no entries 1`] = `"{\\"initialRegion\\":{\\"latitude\\":51.5246586,\\"latitudeDelta\\":0.0012,\\"longitude\\":-0.1339784,\\"longitudeDelta\\":0.0071},\\"date\\":\\"2020-01-01\\",\\"navigation\\":{}}"`;
11 changes: 7 additions & 4 deletions screens/Timetable/TimetableScreen/TimetableScreen.tsx
Expand Up @@ -157,12 +157,15 @@ class TimetableScreen extends React.Component<Props, State> {
onSwipe = ({ nativeEvent: { position: index } }) => {
const { fetchTimetable, user: { token }, timetable = [] } = this.props

if (timetable[index] === null) {
if (timetable[index] === null || index > timetable.length - 1) {
// assumes closest valid index can always be found earlier, not later
const closestValidIndex = timetable.findIndex((w) => w !== null)
const newDate = LocalisationManager.parseToMoment(
timetable[closestValidIndex][0].dateISO,
).add(index - closestValidIndex, `weeks`)

const newDate = closestValidIndex === -1
? LocalisationManager.getMoment()
: LocalisationManager.parseToMoment(
timetable[closestValidIndex][0].dateISO,
).add(index - closestValidIndex, `weeks`)

this.setState({ date: newDate })
return fetchTimetable(token, newDate)
Expand Down
54 changes: 54 additions & 0 deletions screens/Timetable/TimetableScreen/__tests__/WeekView.test.tsx
@@ -0,0 +1,54 @@
/**
* @jest-environment jsdom
*/
import { cleanup, render } from "@testing-library/react-native"
import MockDate from 'mockdate'
import React from 'react'
import "react-native"
import { LocalisationManager } from "../../../../lib"
import WeekView from "../components/WeekView"

describe(`WeekView`, () => {
MockDate.set(`2019-11-18T08:47:21.000Z`)

afterEach(() => {
cleanup()
})

it(`renders the WeekView component`, () => {
const mockProps = {
date: LocalisationManager.getMoment().subtract(7, `days`),
isLoading: false,
navigation: {
dispatch: jest.fn(),
navigate: jest.fn(),
} as any,
onDateChanged: () => null,
onIndexChanged: () => null,
onRefresh: () => null,
timetable: [
{
contact: `Anne Oldman`,
end_time: `00:01`,
location: {
address: [
`221C Banana Bread Street`,
],
name: `Waffle House`,
},
module: {
department_name: `Criminology`,
lecturer: {
department_id: `CRIM`,
name: `Jack Cloth`,
},
module_id: `ABC123`,
},
start_time: `00:00`,
},
],
}
const wrapper = render(<WeekView {...mockProps} />)
expect(wrapper).toMatchSnapshot()
})
})

0 comments on commit ff7aff5

Please sign in to comment.