From f576bc8cee5fde3a3b2de60a3abcbdc90557a696 Mon Sep 17 00:00:00 2001 From: Christopher <105730846+wChrstphr@users.noreply.github.com> Date: Fri, 7 Feb 2025 15:52:25 -0300 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=94=A5=20Removendo=20pasta=20test-rep?= =?UTF-8?q?orts/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test-reports/TESTS.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test-reports/TESTS.xml diff --git a/test-reports/TESTS.xml b/test-reports/TESTS.xml deleted file mode 100644 index e69de29b..00000000 From 4b90ac9e9c567b9463bbca9fed5d3b99590abec3 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 7 Feb 2025 15:54:39 -0300 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9C=85=20Adicionando=20testes=20para=20o?= =?UTF-8?q?=20modo=20dark=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../background/background.component.spec.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/app/components/background/background.component.spec.ts b/src/app/components/background/background.component.spec.ts index fd19a8d2..f3d03a9f 100644 --- a/src/app/components/background/background.component.spec.ts +++ b/src/app/components/background/background.component.spec.ts @@ -92,4 +92,24 @@ describe('BackgroundComponent', () => { component.ngOnDestroy(); expect(unsubscribeSpy).toHaveBeenCalled(); }); + + it('should toggle dark mode', () => { + // Simula a ativação do modo escuro + let isChecked = true; + let event = { target: { checked: isChecked } } as unknown as Event; + + component.toggleDarkMode(event); + expect(document.documentElement.classList.contains('dark-theme')).toBeTrue(); + expect(component.isDarkMode).toBeTrue(); + expect(localStorage.getItem('theme')).toBe('dark'); + + // Simula a desativação do modo escuro + isChecked = false; + event = { target: { checked: isChecked } } as unknown as Event; + + component.toggleDarkMode(event); + expect(document.documentElement.classList.contains('dark-theme')).toBeFalse(); + expect(component.isDarkMode).toBeFalse(); + expect(localStorage.getItem('theme')).toBe('light'); + }); }); From fec87fe888081d7374c0d453c8c02aaf52123dd3 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 7 Feb 2025 17:19:19 -0300 Subject: [PATCH 3/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refatorando=20l=C3=B3g?= =?UTF-8?q?ica=20para=20notifica=C3=A7=C3=A3o=20de=20v=C3=ADdeos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/components/background/background.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/background/background.component.ts b/src/app/components/background/background.component.ts index afebb4bc..d7cc2af1 100644 --- a/src/app/components/background/background.component.ts +++ b/src/app/components/background/background.component.ts @@ -116,7 +116,7 @@ export class BackgroundComponent implements OnInit, OnDestroy { } updateNotificationCount(response: any): void { - if (response?.recommend_videos) { + if (response?.recommend_videos && response.recommend_videos.length > 0) { const count = response.recommend_videos.length; console.log('Updating notification count with:', count); this.hasNotifications = count > 0; From 8acb005720d1fe30f637909ac01dfe9b0c0ba46c Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 7 Feb 2025 18:13:56 -0300 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9C=85=20Complementando=20testes=20do=20?= =?UTF-8?q?background.component.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../background/background.component.spec.ts | 110 +++++++++++++++++- 1 file changed, 108 insertions(+), 2 deletions(-) diff --git a/src/app/components/background/background.component.spec.ts b/src/app/components/background/background.component.spec.ts index f3d03a9f..acec9d25 100644 --- a/src/app/components/background/background.component.spec.ts +++ b/src/app/components/background/background.component.spec.ts @@ -4,7 +4,7 @@ import { RouterTestingModule } from '@angular/router/testing'; import { MenuModule } from 'primeng/menu'; import { NotificationService } from 'src/app/services/notification.service'; import { HttpClientTestingModule } from '@angular/common/http/testing'; -import { of } from 'rxjs'; +import { of, BehaviorSubject } from 'rxjs'; describe('BackgroundComponent', () => { let component: BackgroundComponent; @@ -51,6 +51,15 @@ describe('BackgroundComponent', () => { expect(component.hasNotifications).toBeTrue(); // Verifica se as notificações foram atualizadas })); + it('should log "User is not authenticated" when user is not authenticated', () => { + (notificationService.isAuthenticated as jasmine.Spy).and.returnValue(false); + spyOn(console, 'log'); + + component.ngOnInit(); + + expect(console.log).toHaveBeenCalledWith('User is not authenticated'); + }); + it('should correctly update the notification count', fakeAsync(() => { const response = { recommend_videos: [{}, {}, {}] }; component.updateNotificationCount(response); @@ -112,4 +121,101 @@ describe('BackgroundComponent', () => { expect(component.isDarkMode).toBeFalse(); expect(localStorage.getItem('theme')).toBe('light'); }); -}); + + it('should add "dark-theme" class to document element when applyTheme is called with true', () => { + document.documentElement.classList.remove('dark-theme'); // Ensure the class is not present + expect(document.documentElement.classList.contains('dark-theme')).toBeFalse(); + + component.isDarkMode = true; // Defina isDarkMode como true + component.applyTheme(); + + expect(document.documentElement.classList.contains('dark-theme')).toBeTrue(); + }); + + it('should remove "dark-theme" class from document element when applyTheme is called with false', () => { + document.documentElement.classList.add('dark-theme'); // Ensure the class is present + expect(document.documentElement.classList.contains('dark-theme')).toBeTrue(); + + component.isDarkMode = false; // Defina isDarkMode como false + component.applyTheme(); + + expect(document.documentElement.classList.contains('dark-theme')).toBeFalse(); + }); + + it('should fetch recommended videos count at intervals', fakeAsync(() => { + const mockToken = 'mockToken'; + const mockUserId = 'mockUserId'; + const mockResponse = 5; + const mockCount = new BehaviorSubject(0); + + spyOn(localStorage, 'getItem').and.returnValue(mockToken); + (notificationService.isAuthenticated as jasmine.Spy).and.returnValue(true); + (notificationService.setUserIdFromToken as jasmine.Spy).and.callFake(() => { + notificationService.userId = mockUserId; + }); + (notificationService.fetchRecommendedVideosCount as jasmine.Spy).and.returnValue(of(mockResponse)); + notificationService.recommendedVideosCount$ = mockCount.asObservable(); + + spyOn(component, 'updateNotificationCount'); + spyOn(component, 'updateNotificationLabel'); + + component.ngOnInit(); + + // Simula a passagem do tempo + tick(300000); + + expect(notificationService.isAuthenticated).toHaveBeenCalled(); + expect(localStorage.getItem).toHaveBeenCalledWith('token'); + expect(notificationService.setUserIdFromToken).toHaveBeenCalledWith(mockToken); + expect(notificationService.fetchRecommendedVideosCount).toHaveBeenCalledWith(mockUserId); + expect(component.updateNotificationCount).toHaveBeenCalledWith(mockResponse); + + // Simula a emissão de um novo valor pelo BehaviorSubject + mockCount.next(3); + tick(); + + expect(component.hasNotifications).toBeTrue(); + expect(component.updateNotificationLabel).toHaveBeenCalled(); + + // Interrompendo qualquer timer ativo + component.ngOnDestroy(); + tick(300000); // Avança o tempo para garantir que o timer foi limpo + })); + + it('should update notification count when there are recommended videos', () => { + const response = { recommend_videos: [{}, {}, {}] }; + spyOn(console, 'log'); + spyOn(component, 'updateNotificationLabel'); + + component.updateNotificationCount(response); + + expect(console.log).toHaveBeenCalledWith('Updating notification count with:', 3); + expect(component.hasNotifications).toBeTrue(); + expect(notificationService.updateRecommendedVideosCount).toHaveBeenCalledWith(3); + expect(component.updateNotificationLabel).toHaveBeenCalled(); + }); + + it('should log "No videos found in response" and update notifications when no videos are found', () => { + const response = { recommend_videos: [] }; + spyOn(console, 'log'); + spyOn(component, 'updateNotificationLabel'); + + component.updateNotificationCount(response); + + expect(console.log).toHaveBeenCalledWith('No videos found in response'); + expect(component.hasNotifications).toBeFalse(); + expect(component.updateNotificationLabel).toHaveBeenCalled(); + }); + + it('should log "No videos found in response" and update notifications when response is null', () => { + const response = null; + spyOn(console, 'log'); + spyOn(component, 'updateNotificationLabel'); + + component.updateNotificationCount(response); + + expect(console.log).toHaveBeenCalledWith('No videos found in response'); + expect(component.hasNotifications).toBeFalse(); + expect(component.updateNotificationLabel).toHaveBeenCalled(); + }); +}); \ No newline at end of file