diff --git a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts index 1d8d4b975..8a1901721 100644 --- a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts @@ -11,14 +11,15 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms' import { NgbAccordionModule, NgbActiveModal, + NgbModal, NgbModalModule, + NgbModalRef, } from '@ng-bootstrap/ng-bootstrap' import { HttpClientModule } from '@angular/common/http' import { TextComponent } from '../input/text/text.component' import { PasswordComponent } from '../input/password/password.component' import { of, throwError } from 'rxjs' import { ToastService } from 'src/app/services/toast.service' -import { By } from '@angular/platform-browser' import { Clipboard } from '@angular/cdk/clipboard' const profile = { @@ -35,6 +36,7 @@ describe('ProfileEditDialogComponent', () => { let profileService: ProfileService let toastService: ToastService let clipboard: Clipboard + let modalService: NgbModal beforeEach(() => { TestBed.configureTestingModule({ @@ -55,6 +57,7 @@ describe('ProfileEditDialogComponent', () => { profileService = TestBed.inject(ProfileService) toastService = TestBed.inject(ToastService) clipboard = TestBed.inject(Clipboard) + modalService = TestBed.inject(NgbModal) fixture = TestBed.createComponent(ProfileEditDialogComponent) component = fixture.componentInstance fixture.detectChanges() @@ -160,6 +163,28 @@ describe('ProfileEditDialogComponent', () => { expect(component.saveDisabled).toBeFalsy() }) + it('should logout on save if password changed', fakeAsync(() => { + const getSpy = jest.spyOn(profileService, 'get') + getSpy.mockReturnValue(of(profile)) + component.ngOnInit() + component['newPassword'] = 'new*pass' + component.form.get('password').patchValue('new*pass') + component.form.get('password_confirm').patchValue('new*pass') + + const updateSpy = jest.spyOn(profileService, 'update') + updateSpy.mockReturnValue(of(null)) + Object.defineProperty(window, 'location', { + value: { + href: 'http://localhost/', + }, + writable: true, // possibility to override + }) + component.save() + expect(updateSpy).toHaveBeenCalled() + tick(2600) + expect(window.location.href).toContain('logout') + })) + it('should support auth token copy', fakeAsync(() => { const getSpy = jest.spyOn(profileService, 'get') getSpy.mockReturnValue(of(profile)) diff --git a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.ts b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.ts index 57196846a..f8c63c8c0 100644 --- a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.ts @@ -112,8 +112,6 @@ export class ProfileEditDialogComponent implements OnInit, OnDestroy { } onPasswordChange(): void { - console.log(this.currentPassword, this.newPassword) - this.showPasswordConfirm = this.currentPassword !== this.newPassword if (this.showPasswordConfirm) { @@ -131,6 +129,7 @@ export class ProfileEditDialogComponent implements OnInit, OnDestroy { } save(): void { + const passwordChanged = this.currentPassword !== this.newPassword const profile = Object.assign({}, this.form.value) this.networkActive = true this.profileService @@ -138,7 +137,16 @@ export class ProfileEditDialogComponent implements OnInit, OnDestroy { .pipe(takeUntil(this.unsubscribeNotifier)) .subscribe({ next: () => { + console.log('next', passwordChanged) this.toastService.showInfo($localize`Profile updated successfully`) + if (passwordChanged) { + this.toastService.showInfo( + $localize`Password has been changed, you will be logged out momentarily.` + ) + setTimeout(() => { + window.location.href = `${window.location.origin}/accounts/logout/?next=/accounts/login/` + }, 2500) + } this.activeModal.close() }, error: (error) => {