Skip to content

Commit

Permalink
MUWM-5349: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fanglinfang committed Jul 9, 2024
1 parent 0f7fb5f commit f9b17b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
28 changes: 16 additions & 12 deletions myuw_vue/components/academics/adviser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,18 @@ export default {
profile: (state) => state.profile.value,
}),
...mapGetters('advisers', {
isReadyAdvisers: 'isReady',
isFetchingAdvisers: 'isFetching',
isErroredAdvisers: 'isErrored',
statusCodeAdvisers: 'statusCode',
}),
...mapGetters('profile', {
isReadyProfile: 'isReady',
isFetchingProfile: 'isFetching',
isErroredProfile: 'isErrored',
statusCodeProfile: 'statusCode',
}),
shouldLoad() {
return !this.isPCE && (this.isUndergrad || this.studEmployee) && !this.isGrad;
},
termMajors() {
return this.profile.term_majors;
},
Expand All @@ -156,21 +159,16 @@ export default {
},
showError() {
return (
this.isErroredAdvisers &&
this.statusCodeAdvisers != 404 ||
this.isErroredProfile &&
this.statusCodeProfile != 404
this.isErroredAdvisers && this.statusCodeAdvisers != 404 ||
this.isErroredProfile && this.statusCodeProfile != 404
);
},
showCard() {
return !this.isPCE && (this.isUndergrad || this.studEmployee) && !this.isGrad;
},
hasAdviser() {
return this.isReadyAdvisers && this.advisers && this.advisers.length > 0;
return this.advisers && this.advisers.length > 0;
},
hasProfile() {
return (
this.isReadyProfile && this.profile &&
this.profile &&
this.profile.campus !== undefined &&
(this.profile.class_level === 'FRESHMAN' ||
this.profile.class_level === "SOPHOMORE" ||
Expand All @@ -180,10 +178,16 @@ export default {
},
showContent() {
return this.hasAdviser || this.hasProfile;
},
showCard() {
return (
this.shouldLoad &&
(this.isFetchingAdvisers || this.isFetchingProfile || this.showContent ||
this.showError));
}
},
created() {
if (this.showCard) {
if (this.shouldLoad) {
this.fetchAdvisers();
this.fetchProfile();
}
Expand Down
27 changes: 14 additions & 13 deletions myuw_vue/tests/adviser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ describe('Assigned Adviser Card', () => {
});
const wrapper = mount(AssignedAdviserCard, {store, localVue});
await new Promise(setImmediate);

expect(wrapper.vm.hasAdviser).toBe(true);
expect(wrapper.vm.hasProfile).toBe(true);
expect(wrapper.vm.showCard).toBe(true);
expect(wrapper.findComponent(UwCard).exists()).toBe(true);
expect(wrapper.findAllComponents(UwCardProperty)).toHaveLength(2);
expect(wrapper.vm.showCard).toBe(true);
expect(wrapper.vm.isUndergrad).toBe(true);
expect(wrapper.vm.hasMajors).toBe(true);
expect(wrapper.vm.hasMinors).toBe(true);
});
Expand All @@ -69,7 +69,7 @@ describe('Assigned Adviser Card', () => {
const wrapper = mount(AssignedAdviserCard, { store, localVue });
await new Promise(setImmediate);
expect(wrapper.vm.showCard).toBe(true);
expect(wrapper.vm.advisers.length).toBe(0);
expect(wrapper.vm.hasAdviser).toBe(false);
expect(wrapper.vm.hasProfile).toBe(true);
expect(wrapper.vm.hasMajors).toBe(true);
expect(wrapper.vm.hasMinors).toBe(true);
Expand All @@ -90,6 +90,7 @@ describe('Assigned Adviser Card', () => {
store.state.user.affiliations.undergrad = false;
const wrapper = mount(AssignedAdviserCard, { store, localVue });
await new Promise(setImmediate);
expect(wrapper.vm.shouldLoad).toBe(false);
expect(wrapper.vm.showCard).toBe(false);
});

Expand All @@ -103,10 +104,9 @@ describe('Assigned Adviser Card', () => {
});
const wrapper = mount(AssignedAdviserCard, { store, localVue });
await new Promise(setImmediate);
expect(wrapper.vm.showCard).toBe(true);
console.log(wrapper.vm.profile);
expect(wrapper.vm.hasProfile).toBe(false);
expect(wrapper.vm.showContent).toBe(false);
expect(wrapper.vm.showCard).toBe(false);
});

it('Show card if no adviser record', async () => {
Expand All @@ -122,8 +122,8 @@ describe('Assigned Adviser Card', () => {
const wrapper = mount(AssignedAdviserCard, {store, localVue});
await new Promise(setImmediate);
expect(wrapper.vm.showCard).toBe(true);
expect(wrapper.vm.isReadyAdvisers).toBe(false);
expect(wrapper.vm.isReadyProfile).toBe(true);
expect(wrapper.vm.hasAdviser).toBe(false);
expect(wrapper.vm.hasProfile).toBe(true);
expect(wrapper.findComponent(UwCard).exists()).toBe(true);
expect(wrapper.vm.showError).toBe(false);
});
Expand All @@ -134,8 +134,9 @@ describe('Assigned Adviser Card', () => {
});
const wrapper = mount(AssignedAdviserCard, {store, localVue});
await new Promise(setImmediate);
expect(wrapper.findComponent(UwCard).exists()).toBe(true);
expect(wrapper.vm.showError).toBe(true);
expect(wrapper.vm.showCard).toBe(true);
expect(wrapper.findComponent(UwCard).exists()).toBe(true);
});

it('Hide error', async () => {
Expand All @@ -144,9 +145,9 @@ describe('Assigned Adviser Card', () => {
});
const wrapper = mount(AssignedAdviserCard, {store, localVue,});
await new Promise(setImmediate);
expect(wrapper.vm.showCard).toBe(true);
expect(wrapper.vm.showCard).toBe(false);
expect(wrapper.vm.showError).toBe(false);
expect(wrapper.vm.isReadyAdvisers).toBe(false);
expect(wrapper.vm.isReadyProfile).toBe(false);
expect(wrapper.vm.hasAdviser).toBe(false);
expect(wrapper.vm.hasProfile).toBe(false);
});
});
});

0 comments on commit f9b17b9

Please sign in to comment.