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 #15746: Don't set active topic to 'ALL' in contributor dashboard page. #15841

Merged
merged 9 commits into from Aug 15, 2022
Expand Up @@ -46,6 +46,7 @@ describe('Contributor dashboard page', () => {
};
let focusManagerService: FocusManagerService;
let windowRef: WindowRef;
let getTranslatableTopicNamesAsyncSpy;
let getUserInfoAsyncSpy;

beforeEach(waitForAsync(() => {
Expand Down Expand Up @@ -79,8 +80,10 @@ describe('Contributor dashboard page', () => {
userService = TestBed.inject(UserService);
focusManagerService = TestBed.inject(FocusManagerService);

spyOn(contributionOpportunitiesService, 'getTranslatableTopicNamesAsync')
.and.returnValue(Promise.resolve(['Topic 1', 'Topic 2']));
getTranslatableTopicNamesAsyncSpy = spyOn(
contributionOpportunitiesService, 'getTranslatableTopicNamesAsync');
getTranslatableTopicNamesAsyncSpy.and.returnValue(
Promise.resolve(['Topic 1', 'Topic 2']));
spyOn(localStorageService, 'getLastSelectedTranslationLanguageCode').and
.returnValue('');
spyOn(localStorageService, 'getLastSelectedTranslationTopicName').and
Expand All @@ -99,7 +102,6 @@ describe('Contributor dashboard page', () => {
spyOn(userService, 'getUserContributionRightsDataAsync')
.and.returnValue(Promise.resolve(userContributionRights));
getUserInfoAsyncSpy = spyOn(userService, 'getUserInfoAsync');

getUserInfoAsyncSpy.and.returnValue(
Promise.resolve(userInfo as UserInfo));

Expand Down Expand Up @@ -144,14 +146,31 @@ describe('Contributor dashboard page', () => {
}));

describe('when user is logged in', () => {
it('should set specific properties after $onInit is called', () => {
expect(component.topicName).toBe('All');
expect(translationTopicService.setActiveTopicName)
.toHaveBeenCalled();
expect(component.activeTabName).toBe('myContributionTab');
expect(component.OPPIA_AVATAR_IMAGE_URL).toBe(
'/assets/images/avatar/oppia_avatar_100px.svg');
});
it('should set specific properties after $onInit is called',
fakeAsync(() => {
component.ngOnInit();
tick();

expect(component.topicName).toBe('Topic 1');
expect(translationTopicService.setActiveTopicName)
.toHaveBeenCalled();
expect(component.activeTabName).toBe('myContributionTab');
expect(component.OPPIA_AVATAR_IMAGE_URL).toBe(
'/assets/images/avatar/oppia_avatar_100px.svg');
}));

it('should not set active topic name when no topics are returned',
fakeAsync(() => {
getTranslatableTopicNamesAsyncSpy.and.returnValue(
Promise.resolve([]));

component.ngOnInit();
tick();

expect(component.topicName).toBe(undefined);
expect(translationTopicService.setActiveTopicName)
.not.toHaveBeenCalled();
}));

it('should return language description in kebab case format', () => {
let languageDescription = 'Deutsch (German)';
Expand Down
Expand Up @@ -194,16 +194,17 @@ export class ContributorDashboardPageComponent
this.profilePictureDataUrl = decodeURIComponent(dataUrl);
});

this.topicName = (
ContributorDashboardConstants.DEFAULT_OPPORTUNITY_TOPIC_NAME);
this.translationTopicService.setActiveTopicName(this.topicName);

this.contributionOpportunitiesService.getTranslatableTopicNamesAsync()
.then((topicNames) => {
// TODO(#15710): Set default active topic to 'All'.
if (topicNames.length <= 0) {
return;
}
this.topicName = topicNames[0];
if (topicNames.indexOf(prevSelectedTopicName) !== -1) {
this.topicName = prevSelectedTopicName;
this.translationTopicService.setActiveTopicName(this.topicName);
}
this.translationTopicService.setActiveTopicName(this.topicName);
});

this.activeTabName = 'myContributionTab';
Expand Down