forked from ls1intum/Artemis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Users: Passwort reset by username for internal users (ls1intum#4625)
- Loading branch information
1 parent
e00dd7e
commit 2f52056
Showing
8 changed files
with
80 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { ElementRef } from '@angular/core'; | ||
import { ComponentFixture, TestBed, inject } from '@angular/core/testing'; | ||
import { FormBuilder } from '@angular/forms'; | ||
import { FormBuilder, NgModel } from '@angular/forms'; | ||
import { of, throwError } from 'rxjs'; | ||
import { ArtemisTestModule } from '../../test.module'; | ||
import { PasswordResetInitComponent } from 'app/account/password-reset/init/password-reset-init.component'; | ||
import { PasswordResetInitService } from 'app/account/password-reset/init/password-reset-init.service'; | ||
import { ProfileService } from 'app/shared/layouts/profiles/profile.service'; | ||
import { MockProfileService } from '../../helpers/mocks/service/mock-profile.service'; | ||
import { AlertService } from 'app/core/util/alert.service'; | ||
import { MockComponent, MockProvider } from 'ng-mocks'; | ||
import { MockComponent, MockDirective, MockProvider } from 'ng-mocks'; | ||
import { MockTranslateService, TranslatePipeMock } from '../../helpers/mocks/service/mock-translate.service'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { MockNgbModalService } from '../../helpers/mocks/service/mock-ngb-modal.service'; | ||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { AlertComponent } from 'app/shared/alert/alert.component'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
describe('PasswordResetInitComponent', () => { | ||
let fixture: ComponentFixture<PasswordResetInitComponent>; | ||
|
@@ -22,7 +22,7 @@ describe('PasswordResetInitComponent', () => { | |
beforeEach(() => { | ||
return TestBed.configureTestingModule({ | ||
imports: [ArtemisTestModule], | ||
declarations: [PasswordResetInitComponent, TranslatePipeMock, MockComponent(AlertComponent)], | ||
declarations: [PasswordResetInitComponent, TranslatePipeMock, MockComponent(AlertComponent), MockDirective(NgModel)], | ||
providers: [ | ||
FormBuilder, | ||
{ provide: ProfileService, useClass: MockProfileService }, | ||
|
@@ -39,27 +39,20 @@ describe('PasswordResetInitComponent', () => { | |
}); | ||
|
||
it('sets focus after the view has been initialized', () => { | ||
const node = { | ||
focus(): void {}, | ||
}; | ||
comp.email = new ElementRef(node); | ||
jest.spyOn(node, 'focus'); | ||
fixture.detectChanges(); | ||
|
||
comp.ngAfterViewInit(); | ||
|
||
expect(node.focus).toHaveBeenCalled(); | ||
const emailUsernameInput = fixture.debugElement.query(By.css('#emailUsername')).nativeElement; | ||
const focusedElement = fixture.debugElement.query(By.css(':focus')).nativeElement; | ||
expect(focusedElement).toBe(emailUsernameInput); | ||
}); | ||
|
||
it('notifies of success upon successful requestReset', inject([PasswordResetInitService], (service: PasswordResetInitService) => { | ||
jest.spyOn(service, 'save').mockReturnValue(of({})); | ||
comp.resetRequestForm.patchValue({ | ||
email: '[email protected]', | ||
}); | ||
comp.emailUsernameValue = '[email protected]'; | ||
|
||
comp.requestReset(); | ||
|
||
expect(service.save).toHaveBeenCalledWith('[email protected]'); | ||
expect(comp.success).toBe(true); | ||
})); | ||
|
||
it('no notification of success upon error response', inject([PasswordResetInitService], (service: PasswordResetInitService) => { | ||
|
@@ -69,31 +62,26 @@ describe('PasswordResetInitComponent', () => { | |
data: 'something else', | ||
})), | ||
); | ||
comp.resetRequestForm.patchValue({ | ||
email: '[email protected]', | ||
}); | ||
comp.emailUsernameValue = '[email protected]'; | ||
|
||
comp.requestReset(); | ||
|
||
expect(service.save).toHaveBeenCalledWith('[email protected]'); | ||
expect(comp.success).toBe(false); | ||
expect(comp.externalResetModalRef).toBe(undefined); | ||
})); | ||
|
||
it('no notification of success upon external user error response', inject([PasswordResetInitService], (service: PasswordResetInitService) => { | ||
jest.spyOn(service, 'save').mockReturnValue( | ||
throwError({ | ||
throwError(() => ({ | ||
status: 400, | ||
error: { errorKey: 'externalUser' }, | ||
}), | ||
})), | ||
); | ||
comp.useExternal = true; | ||
comp.resetRequestForm.patchValue({ | ||
email: '[email protected]', | ||
}); | ||
comp.emailUsernameValue = '[email protected]'; | ||
comp.requestReset(); | ||
|
||
expect(service.save).toHaveBeenCalledWith('[email protected]'); | ||
expect(comp.success).toBe(false); | ||
expect(comp.externalResetModalRef).not.toBe(undefined); // External reference | ||
})); | ||
}); |