Skip to content

Commit

Permalink
change password component
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcaprice committed Jan 10, 2024
1 parent 64fa96c commit 2f4297f
Show file tree
Hide file tree
Showing 28 changed files with 2,842 additions and 1,239 deletions.
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,7 +1,7 @@
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'
Expand All @@ -26,32 +26,29 @@ describe('Component Tests', () => {
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 @@ describe('Component Tests', () => {
}
))

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

0 comments on commit 2f4297f

Please sign in to comment.