Skip to content

Commit

Permalink
Merge branch 'created-themeable-ProfilePageMetadataFormComponent_cont…
Browse files Browse the repository at this point in the history
…ribute-7.6' into minor-themed-component-fixes_contribute-main

# Conflicts:
#	src/app/profile-page/profile-page.component.spec.ts
#	src/app/profile-page/profile-page.component.ts
  • Loading branch information
alexandrevryghem committed May 8, 2024
2 parents 4c4531f + 83fbf8b commit 04764e4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
47 changes: 32 additions & 15 deletions src/app/profile-page/profile-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
waitForAsync,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { RouterModule } from '@angular/router';
import { StoreModule } from '@ngrx/store';
import { provideMockStore } from '@ngrx/store/testing';
import { TranslateModule } from '@ngx-translate/core';
Expand Down Expand Up @@ -113,8 +113,9 @@ describe('ProfilePageComponent', () => {
imports: [
StoreModule.forRoot({ auth: authReducer }, storeModuleConfig),
TranslateModule.forRoot(),
RouterTestingModule.withRoutes([]),
ProfilePageComponent, VarDirective,
RouterModule.forRoot([]),
ProfilePageComponent,
VarDirective,
],
providers: [
{ provide: EPersonDataService, useValue: epersonService },
Expand Down Expand Up @@ -154,9 +155,13 @@ describe('ProfilePageComponent', () => {
describe('updateProfile', () => {
describe('when the metadata form returns false and the security form returns true', () => {
beforeEach(() => {
component.metadataForm = jasmine.createSpyObj('metadataForm', {
updateProfile: false,
});
component.metadataForm = {
compRef: {
instance: {
updateProfile: () => false,
},
},
} as any;
spyOn(component, 'updateSecurity').and.returnValue(true);
component.updateProfile();
});
Expand All @@ -168,9 +173,13 @@ describe('ProfilePageComponent', () => {

describe('when the metadata form returns true and the security form returns false', () => {
beforeEach(() => {
component.metadataForm = jasmine.createSpyObj('metadataForm', {
updateProfile: true,
});
component.metadataForm = {
compRef: {
instance: {
updateProfile: () => true,
},
},
} as any;
component.updateProfile();
});

Expand All @@ -181,9 +190,13 @@ describe('ProfilePageComponent', () => {

describe('when the metadata form returns true and the security form returns true', () => {
beforeEach(() => {
component.metadataForm = jasmine.createSpyObj('metadataForm', {
updateProfile: true,
});
component.metadataForm = {
compRef: {
instance: {
updateProfile: () => true,
},
},
} as any;
component.updateProfile();
});

Expand All @@ -194,9 +207,13 @@ describe('ProfilePageComponent', () => {

describe('when the metadata form returns false and the security form returns false', () => {
beforeEach(() => {
component.metadataForm = jasmine.createSpyObj('metadataForm', {
updateProfile: false,
});
component.metadataForm = {
compRef: {
instance: {
updateProfile: () => false,
},
},
} as any;
component.updateProfile();
});

Expand Down
7 changes: 3 additions & 4 deletions src/app/profile-page/profile-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {
import { NotificationsService } from '../shared/notifications/notifications.service';
import { followLink } from '../shared/utils/follow-link-config.model';
import { VarDirective } from '../shared/utils/var.directive';
import { ProfilePageMetadataFormComponent } from './profile-page-metadata-form/profile-page-metadata-form.component';
import { ThemedProfilePageMetadataFormComponent } from './profile-page-metadata-form/themed-profile-page-metadata-form.component';
import { ProfilePageResearcherFormComponent } from './profile-page-researcher-form/profile-page-researcher-form.component';
import { ProfilePageSecurityFormComponent } from './profile-page-security-form/profile-page-security-form.component';
Expand Down Expand Up @@ -76,7 +75,7 @@ export class ProfilePageComponent implements OnInit {
/**
* A reference to the metadata form component
*/
@ViewChild(ProfilePageMetadataFormComponent) metadataForm: ProfilePageMetadataFormComponent;
@ViewChild(ThemedProfilePageMetadataFormComponent) metadataForm: ThemedProfilePageMetadataFormComponent;

/**
* The authenticated user as observable
Expand Down Expand Up @@ -158,8 +157,8 @@ export class ProfilePageComponent implements OnInit {
* Fire an update on both the metadata and security forms
* Show a warning notification when no changes were made in both forms
*/
updateProfile() {
const metadataChanged = this.metadataForm.updateProfile();
updateProfile(): void {
const metadataChanged = this.metadataForm.compRef.instance.updateProfile();
const securityChanged = this.updateSecurity();
if (!metadataChanged && !securityChanged) {
this.notificationsService.warning(
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/theme-support/themed.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { ThemeService } from './theme.service';
export abstract class ThemedComponent<T extends object> implements AfterViewInit, OnDestroy, OnChanges {
@ViewChild('vcr', { read: ViewContainerRef }) vcr: ViewContainerRef;
@ViewChild('content') themedElementContent: ElementRef;
protected compRef: ComponentRef<T>;
compRef: ComponentRef<T>;

/**
* A reference to the themed component. Will start as undefined and emit every time the themed
Expand Down

0 comments on commit 04764e4

Please sign in to comment.