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

Fix crash on first login & scrollToIndex crash #1031

Merged
merged 5 commits into from Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
})
})