Skip to content

Commit

Permalink
✅ Corrigindo testes
Browse files Browse the repository at this point in the history
Co-authored-by: Karoline Luz da Conceição <KarolineLuz@users.noreply.github.com>
  • Loading branch information
navicg and KarolineLuz committed Feb 8, 2025
1 parent 6002131 commit 889d2b4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/app/pages/catalog/catalog.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ describe('CatalogComponent', () => {
expect(component.findAll).toHaveBeenCalled();
});

it('should call setUserIdFromToken when token is available', () => {
spyOn(component, 'setUserIdFromToken').and.callThrough();
localStorage.setItem('token', 'mock-token');
component.ngOnInit();
expect(component.setUserIdFromToken).toHaveBeenCalledWith('mock-token');
});

it('should handle invalid token in setUserIdFromToken', () => {
spyOn(console, 'error');
component.setUserIdFromToken(null);
expect(console.error).toHaveBeenCalledWith('Token inválido');
});

it('should handle error in setUserIdFromToken', () => {
spyOn(console, 'error');
component.setUserIdFromToken('invalid-token');
expect(console.error).toHaveBeenCalledWith('Erro ao decodificar token:', jasmine.any(Error));
});

it('should populate videosEduplay and unbTvVideos on findAll success', () => {
const videos: IVideo[] = [
{ id: 1, title: 'Video 1', channels: [{ id: 1, name: 'unbtv' }] },
Expand Down Expand Up @@ -95,6 +114,16 @@ describe('CatalogComponent', () => {
expect(component.filteredVideos).toEqual([component.unbTvVideos[0]]);
});

it('should filter videos by channel in filterVideosByChannel', () => {
const videos: IVideo[] = [
{ id: 1, title: 'Video 1', channels: [{ id: 1, name: 'unbtv' }] },
{ id: 2, title: 'Video 2', channels: [{ id: 2, name: 'other' }] }
];
component.filterVideosByChannel(videos);
expect(component.unbTvVideos.length).toBe(1);
expect(component.unbTvVideos[0].id).toBe(1);
});

it('should navigate to /videos on program click', () => {
const videos: IVideo[] = [{ id: 1, title: 'Video 1', channels: [] }];
component.onProgramClick(videos);
Expand Down

0 comments on commit 889d2b4

Please sign in to comment.