-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/fga-eps-mds/2023.2-UnB-T…
…V-Frontend into 54-grade-programacao
- Loading branch information
Showing
16 changed files
with
470 additions
and
11 deletions.
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
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
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 |
---|---|---|
|
@@ -17,4 +17,4 @@ export class AuthGuard implements CanActivate { | |
return false; | ||
} | ||
} | ||
} | ||
} |
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
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,39 @@ | ||
table { | ||
border-collapse: collapse; | ||
width: 100%; | ||
border: 1px solid #ccc; | ||
} | ||
|
||
|
||
th { | ||
background-color: #f2f2f2; | ||
border: 1px solid #ccc; | ||
padding: 8px; | ||
text-align: left; | ||
} | ||
|
||
|
||
tr:nth-child(even) { | ||
background-color: #f2f2f2; | ||
} | ||
|
||
tr:nth-child(odd) { | ||
background-color: #ffffff; | ||
} | ||
|
||
|
||
td { | ||
border: 1px solid #ccc; | ||
padding: 8px; | ||
} | ||
|
||
|
||
tr:hover { | ||
background-color: #e0e0e0; | ||
} | ||
|
||
.filter-container { | ||
display: flex; | ||
align-items: flex-start; | ||
column-gap: 6px; | ||
} |
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,79 @@ | ||
<div class="mx-5"> | ||
<div class="filter-container"> | ||
<div> | ||
<label>Nome ou Email:</label> | ||
<input | ||
[(ngModel)]="filterInputValue" | ||
(change)="filterUser()" | ||
placeholder="Filtrar pelo nome do usuário" | ||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-100 p-2.5 outline-none" | ||
/> | ||
</div> | ||
<div> | ||
<label>Vínculo:</label> | ||
<select | ||
(change)="filterUser()" | ||
[(ngModel)]="filterConnectionValue" | ||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-100 p-2.5 outline-none" | ||
> | ||
<option disabled hidden value="">Selecione um vínculo</option> | ||
<option value="">Sem Filtro</option> | ||
<option value="ESTUDANTE">Estudante</option> | ||
<option value="PROFESSOR">Professor</option> | ||
<option value="SERVIDOR">Servidor</option> | ||
<option value="TERCEIRIZADO">Terceirizado</option> | ||
<option value="ESTAGIARIO">Estagiario</option> | ||
<option value="COMUNIDADE EXTERNA">Comunidade Externa</option> | ||
</select> | ||
</div> | ||
</div> | ||
<div *ngIf="users && users.length; else noUsers"> | ||
<table | ||
class="table-auto mt-3" | ||
style="border-collapse: collapse !important" | ||
aria-label="Tabela de usuários" | ||
> | ||
<thead> | ||
<tr> | ||
<th>Nome</th> | ||
<th>Email</th> | ||
<th>Vínculo</th> | ||
<th>Cargo</th> | ||
<th>Ativo</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let user of users"> | ||
<td>{{ user.name }}</td> | ||
<td>{{ user.email }}</td> | ||
<td>{{ user.connection }}</td> | ||
<td> | ||
<select | ||
class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2.5 outline-none" | ||
[(ngModel)]="user.role" | ||
(change)="updateUserRole(user.id)" | ||
*ngIf="user.id !== userId; else readOnly" | ||
> | ||
<option value="USER">Usuário</option> | ||
<option value="ADMIN">Administrador</option> | ||
</select> | ||
<ng-template #readOnly> Administrador </ng-template> | ||
</td> | ||
<td>{{ user.is_active ? "Sim" : "Não" }}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<mat-paginator | ||
[pageIndex]="pageIndex" | ||
[length]="total" | ||
[pageSize]="pageSize" | ||
[pageSizeOptions]="[5, 10, 25]" | ||
aria-label="User Pagination" | ||
(page)="onPaginateChange($event)" | ||
></mat-paginator> | ||
</div> | ||
|
||
<ng-template #noUsers> | ||
<h3>Nenhum usuário encontrado</h3> | ||
</ng-template> | ||
</div> |
134 changes: 134 additions & 0 deletions
134
src/app/pages/update-role/update-role.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,134 @@ | ||
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { UserService } from 'src/app/services/user.service'; | ||
import { of, throwError } from 'rxjs'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
import { UpdateRoleComponent } from './update-role.component'; | ||
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
|
||
const mockData = [ | ||
{ | ||
"connection": "PROFESSOR", | ||
"id": 1, | ||
"name": "Luisa", | ||
"email": "[email protected]", | ||
"role": "USER", | ||
"is_active": null, | ||
}, | ||
{ | ||
"connection": "ESTUDANTE", | ||
"id": 2, | ||
"name": "Renato", | ||
"email": "[email protected]", | ||
"role": "ADMIN", | ||
"is_active": true, | ||
}, | ||
{ | ||
"connection": "SERVIDOR", | ||
"id": 3, | ||
"name": "Paolla", | ||
"email": "[email protected]", | ||
"role": "USER", | ||
"is_active": true, | ||
} | ||
] | ||
|
||
class UserServiceMock { | ||
constructor() { } | ||
getAllUsers() { | ||
return of(mockData); | ||
} | ||
updateUserRole() { | ||
return of({}); | ||
} | ||
} | ||
|
||
describe('UpdateRoleComponent', () => { | ||
let component: UpdateRoleComponent; | ||
let fixture: ComponentFixture<UpdateRoleComponent>; | ||
let userService: UserService; | ||
let httpMock: HttpTestingController; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [UpdateRoleComponent], | ||
imports: [HttpClientTestingModule, MatPaginatorModule, FormsModule, BrowserAnimationsModule], | ||
providers: [{ provide: UserService, useValue: new UserServiceMock() }] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(UpdateRoleComponent); | ||
component = fixture.componentInstance; | ||
userService = TestBed.inject(UserService); | ||
httpMock = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
it('should create', () => { | ||
let adminToken: string = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJsdWNhc2NhbmRyYWRleDFAZ21haWwuY29tIiwicm9sZSI6IkFETUlOIiwiZXhwIjoxNzAwMTAwMDQxfQ.aDhw1xkK55bhUQCm6tSxX4LYxq8hP_b3T8gYUS449F8" | ||
localStorage.setItem("token", adminToken) | ||
|
||
component.users = mockData; | ||
fixture.detectChanges(); | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should get all users', () => { | ||
const mySpy = spyOn(userService, 'getAllUsers').and.callThrough(); | ||
component.getAllUsers(); | ||
expect(mySpy).toHaveBeenCalled(); | ||
}); | ||
|
||
|
||
it('should get all users and data headers is null', () => { | ||
const mySpy = spyOn(userService, 'getAllUsers').and.returnValue(of({ headers: null, body: [] })); | ||
component.getAllUsers(); | ||
expect(mySpy).toHaveBeenCalled(); | ||
expect(component.users).toEqual([]); | ||
}); | ||
|
||
|
||
|
||
it('should get all users and return error', () => { | ||
const mySpy = spyOn(userService, 'getAllUsers').and.returnValue(throwError(() => new Error('Erro'))); | ||
component.getAllUsers(); | ||
expect(mySpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should update pageSize and pageIndex onPaginateChange', () => { | ||
const event: PageEvent = { | ||
length: 50, | ||
pageIndex: 1, | ||
pageSize: 10, | ||
previousPageIndex: 0 | ||
}; | ||
|
||
component.onPaginateChange(event); | ||
|
||
expect(component.pageSize).toEqual(event.pageSize); | ||
expect(component.pageIndex).toEqual(event.pageIndex); | ||
}); | ||
|
||
it('should filter users from get users', () => { | ||
const mySpy = spyOn(userService, 'getAllUsers').and.callThrough(); | ||
component.filterUser(); | ||
expect(mySpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should update user role', () => { | ||
const mySpy = spyOn(userService, 'updateUserRole').and.callThrough(); | ||
component.updateUserRole(1); | ||
expect(mySpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should update user role and return error', () => { | ||
const mySpy = spyOn(userService, 'updateUserRole').and.returnValue(throwError(() => new Error('Erro'))); | ||
component.updateUserRole(1); | ||
expect(mySpy).toHaveBeenCalled(); | ||
}); | ||
|
||
|
||
}); |
Oops, something went wrong.