-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feat/1571 forgotten username display username #6450
Merged
ssrome
merged 7 commits into
feature-branch/forgotten-username
from
feat/1571-forgotten-username-display-username
Dec 19, 2024
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d546629
Create new page to display username
ssrome 9e946b6
Add panel to display
ssrome bf0b324
Merge branch 'feature-branch/forgotten-username' into feat/1571-forgo…
ssrome a2d2d6d
Rename and move component
ssrome 3efe1cd
Remove commented code
ssrome 45be738
Create component for page no longer available
ssrome 6020fab
Addressing pr comments
ssrome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-!-font-size-36 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 ? true : false; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably we could simplify it as
Suggested change
Or, at the html template, we could set the if condition as |
||||||
} | ||||||
|
||||||
public getUsernameFound(): void { | ||||||
this.username = this.findUsernameService.usernameFound; | ||||||
} | ||||||
|
||||||
public backToSignInPage(event: Event): void { | ||||||
event.preventDefault(); | ||||||
this.router.navigate(['/login']); | ||||||
} | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use
govuk-heading-l
instead ofgovuk-!-font-size-36
here. Both are same font size, but in most case we use the heading classes for h1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use the gov heading class