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

change password component #1083

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 157 additions & 4 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"ng-extract-i18n-merge": "^2.9.1",
"prettier": "^3.0.3",
"typescript": "~4.9.5"
}
Expand Down
5 changes: 3 additions & 2 deletions ui/src/app/account/account.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { ReactiveFormsModule } from '@angular/forms'
import { routes } from './account.route'
import { PasswordResetInitComponent } from './password/password-reset-init.component'
import { SettingsComponent } from './settings/settings.component'
import { SharedModule } from '../shared/shared.module'
import { SharedModule } from '../shared/shared.module';
import { PasswordComponent } from './password/password.component'

@NgModule({
declarations: [LoginComponent, PasswordResetInitComponent, SettingsComponent],
declarations: [LoginComponent, PasswordResetInitComponent, SettingsComponent, PasswordComponent],
imports: [SharedModule, CommonModule, ReactiveFormsModule, RouterModule.forChild(routes)],
})
export class AccountModule {}
10 changes: 10 additions & 0 deletions ui/src/app/account/account.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LoginComponent } from './login/login.component'
import { PasswordResetInitComponent } from './password/password-reset-init.component'
import { SettingsComponent } from './settings/settings.component'
import { AuthGuard } from './auth.guard'
import { PasswordComponent } from './password/password.component'

export const routes: Routes = [
{
Expand All @@ -26,4 +27,13 @@ export const routes: Routes = [
},
canActivate: [AuthGuard],
},
{
path: 'password',
component: PasswordComponent,
data: {
authorities: ['ROLE_USER'],
pageTitle: 'global.menu.account.password.string',
},
canActivate: [AuthGuard],
},
]
70 changes: 32 additions & 38 deletions ui/src/app/account/password/password-reset-init.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ComponentFixture, TestBed, inject } from '@angular/core/testing'
import { of, throwError } from 'rxjs'

Check warning on line 2 in ui/src/app/account/password/password-reset-init.component.spec.ts

View workflow job for this annotation

GitHub Actions / format

'throwError' is defined but never used

import { PasswordResetInitService } from '../service/password-reset-init.service'
import { PasswordService } from '../service/password.service'
import { PasswordResetInitComponent } from './password-reset-init.component'
import { EMAIL_NOT_FOUND_TYPE } from 'src/app/app.constants'

Check warning on line 6 in ui/src/app/account/password/password-reset-init.component.spec.ts

View workflow job for this annotation

GitHub Actions / format

'EMAIL_NOT_FOUND_TYPE' is defined but never used
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { By } from '@angular/platform-browser'
import { PasswordResetInitResult } from '../model/password-reset-init-result.model'
Expand All @@ -26,32 +26,29 @@
expect(comp.errorEmailNotExists).toBeUndefined()
})

it('notifies of success upon successful requestReset', inject(
[PasswordResetInitService],
(service: PasswordResetInitService) => {
spyOn(service, 'initPasswordReset').and.returnValue(of(new PasswordResetInitResult(true, false, false)))
comp.resetRequestForm.patchValue({
email: '[email protected]',
})
it('notifies of success upon successful requestReset', inject([PasswordService], (service: PasswordService) => {
spyOn(service, 'initPasswordReset').and.returnValue(of(new PasswordResetInitResult(true, false, false)))
comp.resetRequestForm.patchValue({
email: '[email protected]',
})

comp.requestReset()
const emailControl = comp.resetRequestForm.get('email')!
emailControl.setValue('[email protected]')
fixture.detectChanges()
expect(comp.success).toEqual('OK')
expect(comp.error).toBeUndefined()
expect(comp.errorEmailNotExists).toBeUndefined()
fixture.whenStable().then(() => {
expect(true).toBeFalsy()
const button = fixture.debugElement.query(By.css('#reset'))
expect(button.nativeElement.disabled).toBeFalsy()
})
}
))
comp.requestReset()
const emailControl = comp.resetRequestForm.get('email')!
emailControl.setValue('[email protected]')
fixture.detectChanges()
expect(comp.success).toEqual('OK')
expect(comp.error).toBeUndefined()
expect(comp.errorEmailNotExists).toBeUndefined()
fixture.whenStable().then(() => {
expect(true).toBeFalsy()
const button = fixture.debugElement.query(By.css('#reset'))
expect(button.nativeElement.disabled).toBeFalsy()
})
}))

it('notifies of unknown email upon email address not registered/400', inject(
[PasswordResetInitService],
(service: PasswordResetInitService) => {
[PasswordService],
(service: PasswordService) => {
spyOn(service, 'initPasswordReset').and.returnValue(of(new PasswordResetInitResult(false, true, false)))
comp.resetRequestForm.patchValue({
email: '[email protected]',
Expand All @@ -65,21 +62,18 @@
}
))

it('notifies of error upon error response', inject(
[PasswordResetInitService],
(service: PasswordResetInitService) => {
spyOn(service, 'initPasswordReset').and.returnValue(of(new PasswordResetInitResult(false, false, true)))
comp.resetRequestForm.patchValue({
email: '[email protected]',
})
comp.requestReset()
it('notifies of error upon error response', inject([PasswordService], (service: PasswordService) => {
spyOn(service, 'initPasswordReset').and.returnValue(of(new PasswordResetInitResult(false, false, true)))
comp.resetRequestForm.patchValue({
email: '[email protected]',
})
comp.requestReset()

expect(service.initPasswordReset).toHaveBeenCalledWith('[email protected]')
expect(comp.success).toBeUndefined()
expect(comp.errorEmailNotExists).toBeUndefined()
expect(comp.error).toEqual('ERROR')
}
))
expect(service.initPasswordReset).toHaveBeenCalledWith('[email protected]')
expect(comp.success).toBeUndefined()
expect(comp.errorEmailNotExists).toBeUndefined()
expect(comp.error).toEqual('ERROR')
}))

it('should disable the submit button for invalid email address', () => {
const emailControl = comp.resetRequestForm.get('email')!
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/account/password/password-reset-init.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, AfterViewInit, Renderer2 } from '@angular/core'
import { FormBuilder, FormGroup, Validators } from '@angular/forms'

import { PasswordResetInitService } from '../service/password-reset-init.service'
import { PasswordService } from '../service/password.service'
import { EMAIL_NOT_FOUND_TYPE } from 'src/app/app.constants'
import { PasswordResetInitResult } from '../model/password-reset-init-result.model'

Expand All @@ -18,7 +18,7 @@ export class PasswordResetInitComponent implements AfterViewInit {
})

constructor(
private passwordResetInitService: PasswordResetInitService,
private passwordResetInitService: PasswordService,
private renderer: Renderer2,
private fb: FormBuilder
) {}
Expand Down
Loading
Loading