Skip to content
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

finish route test and adding routes on user detail #42

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions e2e/features/Route/CreateRoute.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ 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"
Then Logout and delete first 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 "#createRoute" element

35 changes: 32 additions & 3 deletions e2e/steps/Route/create-route.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -10,10 +12,17 @@ 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('#createRoute').click();
cy.get(class_).contains(option).click();
});

And('I click on the {string} menu option', (option) => {
selectNavigationBar(option,'Create');
});

And('Select type {string} from the dropdown of types', (type) => {
Expand All @@ -27,6 +36,26 @@ 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();
});
});
});


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')
Expand Down
3 changes: 2 additions & 1 deletion src/app/routes/route.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Route> {
Expand All @@ -10,7 +11,7 @@ export class RouteService extends HateoasResourceOperation<Route> {
super(Route);
}

public findByCreatedBy(creator: string): Observable<ResourceCollection<Route>> {
public findByCreatedBy(creator: User): Observable<ResourceCollection<Route>> {
return this.searchCollection("findByCreatedBy", { params: { creator: creator } })
}

Expand Down
43 changes: 43 additions & 0 deletions src/app/user/user-detail/user-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,46 @@ <h6 class="card-subtitle text-muted">Role</h6>
</div>
</div>
</div>

<div class="row">
<div class="card col-lg-4 col-md-6 col-sm-12 col-xs-12" *ngFor="let route of routes">
<div class="card-block">
<div class="card-header row m-1 text-center" >
<h5>Route</h5>
</div>
<div class="card-body row m-1">
<div class="col-md-6 p-3">
<h6 class="card-subtitle text-muted">CreatedBy</h6>
<p class="card-text">{{route.createdBy?.username}}</p>
</div>
<div class="col-md-6 p-3">
<h6 class="card-subtitle text-muted">Creation date</h6>
<p class="card-text">{{route.creationDate | date: 'dd/MM/yyyy HH:mm:ss'}}</p>
</div>
<div class="col-md-6 p-3">
<h6 class="card-subtitle text-muted">Title</h6>
<p class="card-text">{{route.title}}</p>
</div>
<div class="col-md-6 p-3">
<h6 class="card-subtitle text-muted">Type</h6>
<p class="card-text">{{route.type}}</p>
</div>
<div class="col-lg12 col-md-12 p-3">
<h6 class="card-subtitle text-muted">Description</h6>
<p class="card-text">{{route.description}}</p>
</div>
</div>
<div class="card-footer text-right row">
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" *ngIf="currentUserEdit(route.createdBy?.username) && !isRole('admin')" [routerLink]="[route.uri+'/edit']" class="btn col-6 m-1 btn-outline-success">Edit</button>
<button type="button" *ngIf="!isRole('admin')" [routerLink]="[route.uri]" class="btn col-6 m-1 btn-outline-primary">Detail</button>
<button type="button" *ngIf="isRole('admin')" [routerLink]="[route.uri + '/delete']" class="btn col-6 m-1 btn-outline-danger">Delete</button>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<hr class="my-3">
</div>

30 changes: 29 additions & 1 deletion src/app/user/user-detail/user-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,56 @@ 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',
templateUrl: './user-detail.component.html'
})
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 {
const id = this.route.snapshot.paramMap.get('id');
this.userService.getResource(id).subscribe(
user => {
this.user = user;
this.routesService.findByCreatedBy(this.user).subscribe((page: PagedResourceCollection<Route>) => {
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);
}
}
Loading