Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianTurner committed Jul 5, 2024
1 parent bb5bf3a commit d585201
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 17 deletions.
47 changes: 33 additions & 14 deletions apps/party-time-frontend-17/-e2e/src/e2e/F013.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,66 @@ describe(passwordChange, () => {
beforeEach(() => {
cy.viewport(1920, 1080);
cy.login();
cy.visit('/');
cy.visit('/account/change-password');
});

const confirmPassword =
'Benutzer sollten in der Lage sein, ihr aktuelles Passwort einzugeben, um ihre Identität zu bestätigen.';
it(confirmPassword, () => {
cy.get('[data-cy="old-password-input"]').type('Hallo123!party');
cy.screenshot(
getScreenshotPath(requirement, passwordChange, confirmPassword),
getScreenshotPath(requirement, passwordChange, "1"),
{
overwrite: true,
capture: 'viewport',
}
);
});

const newPassword =
'Benutzer sollten in der Lage sein, ein neues Passwort einzugeben und zu bestätigen.';
it(newPassword, () => {
cy.screenshot(getScreenshotPath(requirement, passwordChange, newPassword), {
overwrite: true,
capture: 'viewport',
});
});


const newPasswordConstraints =
' Das neue Passwort muss bestimmte Anforderungen erfüllen, z. B. eine Mindestlänge und die Verwendung von Sonderzeichen.';
' Das neue Passwort muss bestimmte Anforderungen erfüllen, z. B. eine Mindestlänge und die Verwendung von Sonderzeichen.';
it(newPasswordConstraints, () => {
cy.get('[data-cy="new-password-input"]').type('prty');
cy.get('[data-cy="old-password-input"]').focus();

cy.screenshot(
getScreenshotPath(requirement, passwordChange, newPasswordConstraints),
getScreenshotPath(requirement, passwordChange, '2'),
{
overwrite: true,
capture: 'viewport',
}
);
});
const newPassword =
'Benutzer sollten in der Lage sein, ein neues Passwort einzugeben und zu bestätigen.';
it(newPassword, () => {

cy.get('[data-cy="new-password-input"]').type('Hallo123!party');
cy.screenshot(getScreenshotPath(requirement, passwordChange, '3'), {
overwrite: true,
capture: 'viewport',
});

});

const passwordChangeLogout =
'Nachdem das Passwort geändert wurde, sollte der Benutzer automatisch abgemeldet werden und sich mit dem neuen Passwort erneut anmelden müssen.';
it(passwordChangeLogout, () => {

cy.get('[data-cy="old-password-input"]').type('Hallo123!party');
cy.get('[data-cy="new-password-input"]').type('Hallo123!party');
cy.screenshot(
getScreenshotPath(requirement, passwordChange, passwordChangeLogout),
getScreenshotPath(requirement, passwordChange, '4'),
{
overwrite: true,
capture: 'viewport',
}
);
cy.get('[data-cy="submit-button"]').click();
cy.wait(1000);
cy.screenshot(
getScreenshotPath(requirement, passwordChange, '5'),
{
overwrite: true,
capture: 'viewport',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { NavbarComponent } from '../../../components/navbar/navbar.component';
import { PageHeaderComponent } from '../../../components/page-header/page-header.component';
import { ChangePasswordDTO } from '../../../models/dto/account-dto.interface';
import { ApiError } from '../../../models/error.interface';
import { AuthService } from '../../../services/auth/auth.service';

@Component({
selector: 'app-change-password',
Expand Down Expand Up @@ -119,11 +120,12 @@ import { ApiError } from '../../../models/error.interface';
</section>
<app-footer></app-footer>`,

providers: [AccountService],
providers: [AccountService, AuthService],
styles: ``,
})
export class ChangePasswordComponent {
private accountService: IAccountService = inject(AccountService);
private authService: AuthService = inject(AuthService);
private snackBar: MatSnackBar = inject(MatSnackBar);

changePasswordForm = new FormGroup({
Expand Down Expand Up @@ -156,13 +158,14 @@ export class ChangePasswordComponent {
},
{ emitEvent: false }
);

Object.keys(this.changePasswordForm.controls).forEach((key) => {
const control = this.changePasswordForm.get(key);
control?.markAsPristine();
control?.markAsUntouched();
control?.setErrors(null);
});
this.authService.logout();
},
error: (apiError: ApiError) => {
console.error('Password change error:', apiError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
LoginResponseDTO,
} from '../../models/dto/auth-dto.interface';
import { ApiError } from '../../models/error.interface';
import { Router } from '@angular/router';

@Injectable({
providedIn: 'root',
Expand All @@ -24,6 +25,7 @@ export class AuthService implements IAuthService {
private http: HttpClient = inject(HttpClient);
private storageService: StorageService = inject(StorageService);
private authStatus$ = new BehaviorSubject<boolean>(this.hasToken());
private router: Router = inject(Router);

isAuthenticated(): Observable<boolean> {
return this.authStatus$.asObservable();
Expand Down Expand Up @@ -75,6 +77,7 @@ export class AuthService implements IAuthService {

logout(): void {
this.storageService.removeAuthToken();
this.authStatus$.next(this.hasToken());
this.authStatus$.next(this.hasToken());
this.router.navigate(['/auth/login']);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d585201

Please sign in to comment.