Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fetching after enroll #3808

Merged
merged 5 commits into from
Oct 26, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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