From e49995f43ba45acd2b3403ad767026ae0b47a001 Mon Sep 17 00:00:00 2001 From: Dani Date: Thu, 7 Dec 2023 19:07:08 +0100 Subject: [PATCH 1/3] more tests --- e2e/features/CreateRoute.feature | 16 ++++++++++++++-- e2e/steps/create-route.ts | 26 ++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/e2e/features/CreateRoute.feature b/e2e/features/CreateRoute.feature index 90f57a3..a115237 100644 --- a/e2e/features/CreateRoute.feature +++ b/e2e/features/CreateRoute.feature @@ -3,9 +3,10 @@ Feature: Create a new route As a user I want to create a new route - Scenario: Create a new route + Scenario: Create a new route with logged in user Given I'm in the homepage logged in as user with username "demo" and password "password" - When I click on the "Route" menu option + When I click on the "Routes" menu option with class ".nav-link" + And I click on the "Create" menu option with class ".dropdown-item" And I fill the form with | FIELD | VALUE | | title | testRoute | @@ -14,3 +15,14 @@ Feature: Create a new route And I click the "Submit" button Then I've created a new route with creation user "demo", title "testRoute", description "That's a test route to make e2e tests" and type "Running" + Scenario: Create a new route with logged in admin + Given I'm in the homepage logged in as user with username "root" and password "password" + When I click on the "Routes" menu option with class ".nav-link" + Then I try to click on the "Create" menu option with class ".dropdown-item" + + + Scenario: Create a new route without logged in user + Given I'm in the homepage + When I do nothing + Then I try to click on the "Route" menu option with class ".nav-link" + diff --git a/e2e/steps/create-route.ts b/e2e/steps/create-route.ts index 513ed80..8bf7af4 100644 --- a/e2e/steps/create-route.ts +++ b/e2e/steps/create-route.ts @@ -12,9 +12,19 @@ Given('I\'m in the homepage logged in as user with username {string} and passwor //login(username,password); }); -When('I click on the {string} menu option', (option) => { +Given('I\'m in the homepage', () => { + cy.visit('http://localhost:4200'); +}); + +When('I click on the {string} menu option with class {string}', (option,class_) => { //clickMenuOption(option); - cy.get('.nav-link').contains(option).click(); + cy.get(class_).contains(option).click(); +}); + +When('I do nothing', () => { + // Nothing to do + }); +And('I click on the {string} menu option', (option) => { cy.get('#createRoute').click(); }); @@ -29,6 +39,18 @@ Then('I\'ve created a new route with creation user {string}, title {string}, des checkElementText('#Type', type); }); +Then('I try to click on the {string} menu option with class {string}', (option,class_) => { + describe('Exception Handling In Cypress', () => { + it('Navigate to webpage', () => { + Cypress.on('fail', (error, runnable) => { + if (!error.message.includes('Timed out retrying after 4000ms')) { + throw error + } + }); + cy.get(class_).contains(option).click(); + }); + }); +}); function checkElementText(element:string, text:string) { cy.get(element) .invoke('text') From 75de528cc9fb97b6d641ee6d3ffc50c9325f7c23 Mon Sep 17 00:00:00 2001 From: Dani Date: Tue, 16 Jan 2024 21:00:37 +0100 Subject: [PATCH 2/3] create test --- e2e/features/Route/CreateRoute.feature | 8 +------- e2e/steps/Route/create-route.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/e2e/features/Route/CreateRoute.feature b/e2e/features/Route/CreateRoute.feature index a580c5d..af0f9ec 100644 --- a/e2e/features/Route/CreateRoute.feature +++ b/e2e/features/Route/CreateRoute.feature @@ -18,11 +18,5 @@ Feature: Create a new route Scenario: Create a new route with logged in admin Given I'm in the homepage logged in as user with username "root" and password "password" When I click on the "Routes" menu option with class ".nav-link" - Then I try to click on the "Create" menu option with class ".dropdown-item" - - - Scenario: Create a new route without logged in user - Given I'm in the homepage - When I do nothing - Then I try to click on the "Route" menu option with class ".nav-link" + Then I try to click on "#createRoute" element diff --git a/e2e/steps/Route/create-route.ts b/e2e/steps/Route/create-route.ts index 405ec5f..8ace07d 100644 --- a/e2e/steps/Route/create-route.ts +++ b/e2e/steps/Route/create-route.ts @@ -1,4 +1,6 @@ import {Given, When, Then, And} from 'cypress-cucumber-preprocessor/steps'; +import {selectNavigationBar} from "./delete-route"; +import {error} from "@angular/compiler-cli/src/transformers/util"; Given('I\'m in the homepage logged in as user with username {string} and password {string}', (username,password) => { cy.visit('http://localhost:4200'); @@ -19,11 +21,8 @@ When('I click on the {string} menu option with class {string}', (option,class_) cy.get(class_).contains(option).click(); }); -When('I do nothing', () => { - // Nothing to do - }); And('I click on the {string} menu option', (option) => { - cy.get('#createRoute').click(); + selectNavigationBar(option,'Create'); }); And('Select type {string} from the dropdown of types', (type) => { @@ -37,6 +36,7 @@ Then('I\'ve created a new route with creation user {string}, title {string}, des checkElementText('#Type', type); }); + Then('I try to click on the {string} menu option with class {string}', (option,class_) => { describe('Exception Handling In Cypress', () => { it('Navigate to webpage', () => { @@ -49,6 +49,13 @@ Then('I try to click on the {string} menu option with class {string}', (option,c }); }); }); + + +Then('I try to click on {string} element', (element) => { + cy.get(element).should('not.exist'); +}); + + function checkElementText(element:string, text:string) { cy.get(element) .invoke('text') From d7530ec9b476140031b394ac133660f2ff8a32e2 Mon Sep 17 00:00:00 2001 From: Dani Date: Tue, 16 Jan 2024 21:59:09 +0100 Subject: [PATCH 3/3] adding list of routes of the user on user detail --- src/app/routes/route.service.ts | 3 +- .../user-detail/user-detail.component.html | 43 +++++++++++++++++++ .../user/user-detail/user-detail.component.ts | 30 ++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/app/routes/route.service.ts b/src/app/routes/route.service.ts index 32e806c..b9f124a 100644 --- a/src/app/routes/route.service.ts +++ b/src/app/routes/route.service.ts @@ -2,6 +2,7 @@ import { Injectable } from "@angular/core"; import { Observable } from "rxjs/internal/Observable"; import { HateoasResourceOperation, ResourceCollection } from "@lagoshny/ngx-hateoas-client"; import { Route } from "./route"; +import {User} from "../login-basic/user"; @Injectable({providedIn: "root"}) export class RouteService extends HateoasResourceOperation { @@ -10,7 +11,7 @@ export class RouteService extends HateoasResourceOperation { super(Route); } - public findByCreatedBy(creator: string): Observable> { + public findByCreatedBy(creator: User): Observable> { return this.searchCollection("findByCreatedBy", { params: { creator: creator } }) } diff --git a/src/app/user/user-detail/user-detail.component.html b/src/app/user/user-detail/user-detail.component.html index 88dba4c..e78e896 100644 --- a/src/app/user/user-detail/user-detail.component.html +++ b/src/app/user/user-detail/user-detail.component.html @@ -28,3 +28,46 @@
Role
+ +
+
+
+
+
Route
+
+
+
+
CreatedBy
+

{{route.createdBy?.username}}

+
+
+
Creation date
+

{{route.creationDate | date: 'dd/MM/yyyy HH:mm:ss'}}

+
+
+
Title
+

{{route.title}}

+
+
+
Type
+

{{route.type}}

+
+
+
Description
+

{{route.description}}

+
+
+ +
+
+
+
+
+
+ diff --git a/src/app/user/user-detail/user-detail.component.ts b/src/app/user/user-detail/user-detail.component.ts index 4668ad8..05f4127 100644 --- a/src/app/user/user-detail/user-detail.component.ts +++ b/src/app/user/user-detail/user-detail.component.ts @@ -3,6 +3,9 @@ import { ActivatedRoute } from '@angular/router'; import { UserService } from '../user.service'; import { User } from '../../login-basic/user'; import { AuthenticationBasicService } from '../../login-basic/authentication-basic.service'; +import {PagedResourceCollection} from "@lagoshny/ngx-hateoas-client"; +import {Route} from "../../routes/route"; +import {RouteService} from "../../routes/route.service"; @Component({ selector: 'app-user-detail', @@ -10,10 +13,13 @@ import { AuthenticationBasicService } from '../../login-basic/authentication-bas }) export class UserDetailComponent implements OnInit { public user: User = new User(); + public routes: Route[] = []; + constructor(private route: ActivatedRoute, private userService: UserService, - private authenticationService: AuthenticationBasicService) { + private authenticationService: AuthenticationBasicService, + private routesService: RouteService) { } ngOnInit(): void { @@ -21,10 +27,32 @@ export class UserDetailComponent implements OnInit { this.userService.getResource(id).subscribe( user => { this.user = user; + this.routesService.findByCreatedBy(this.user).subscribe((page: PagedResourceCollection) => { + this.routes = page.resources; + console.log(this.routes); + this.routes.map(routes => { + routes.getRelation('createdBy') + .subscribe((user: User) => { + routes.createdBy = user; + }); + }); + }); }); } getCurrentUser(): User { return this.authenticationService.getCurrentUser(); } + + getCurrentUserName(): string { + return this.getCurrentUser().id; + } + + currentUserEdit(username: string){ + return this.getCurrentUserName() == username; + } + + isRole(role: string): boolean { + return this.authenticationService.isRole(role); + } }