diff --git a/tutor/specs/components/my-courses.spec.jsx b/tutor/specs/components/my-courses.spec.jsx index ef5ddd01ac..e7a5c84321 100644 --- a/tutor/specs/components/my-courses.spec.jsx +++ b/tutor/specs/components/my-courses.spec.jsx @@ -39,6 +39,18 @@ describe('My Courses Component', function() { expect.snapshot().toMatchSnapshot(); }); + it('re-fetches courses if the back button is used', () => { + currentCourses.fetch = jest.fn(() => Promise.resolve()); + + let wrapper = mount(); + expect(currentCourses.fetch).not.toHaveBeenCalled(); + wrapper.unmount(); + + wrapper = mount(); + expect(currentCourses.fetch).toHaveBeenCalled(); + wrapper.unmount(); + }); + it('renders the listing sorted', function() { const wrapper = mount(); for (let i = 0; i < MASTER_COURSES_LIST.length; i++) { diff --git a/tutor/specs/models/user.spec.ts b/tutor/specs/models/user.spec.ts index c57552aa44..fb9f36f904 100644 --- a/tutor/specs/models/user.spec.ts +++ b/tutor/specs/models/user.spec.ts @@ -30,7 +30,7 @@ describe('User Model', () => { expect(User.metrics.course_subjects).toEqual('testing'); expect(User.metrics.course_types).toEqual('real'); }) - + it('calculates audience tags', () => { bootstrapCoursesList(); expect(User.tourAudienceTags).toEqual(['teacher', 'teacher-not-previewed']); @@ -105,6 +105,11 @@ describe('User Model', () => { expect(JSON.parse(body)).toMatchObject({ some: 'data', }) + + // Some events do not contain data + fetchMock.mockResponseOnce(JSON.stringify({ ok: true })) + User.logEvent({ category: 'nodata', code: 'nodata' }) + expect(fetchMock.mock.calls[1][1]?.body).toBeUndefined() })) it('checks for names then splits', action(() => { diff --git a/tutor/src/components/my-courses/index.jsx b/tutor/src/components/my-courses/index.tsx similarity index 82% rename from tutor/src/components/my-courses/index.jsx rename to tutor/src/components/my-courses/index.tsx index 73ff5b6148..d1662bb992 100644 --- a/tutor/src/components/my-courses/index.jsx +++ b/tutor/src/components/my-courses/index.tsx @@ -9,16 +9,24 @@ import TourRegion from '../tours/region'; import PendingVerification from './pending-verification'; import NonAllowedTeacher from './non-allowed-teacher'; import { MyCoursesPast, MyCoursesCurrent } from './listings'; +import { RouteComponentProps } from 'react-router-dom' + +interface MyCoursesProps { + history?: RouteComponentProps['history'] +} @observer -export default -class MyCourses extends React.Component { - constructor(props) { +class MyCourses extends React.Component { + constructor(props: MyCoursesProps) { super(props); modelize(this); } - componentDidMount() { + async componentDidMount() { + const { history } = this.props; + if (history && history.action === 'POP') { + await currentCourses.fetch(); + } currentUser.logEvent({ category: 'onboarding', code: 'arrived_my_courses' }); } @@ -27,7 +35,7 @@ class MyCourses extends React.Component { } @computed get shouldRedirect() { - if (currentCourses.size !== 1){ + if (currentCourses.size !== 1) { return false; } return ( @@ -72,8 +80,10 @@ class MyCourses extends React.Component { className="my-courses" > - + ); } } + +export default MyCourses diff --git a/tutor/src/models/user.ts b/tutor/src/models/user.ts index 260665ca46..775b3cc1c2 100644 --- a/tutor/src/models/user.ts +++ b/tutor/src/models/user.ts @@ -13,7 +13,7 @@ import urlFor from '../api' export interface UserEventPayload { category: string code: string - data: any + data?: any }