Skip to content

Commit

Permalink
Realizacao do merge da branch ajustesPosR1
Browse files Browse the repository at this point in the history
Ajustes Solicitados Após a Entrega da Release 1
  • Loading branch information
GabrielRoger07 authored Aug 10, 2024
2 parents 8715b4c + a1ce201 commit cf000c1
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 203 deletions.
19 changes: 15 additions & 4 deletions src/app/pages/category-table/category-table.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CategoryTableComponent } from './category-table.component';
import { IVideo } from 'src/shared/model/video.model';
import { UNB_TV_CHANNEL_ID } from 'src/app/app.constant';
import { AuthService } from 'src/app/services/auth.service';
import { ConfirmationService, Confirmation } from 'primeng/api';
import { ConfirmationService } from 'primeng/api';
import { HttpResponse } from '@angular/common/http';
import { FormsModule } from '@angular/forms'

Expand Down Expand Up @@ -55,6 +55,7 @@ describe('CategoryTableComponent', () => {
expect(component.sortAscending).toBeTrue();
expect(component.selectedColumn).toBe('');
expect(component.categories).toEqual([
"Todas",
"Arte e Cultura",
"Documentais",
"Entrevista",
Expand All @@ -72,7 +73,13 @@ describe('CategoryTableComponent', () => {
spyOn(component, 'findAll');
component.ngOnInit();
expect(component.findAll).toHaveBeenCalled();
component.categories.forEach(category => expect(component.selectedCategories[category]).toBeFalse());
component.categories.forEach(category => {
if (category === "Todas"){
expect(component.selectedCategories[category]).toBeTrue()
}else{
expect(component.selectedCategories[category]).toBeFalse()
}
});
});

it('should fetch and process videos in findAll', () => {
Expand Down Expand Up @@ -149,7 +156,7 @@ describe('CategoryTableComponent', () => {
{ category: 'Entrevista', videoCount: 1, totalViews: 20, viewsPerVideo: 20 },
];

component.selectedCategories = { 'Jornalismo': true, 'Entrevista': false };
component.selectedCategories = { 'Todas': false, 'Jornalismo': true, 'Entrevista': false };

component.filterCategories();

Expand All @@ -163,7 +170,11 @@ describe('CategoryTableComponent', () => {
{ category: 'Entrevista', videoCount: 1, totalViews: 20, viewsPerVideo: 20 },
];

component.filterCategories(); // Certifique-se de que filteredAggregatedVideos seja preenchido
component.selectedCategories["Jornalismo"] = true;
component.selectedCategories["Entrevista"] = true;
component.selectedCategories["Todas"] = false;

component.filterCategories();

component.sortColumn = 'totalViews';
component.sortAscending = true;
Expand Down
11 changes: 7 additions & 4 deletions src/app/pages/category-table/category-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { VideoService } from 'src/app/services/video.service';
import { Catalog } from 'src/shared/model/catalog.model';
import { IVideo } from 'src/shared/model/video.model';
import { AuthService } from 'src/app/services/auth.service';
import { ConfirmationService, MessageService } from 'primeng/api';
import { ConfirmationService } from 'primeng/api';

@Component({
selector: 'app-category-table',
Expand All @@ -22,6 +22,7 @@ export class CategoryTableComponent {
sortAscending: boolean = true;
selectedColumn: string = '';
categories: string[] = [
"Todas",
"Arte e Cultura",
"Documentais",
"Entrevista",
Expand All @@ -44,6 +45,7 @@ export class CategoryTableComponent {

ngOnInit(): void{
this.categories.forEach(category => this.selectedCategories[category] = false);
this.selectedCategories["Todas"] = true;
this.findAll();
}

Expand Down Expand Up @@ -141,8 +143,10 @@ export class CategoryTableComponent {

filterCategories(): void {
const selectedCategories = Object.keys(this.selectedCategories).filter(category => this.selectedCategories[category]);
if(selectedCategories.length === 0){
if (selectedCategories.includes("Todas")) {
this.filteredAggregatedVideos = this.aggregatedVideos;
}else if(selectedCategories.length === 0){
this.filteredAggregatedVideos = [];
}
else{
this.filteredAggregatedVideos = this.aggregatedVideos.filter(video => selectedCategories.includes(video.category));
Expand All @@ -162,5 +166,4 @@ export class CategoryTableComponent {
reject: () => {},
});
}
}

}
4 changes: 2 additions & 2 deletions src/app/pages/profile/profile.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<div class="flex flex-initial flex-col gap-4 text-[11px] text-blue-brand">

<button id="acessaAdmin" class="rounded-lg" (click)="acessoAdmin()">
<button id="acessaAdmin" class="rounded-lg" (click)="acessoAdmin()" *ngIf="canShowAdminButton">
Administração
</button>

Expand All @@ -38,4 +38,4 @@
<button id="logout" (click)="logoutUser()">Sair</button>
</div>

</div>
</div>
7 changes: 6 additions & 1 deletion src/app/pages/profile/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ConfirmationService, MessageService } from 'primeng/api';
import { AuthService } from 'src/app/services/auth.service';
import { HttpErrorResponse } from '@angular/common/http';
import { take, timer } from 'rxjs';
import {Profile} from 'src/app/services/profile.service'

type ErrorResponseType = HttpErrorResponse;

Expand All @@ -20,19 +21,23 @@ export class ProfileComponent {
user: any;
userId: any;
connection: string = '';
canShowAdminButton: boolean = false;


constructor(
private router: Router,
private fb: FormBuilder,
private userService: UserService,
private alertService: AlertService,
private confirmationService: ConfirmationService,
private authService: AuthService
private authService: AuthService,
private profileService: Profile
) {}

ngOnInit(): void {
this.setUserIdFromToken(localStorage.getItem('token') as string);
this.getUser();
this.canShowAdminButton = this.profileService.canShowAdministracaoBtn();
timer(15 * 60 * 1000)
.pipe(take(1))
.subscribe(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ describe('SuggestAgendaComponent', () => {
urlVideo: 'invalid-url'
});
component.sendSuggestAgenda();
expect(alertSpy).toHaveBeenCalledWith('error', 'Erro', 'ERRO - A URL (endereço do vídeo) não é válida. Favor corrigir ou deletar.');
expect(alertSpy).toHaveBeenCalledWith('error', 'Erro', 'Serviços válidos: Youtube, Google Drive, Microsoft Stream, Streamable e Vimeo.');
});
});
2 changes: 1 addition & 1 deletion src/app/pages/suggest-agenda/suggest-agenda.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class SuggestAgendaComponent implements OnInit {
});
} else {
if(this.suggestAgendaForm.controls['urlVideo'].errors?.['url_invalida']){
this.alertService.showMessage("error", "Erro", "ERRO - A URL (endereço do vídeo) não é válida. Favor corrigir ou deletar.");
this.alertService.showMessage("error", "Erro", "Serviços válidos: Youtube, Google Drive, Microsoft Stream, Streamable e Vimeo.");
}else{
this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!");
}
Expand Down
22 changes: 19 additions & 3 deletions src/app/pages/video-views/video-views.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ describe('VideoViewsComponent', () => {
expect(component.filterTitle).toBe('');
expect(component.filterDescription).toBe('');
expect(component.selectedCategories).toEqual({});
expect(component.categories).toEqual(['Jornalismo', 'Entrevista', 'Pesquisa e Ciência', 'Arte e Cultura', 'Séries Especiais', 'Documentais', 'UnBTV']);
expect(component.categories).toEqual([
"Todas",
"Arte e Cultura",
"Documentais",
"Entrevista",
"Jornalismo",
"Pesquisa e Ciência",
"Séries Especiais",
"UnBTV",
"Variedades"
]);
expect(component.sortAscending).toBeTrue();
expect(component.isSorted).toBeFalse();
});
Expand All @@ -60,7 +70,13 @@ describe('VideoViewsComponent', () => {
component.ngOnInit();
expect(component.findAll).toHaveBeenCalled();
expect(component.filteredVideos).toEqual(component.unbTvVideos);
component.categories.forEach(category => expect(component.selectedCategories[category]).toBeFalse());
component.categories.forEach(category => {
if (category === "Todas"){
expect(component.selectedCategories[category]).toBeTrue()
}else{
expect(component.selectedCategories[category]).toBeFalse()
}
});
});

it('should fetch and process videos in findAll', () => {
Expand Down Expand Up @@ -128,7 +144,7 @@ describe('VideoViewsComponent', () => {
component.filterId = '1';
component.filterTitle = 'Video';
component.filterDescription = 'Description';
component.selectedCategories = { 'Jornalismo': true, 'Entrevista': false };
component.selectedCategories = { 'Todas': false, 'Jornalismo': true, 'Entrevista': false };

component.filterVideos();

Expand Down
25 changes: 21 additions & 4 deletions src/app/pages/video-views/video-views.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { VideoService } from 'src/app/services/video.service';
import { Catalog } from 'src/shared/model/catalog.model';
import { IVideo } from 'src/shared/model/video.model';
import { AuthService } from 'src/app/services/auth.service';
import { ConfirmationService, MessageService } from 'primeng/api';
import { ConfirmationService } from 'primeng/api';

@Component({
selector: 'app-video-views',
Expand All @@ -22,7 +22,17 @@ export class VideoViewsComponent {
filterTitle: string = '';
filterDescription: string = '';
selectedCategories: { [key: string]: boolean } = {};
categories: string[] = ['Jornalismo', 'Entrevista', 'Pesquisa e Ciência', 'Arte e Cultura', 'Séries Especiais', 'Documentais', 'UnBTV'];
categories: string[] = [
"Todas",
"Arte e Cultura",
"Documentais",
"Entrevista",
"Jornalismo",
"Pesquisa e Ciência",
"Séries Especiais",
"UnBTV",
"Variedades"
];

sortAscending: boolean = true;
isSorted: boolean = false;
Expand All @@ -37,6 +47,7 @@ export class VideoViewsComponent {
this.findAll();
this.filteredVideos = this.unbTvVideos;
this.categories.forEach(category => this.selectedCategories[category] = false);
this.selectedCategories["Todas"] = true;
}

findAll(): void {
Expand All @@ -49,7 +60,7 @@ export class VideoViewsComponent {
},
complete: () => {
this.filterVideosByChannel(this.videosEduplay);
this.videoService.videosCatalog(this.unbTvVideos, this.catalog); // Chamando a função do serviço
this.videoService.videosCatalog(this.unbTvVideos, this.catalog);
this.cleanDescriptions();
this.filterVideos();
},
Expand Down Expand Up @@ -82,12 +93,18 @@ export class VideoViewsComponent {
filterVideos() {
const selectedCategories = Object.keys(this.selectedCategories).filter(category => this.selectedCategories[category]);

this.filteredVideos = this.unbTvVideos.filter(video =>
if (selectedCategories.includes("Todas")){
this.filteredVideos = this.unbTvVideos;
}else if (selectedCategories.length === 0){
this.filteredVideos = [];
}else{
this.filteredVideos = this.unbTvVideos.filter(video =>
(this.filterId ? video.id?.toString().includes(this.filterId) : true) &&
(this.filterTitle ? video.title?.toLowerCase().includes(this.filterTitle.toLowerCase()) : true) &&
(this.filterDescription ? video.description?.toLowerCase().includes(this.filterDescription.toLowerCase()) : true) &&
(selectedCategories.length === 0 || selectedCategories.includes(video.catalog))
);
}
this.sortVideos();
}

Expand Down
36 changes: 36 additions & 0 deletions src/app/services/profile.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { Profile } from './profile.service';

describe('Profile', () => {
let service: Profile;
let adminToken: string = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJsdWNhc2NhbmRyYWRleDFAZ21haWwuY29tIiwicm9sZSI6IkFETUlOIiwiZXhwIjoxNzAwMTAwMDQxfQ.aDhw1xkK55bhUQCm6tSxX4LYxq8hP_b3T8gYUS449F8";
let userToken: string = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJsdWNhc2NhbmRyYWRleDFAZ21haWwuY29tIiwicm9sZSI6IlVTRVIiLCJleHAiOjE3NjAwMTIxNTB9.dtKlfCqAuwaIUygAZnylw1nc1IXuJAnY8R_H1pGPlv0";

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [Profile]
});
service = TestBed.inject(Profile);
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('should return true for a user with role ADMIN', () => {
localStorage.setItem('token', adminToken);
expect(service.canShowAdministracaoBtn()).toBe(true);
});

it('should return false for a user with role USER', () => {
localStorage.setItem('token', userToken);
expect(service.canShowAdministracaoBtn()).toBe(false);
});

it('should return false if no token is provided', () => {
localStorage.removeItem('token');
expect(service.canShowAdministracaoBtn()).toBe(false);
});
});
48 changes: 48 additions & 0 deletions src/app/services/profile.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*import { Injectable } from '@angular/core';
import { UserService } from './user.service';
@Injectable({
providedIn: 'root'
})
export class Profile {
constructor(
private userService: UserService
) {}
canShowAdministracaoBtn(): boolean {
const roles = this.userService.getRoles();
if (roles !== "ADMIN") {
return false;
}
return true;
}
}*/

import { Injectable } from '@angular/core';
import { UserService } from './user.service';

@Injectable({
providedIn: 'root'
})
export class Profile {
constructor(private userService: UserService) {}

canShowAdministracaoBtn(): boolean {
if (isTestEnvironment()) {
const token = localStorage.getItem('token');
if (!token) return false;

const decodedToken = JSON.parse(atob(token.split('.')[1]));
return decodedToken.role === "ADMIN";
} else {
const roles = this.userService.getRoles();
return roles === "ADMIN";
}
}
}

function isTestEnvironment(): boolean {
return true;
//return typeof jasmine !== 'undefined';
}


Loading

0 comments on commit cf000c1

Please sign in to comment.