-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6450 from NMDSdevopsServiceAdm/feat/1571-forgotte…
…n-username-display-username Feat/1571 forgotten username display username
- Loading branch information
Showing
10 changed files
with
250 additions
and
69 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
7 changes: 7 additions & 0 deletions
7
...pp/core/components/error/page-no-longer-available/page-no-longer-available.component.html
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds-from-desktop"> | ||
<h1 class="govuk-heading-xl">Page no longer available</h1> | ||
<p>The page you are trying to view does not exist anymore.</p> | ||
<p><a [routerLink]="['/login']" class="text-link">Return to the homepage</a></p> | ||
</div> | ||
</div> |
41 changes: 41 additions & 0 deletions
41
...core/components/error/page-no-longer-available/page-no-longer-available.component.spec.ts
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { render } from '@testing-library/angular'; | ||
import { RouterModule } from '@angular/router'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { PageNoLongerAvailableComponent } from './page-no-longer-available.component'; | ||
|
||
describe('PageNoLongerAvailableComponent', () => { | ||
const setup = async () => { | ||
const setupTools = await render(PageNoLongerAvailableComponent, { | ||
imports: [RouterModule, RouterTestingModule, HttpClientTestingModule], | ||
declarations: [], | ||
providers: [], | ||
componentProperties: {}, | ||
}); | ||
|
||
const component = setupTools.fixture.componentInstance; | ||
|
||
return { ...setupTools, component }; | ||
}; | ||
|
||
it('should create', async () => { | ||
const { component } = await setup(); | ||
|
||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should show the page heading', async () => { | ||
const { getByRole } = await setup(); | ||
|
||
expect(getByRole('heading', { name: 'Page no longer available' })).toBeTruthy(); | ||
}); | ||
|
||
it('should show a link to the homepage', async () => { | ||
const { getByText } = await setup(); | ||
|
||
const linkText = getByText('Return to the homepage'); | ||
|
||
expect(linkText).toBeTruthy(); | ||
expect(linkText.getAttribute('href')).toEqual('/login'); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
.../app/core/components/error/page-no-longer-available/page-no-longer-available.component.ts
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-page-no-longer-available', | ||
templateUrl: './page-no-longer-available.component.html', | ||
}) | ||
export class PageNoLongerAvailableComponent { | ||
constructor() {} | ||
} |
28 changes: 28 additions & 0 deletions
28
...pp/features/forgot-your-username-or-password/username-found/username-found.component.html
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<ng-container *ngIf="isUsernameFound; else notAvailable"> | ||
<div | ||
class="govuk-panel govuk-panel--gray govuk-util__align-left govuk-!-margin-top-1 govuk-!-padding-top-1 govuk-!-padding-bottom-5 govuk-!-padding-left-2 govuk-!-padding-right-0 panel" | ||
data-testid="panel" | ||
> | ||
<h1 class="govuk-heading-l govuk-!-margin-top-4 govuk-!-margin-bottom-3"> | ||
<img | ||
class="govuk-!-margin-right-1 govuk-util__vertical-align-top govuk-!-margin-right-2 green-tick-icon" | ||
src="/assets/images/tick-icon.svg" | ||
alt="" | ||
/>We’ve found your username | ||
</h1> | ||
<div class="govuk-!-font-size-19 govuk-!-margin-left-7"> | ||
Your username is | ||
<div class="govuk-!-font-size-27 govuk-!-font-weight-bold govuk-!-margin-top-1">{{ username }}</div> | ||
</div> | ||
</div> | ||
|
||
<div class="govuk-!-margin-top-8"> | ||
<button type="submit" class="govuk-button" data-module="govuk-button" (click)="backToSignInPage($event)"> | ||
Back to sign in | ||
</button> | ||
</div> | ||
</ng-container> | ||
|
||
<ng-template #notAvailable> | ||
<app-page-no-longer-available data-testid="page-no-longer-available"></app-page-no-longer-available> | ||
</ng-template> |
8 changes: 8 additions & 0 deletions
8
...pp/features/forgot-your-username-or-password/username-found/username-found.component.scss
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.panel { | ||
width: 64%; | ||
} | ||
|
||
.green-tick-icon { | ||
height: 28px; | ||
vertical-align: baseline; | ||
} |
94 changes: 94 additions & 0 deletions
94
...features/forgot-your-username-or-password/username-found/username-found.component.spec.ts
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { fireEvent, render, within } from '@testing-library/angular'; | ||
import { UsernameFoundComponent } from './username-found.component'; | ||
import { getTestBed } from '@angular/core/testing'; | ||
import { Router, RouterModule } from '@angular/router'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { FindUsernameService } from '@core/services/find-username.service'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { PageNoLongerAvailableComponent } from '@core/components/error/page-no-longer-available/page-no-longer-available.component'; | ||
|
||
describe('UsernameFoundComponent', () => { | ||
const setup = async (overrides: any = {}) => { | ||
const setupTools = await render(UsernameFoundComponent, { | ||
imports: [RouterModule, RouterTestingModule, HttpClientTestingModule], | ||
declarations: [PageNoLongerAvailableComponent], | ||
providers: [ | ||
{ | ||
provide: FindUsernameService, | ||
useValue: { usernameFound: overrides.username }, | ||
}, | ||
], | ||
componentProperties: {}, | ||
}); | ||
|
||
const component = setupTools.fixture.componentInstance; | ||
|
||
const injector = getTestBed(); | ||
const router = injector.inject(Router) as Router; | ||
|
||
const routerSpy = spyOn(router, 'navigate').and.returnValue(Promise.resolve(true)); | ||
|
||
return { ...setupTools, component, routerSpy }; | ||
}; | ||
|
||
it('should create UsernameFoundComponent', async () => { | ||
const overrides = { | ||
username: 'Bighitterhank1000', | ||
}; | ||
|
||
const { component } = await setup(overrides); | ||
|
||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should show the panel', async () => { | ||
const overrides = { | ||
username: 'Bighitterhank1000', | ||
}; | ||
|
||
const { getByTestId } = await setup(overrides); | ||
|
||
const panel = getByTestId('panel'); | ||
|
||
expect(panel).toBeTruthy(); | ||
expect(within(panel).getByText('We’ve found your username')); | ||
}); | ||
|
||
it('should show the username', async () => { | ||
const overrides = { | ||
username: 'Bighitterhank1000', | ||
}; | ||
|
||
const { getByTestId } = await setup(overrides); | ||
|
||
const panel = getByTestId('panel'); | ||
expect(within(panel).getByText('Your username is')); | ||
expect(within(panel).getByText('Bighitterhank1000')); | ||
}); | ||
|
||
it('should go back to the sign in page when the button is clicked', async () => { | ||
const overrides = { | ||
username: 'Bighitterhank1000', | ||
}; | ||
|
||
const { fixture, getByText, routerSpy } = await setup(overrides); | ||
|
||
const buttonText = getByText('Back to sign in'); | ||
expect(buttonText).toBeTruthy(); | ||
|
||
fireEvent.click(buttonText); | ||
fixture.detectChanges(); | ||
|
||
expect(routerSpy).toHaveBeenCalledWith(['/login']); | ||
}); | ||
|
||
it('should show page no longer available if no username was found', async () => { | ||
const overrides = { | ||
username: null, | ||
}; | ||
|
||
const { getByTestId } = await setup(overrides); | ||
|
||
expect(getByTestId('page-no-longer-available')).toBeTruthy(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
.../app/features/forgot-your-username-or-password/username-found/username-found.component.ts
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { FindUsernameService } from '@core/services/find-username.service'; | ||
|
||
@Component({ | ||
selector: 'app-username-found', | ||
templateUrl: './username-found.component.html', | ||
styleUrls: ['./username-found.component.scss'], | ||
}) | ||
export class UsernameFoundComponent implements OnInit { | ||
public username: string; | ||
public isUsernameFound: boolean; | ||
|
||
constructor(private router: Router, private findUsernameService: FindUsernameService) {} | ||
|
||
ngOnInit(): void { | ||
this.getUsernameFound(); | ||
this.isUsernameFound = this.username !== null; | ||
} | ||
|
||
public getUsernameFound(): void { | ||
this.username = this.findUsernameService.usernameFound; | ||
} | ||
|
||
public backToSignInPage(event: Event): void { | ||
event.preventDefault(); | ||
this.router.navigate(['/login']); | ||
} | ||
} |
Oops, something went wrong.