Skip to content

Commit 86541bc

Browse files
authored
Merge pull request #836 from europeana/feat/MET-5802-Remove-Regiser-User-Feature-Revert
MET-5802 Revert
2 parents 07551f0 + 25e446f commit 86541bc

13 files changed

+392
-0
lines changed

projects/metis/src/app/_translate/lang-en.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export const LANG_EN_TRANS = {
155155
rawXml: 'Raw XML',
156156
redirectsFrom: 'Redirects from',
157157
refresh: 'Refresh',
158+
register: 'Register to Metis',
159+
registrationAlready: 'You are already registered, you will be redirected to the sign in page!',
160+
registrationFailed: 'Registration failed, try again later',
161+
registrationSuccessful: 'Registration successful, you will be redirected to the sign in page!',
158162
replacedby: 'Replaced by',
159163
replaces: 'Replaces',
160164
report: 'Report',
@@ -211,6 +215,7 @@ export const LANG_EN_TRANS = {
211215
userPasswordNew: 'New password',
212216
userPasswordOld: 'Old password',
213217
userPasswordOldError: 'The new password cannot be the same as the old password',
218+
userPasswordWeakError: 'Password is too weak',
214219
userProfile: 'User profile',
215220
viewPreview: 'View in Preview',
216221
viewCollections: 'View in Collections',

projects/metis/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import { LoadTitleComponent } from './load-title';
6060
import { LoginComponent } from './login';
6161
import { PageNotFoundComponent } from './page-not-found';
6262
import { ProfileComponent } from './profile';
63+
import { RegisterComponent } from './register';
6364
import { AppRoutingModule } from './routing';
6465
import {
6566
HeaderComponent,
@@ -76,6 +77,7 @@ import { SearchResultsComponent } from './search-results';
7677
ActionbarComponent,
7778
AppComponent,
7879
CollapsibleDirective,
80+
RegisterComponent,
7981
LoginComponent,
8082
ProfileComponent,
8183
LoadAnimationComponent,

projects/metis/src/app/home/home.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ <h2 *ngIf="bannerheading">{{ bannerheading }}</h2>
119119
<p *ngIf="bannertext">{{ bannertext }}</p>
120120
</div>
121121
</div>
122+
<div class="banner-link" *ngIf="bannerlinktext">
123+
<a routerLink="/register" class="btn btn-light">{{ bannerlinktext }}</a>
124+
</div>
122125
</section>
123126
<lib-footer></lib-footer>
124127
</div>

projects/metis/src/app/home/home.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class HomeComponent implements OnInit {
1616

1717
bannerheading: string;
1818
bannertext: string;
19+
bannerlinktext: string;
1920

2021
constructor(private readonly documentTitleService: DocumentTitleService) {
2122
this.heroimage = 'url(/assets/images/hero_metis_1600x650_jade.png)';
@@ -27,6 +28,7 @@ export class HomeComponent implements OnInit {
2728
this.bannerheading = 'What can you do with Metis?';
2829
this.bannertext =
2930
'Ever wondered how to automagically digest huge amounts of data with the push of a button?';
31+
this.bannerlinktext = 'Register to Metis here';
3032
}
3133

3234
/** ngOnInit
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './register.component';
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<div class="metis-register-form metis-form">
2+
<form (ngSubmit)="onSubmit()" [formGroup]="registerForm" novalidate autocomplete="off">
3+
<div class="form-header">
4+
<h2>{{ 'register' | translate }}</h2>
5+
</div>
6+
7+
<app-notification
8+
[notification]="notification"
9+
(closed)="notification = undefined"
10+
></app-notification>
11+
12+
<div class="form-fields">
13+
<fieldset class="form-group">
14+
<legend>{{ 'email' | translate }}</legend>
15+
<label for="email">{{ 'email' | translate }}:</label>
16+
<input id="email" formControlName="email" placeholder="[email protected]" />
17+
<div
18+
class="messages"
19+
*ngIf="registerForm.controls['email'].touched && !registerForm.controls['email'].valid"
20+
>
21+
<div class="error-message">{{ 'emailError' | translate }}</div>
22+
</div>
23+
</fieldset>
24+
25+
<fieldset class="form-group" formGroupName="passwords">
26+
<legend>{{ 'userPassword' | translate }}</legend>
27+
<label for="password">{{ 'userPassword' | translate }}:</label>
28+
<input
29+
id="password"
30+
type="password"
31+
formControlName="password"
32+
(keyup)="onKeyupPassword()"
33+
placeholder="{{ 'userPassword' | translate }}"
34+
/>
35+
<app-password-check [passwordToCheck]="password"></app-password-check>
36+
<input
37+
id="confirm"
38+
type="password"
39+
formControlName="confirm"
40+
placeholder="Confirm password"
41+
/>
42+
<div
43+
class="messages"
44+
*ngIf="
45+
registerForm.controls['passwords'].get('confirm')!.touched &&
46+
!registerForm.controls['passwords'].get('confirm')!.valid
47+
"
48+
>
49+
<div class="error-message">{{ 'userPasswordMatchError' | translate }}</div>
50+
</div>
51+
</fieldset>
52+
53+
<div class="form-group form-group-btns">
54+
<app-loading-button
55+
classes="button-filled"
56+
type="submit"
57+
[disabled]="!registerForm.valid"
58+
[isLoading]="loading"
59+
[title]="'submit' | translate"
60+
></app-loading-button>
61+
</div>
62+
</div>
63+
</form>
64+
</div>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@import 'shared-styles/assets/sass/scss/generic/variables-colours';
2+
3+
.notfound {
4+
margin: 0 auto;
5+
padding-top: 2rem;
6+
width: 25rem;
7+
8+
.notfound-body {
9+
background-color: $offwhite;
10+
box-sizing: border-box;
11+
padding: 2rem 1.2rem;
12+
width: auto;
13+
}
14+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
2+
import { Router } from '@angular/router';
3+
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
4+
import { ReactiveFormsModule } from '@angular/forms';
5+
import { RouterTestingModule } from '@angular/router/testing';
6+
import { of } from 'rxjs';
7+
import {
8+
createMockPipe,
9+
MockAuthenticationService,
10+
MockAuthenticationServiceErrors,
11+
MockTranslateService
12+
} from '../_mocked';
13+
import { NotificationType } from '../_models';
14+
import { AuthenticationService } from '../_services';
15+
import { TranslateService } from '../_translate';
16+
import { LoginComponent } from '../login';
17+
import { RegisterComponent } from '.';
18+
19+
describe('RegisterComponent', () => {
20+
let component: RegisterComponent;
21+
let fixture: ComponentFixture<RegisterComponent>;
22+
let submitBtn: HTMLInputElement;
23+
let authentication: AuthenticationService;
24+
let router: Router;
25+
26+
const configureTestingModule = (errorMode = false): void => {
27+
TestBed.configureTestingModule({
28+
imports: [
29+
RouterTestingModule.withRoutes([{ path: './signin', component: LoginComponent }]),
30+
ReactiveFormsModule
31+
],
32+
declarations: [RegisterComponent, createMockPipe('translate')],
33+
providers: [
34+
{
35+
provide: AuthenticationService,
36+
useClass: errorMode ? MockAuthenticationServiceErrors : MockAuthenticationService
37+
},
38+
{ provide: TranslateService, useClass: MockTranslateService }
39+
],
40+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
41+
}).compileComponents();
42+
router = TestBed.inject(Router);
43+
authentication = TestBed.inject(AuthenticationService);
44+
};
45+
46+
const b4Each = (): void => {
47+
fixture = TestBed.createComponent(RegisterComponent);
48+
component = fixture.componentInstance;
49+
fixture.detectChanges();
50+
};
51+
52+
const fillValidForm = (): void => {
53+
component.registerForm.controls.email.setValue('[email protected]');
54+
component.registerForm.controls.passwords.controls.password.setValue('!Passw0rd123');
55+
component.registerForm.controls.passwords.controls.confirm.setValue('!Passw0rd123');
56+
};
57+
58+
describe('Normal operations', () => {
59+
beforeEach(async(() => {
60+
configureTestingModule();
61+
}));
62+
63+
beforeEach(b4Each);
64+
65+
it('should create', () => {
66+
expect(component).toBeTruthy();
67+
});
68+
69+
it('updates the password on key-up', () => {
70+
expect(component.password).toBeFalsy();
71+
component.registerForm.controls.passwords.controls.password.setValue('password');
72+
expect(component.password).toBeFalsy();
73+
component.onKeyupPassword();
74+
expect(component.password).toBeTruthy();
75+
});
76+
77+
it('should contain a form', () => {
78+
expect(fixture.nativeElement.querySelector('.metis-register-form') === null).toBe(false);
79+
});
80+
81+
it('should contain a disabled button at first', () => {
82+
submitBtn = fixture.nativeElement.querySelector('app-loading-button');
83+
expect(submitBtn.disabled).toBe(true);
84+
});
85+
86+
it('should not register if submit fails', fakeAsync(() => {
87+
spyOn(router, 'navigate');
88+
spyOn(authentication, 'register').and.callFake(() => {
89+
return of(false);
90+
});
91+
fillValidForm();
92+
component.onSubmit();
93+
tick(3000);
94+
tick(1);
95+
fixture.detectChanges();
96+
expect(router.navigate).not.toHaveBeenCalled();
97+
}));
98+
99+
it('should submit the form and redirect', fakeAsync(() => {
100+
spyOn(router, 'navigate');
101+
submitBtn = fixture.nativeElement.querySelector('app-loading-button');
102+
fillValidForm();
103+
component.onSubmit();
104+
tick(3000);
105+
tick(1);
106+
fixture.detectChanges();
107+
expect(submitBtn.disabled).toBeFalsy();
108+
expect(component.loading).toBeFalsy();
109+
expect(router.navigate).toHaveBeenCalledWith(['/signin']);
110+
}));
111+
112+
it('should reject weak password', () => {
113+
submitBtn = fixture.nativeElement.querySelector('app-loading-button');
114+
component.registerForm.controls.email.setValue('[email protected]');
115+
component.registerForm.controls.passwords.controls.password.setValue('');
116+
component.registerForm.controls.passwords.controls.confirm.setValue('');
117+
expect(submitBtn.disabled).toBeTruthy();
118+
component.onSubmit();
119+
fixture.detectChanges();
120+
expect(component.notification).toBeTruthy();
121+
if (component.notification) {
122+
expect(component.notification.type).toEqual(NotificationType.ERROR);
123+
}
124+
});
125+
});
126+
127+
describe('Error handling', () => {
128+
beforeEach(async(() => {
129+
configureTestingModule(true);
130+
}));
131+
132+
beforeEach(b4Each);
133+
134+
it('should handle submit errors', fakeAsync(() => {
135+
fillValidForm();
136+
component.onSubmit();
137+
tick(1);
138+
fixture.detectChanges();
139+
expect(component.notification).toBeTruthy();
140+
if (component.notification) {
141+
expect(component.notification.type).toEqual(NotificationType.ERROR);
142+
}
143+
}));
144+
});
145+
});

0 commit comments

Comments
 (0)