Skip to content

Commit

Permalink
fix fetching after enroll (#3808)
Browse files Browse the repository at this point in the history
* make data optional as it's already skipped in some events
* add spec for re-fetch behavior
  • Loading branch information
jivey authored Oct 26, 2021
1 parent fb4e293 commit 9fd273b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
12 changes: 12 additions & 0 deletions tutor/specs/components/my-courses.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ describe('My Courses Component', function() {
expect.snapshot(<C><CourseListing /></C>).toMatchSnapshot();
});

it('re-fetches courses if the back button is used', () => {
currentCourses.fetch = jest.fn(() => Promise.resolve());

let wrapper = mount(<C><CourseListing /></C>);
expect(currentCourses.fetch).not.toHaveBeenCalled();
wrapper.unmount();

wrapper = mount(<C><CourseListing history={{ action: 'POP' }} /></C>);
expect(currentCourses.fetch).toHaveBeenCalled();
wrapper.unmount();
});

it('renders the listing sorted', function() {
const wrapper = mount(<C><CourseListing /></C>);
for (let i = 0; i < MASTER_COURSES_LIST.length; i++) {
Expand Down
7 changes: 6 additions & 1 deletion tutor/specs/models/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyCoursesProps> {
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' });
}

Expand All @@ -27,7 +35,7 @@ class MyCourses extends React.Component {
}

@computed get shouldRedirect() {
if (currentCourses.size !== 1){
if (currentCourses.size !== 1) {
return false;
}
return (
Expand Down Expand Up @@ -72,8 +80,10 @@ class MyCourses extends React.Component {
className="my-courses"
>
<MyCoursesCurrent />
<MyCoursesPast />
<MyCoursesPast />
</TourRegion>
);
}
}

export default MyCourses
2 changes: 1 addition & 1 deletion tutor/src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import urlFor from '../api'
export interface UserEventPayload {
category: string
code: string
data: any
data?: any
}


Expand Down

0 comments on commit 9fd273b

Please sign in to comment.