Skip to content

Commit

Permalink
Resolve MUWM-5349 (#3125)
Browse files Browse the repository at this point in the history
Resolve MUWM-5349
  • Loading branch information
fanglinfang authored Jul 11, 2024
1 parent c6af524 commit 18d5d5d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 32 deletions.
39 changes: 25 additions & 14 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,27 +159,35 @@ 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;
},
hasCompus() {
return this.profile && this.profile.campus !== undefined;
hasProfile() {
return (
this.profile &&
this.profile.campus !== undefined &&
(this.profile.class_level === 'FRESHMAN' ||
this.profile.class_level === "SOPHOMORE" ||
this.profile.class_level === "JUNIOR" ||
this.profile.class_level === "SENIOR")
); //MUWM-5349
},
showContent() {
return this.hasAdviser || this.hasCompus;
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
54 changes: 36 additions & 18 deletions myuw_vue/tests/adviser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import profile from '../vuex/store/profile';
import javgAdvisers from './mock_data/advisers/javerage.json';
import inactiveAdvisers from './mock_data/advisers/jbot.json';
import javgProfile from './mock_data/profile/javerage.json';
import jintProfile from './mock_data/profile/jinter.json';

import AssignedAdviserCard from '../components/academics/adviser.vue';
import UwCard from '../components/_templates/card.vue';
Expand Down Expand Up @@ -38,7 +39,7 @@ describe('Assigned Adviser Card', () => {
});
});

it('Show Assigned Adviser card for undergrad (javerage)', async () => {
it('Show Adviser card for undergrad (javerage)', async () => {
axios.get.mockImplementation((url) => {
const urlData = {
'/api/v1/advisers/': javgAdvisers,
Expand All @@ -48,16 +49,16 @@ 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);
});

it('Show card but no Assigned Adviser (jbot)', async () => {
it('Show card has profile but no Assigned Adviser (jbot)', async () => {
axios.get.mockImplementation((url) => {
const urlData = {
'/api/v1/advisers/': inactiveAdvisers,
Expand All @@ -67,28 +68,44 @@ describe('Assigned Adviser Card', () => {
});
const wrapper = mount(AssignedAdviserCard, { store, localVue });
await new Promise(setImmediate);

expect(wrapper.findComponent(UwCard).exists()).toBe(true);
expect(wrapper.findAllComponents(UwCardProperty)).toHaveLength(2);
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);
expect(wrapper.findComponent(UwCard).exists()).toBe(true);
expect(wrapper.findAllComponents(UwCardProperty)).toHaveLength(2);
});

it('Hide Assigned Adviser card if not undergrad', async () => {
it('Hide Adviser card if not undergrad', async () => {
store.state.user.affiliations.undergrad = false;
const wrapper = mount(AssignedAdviserCard, {store, localVue});
await new Promise(setImmediate);
expect(wrapper.vm.showCard).toBe(false);
});

it('Hide Assigned Adviser card if is a student employee and grad', async () => {
it('Hide Adviser card if is a student employee and grad', async () => {
store.state.user.affiliations.stud_employee = true;
store.state.user.affiliations.grad = true;
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);
});

it('Hide Adviser card if class level is not desired', async () => {
axios.get.mockImplementation((url) => {
const urlData = {
'/api/v1/advisers/': inactiveAdvisers,
'/api/v1/profile/': jintProfile,
};
return Promise.resolve({ data: urlData[url] });
});
const wrapper = mount(AssignedAdviserCard, { store, localVue });
await new Promise(setImmediate);
expect(wrapper.vm.hasProfile).toBe(false);
expect(wrapper.vm.showContent).toBe(false);
expect(wrapper.vm.showCard).toBe(false);
});

Expand All @@ -105,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 @@ -117,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 @@ -127,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 18d5d5d

Please sign in to comment.