From 76b4a355782289ae8d5ea3809df8d4dc0edc6be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor?= Date: Sun, 10 Dec 2023 22:23:23 -0300 Subject: [PATCH] Corrige testes --- .../video-viewer.component.spec.ts | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/app/pages/video-viewer/video-viewer.component.spec.ts b/src/app/pages/video-viewer/video-viewer.component.spec.ts index c07e2897..84ce22e6 100644 --- a/src/app/pages/video-viewer/video-viewer.component.spec.ts +++ b/src/app/pages/video-viewer/video-viewer.component.spec.ts @@ -15,7 +15,7 @@ import { of } from 'rxjs'; import { HttpResponse } from '@angular/common/http'; class VideoServiceMock { - constructor() {} + constructor() { } findVideoById() { return of({}); } @@ -52,6 +52,15 @@ describe('VideoViewerComponent', () => { ); fixture.detectChanges(); videoService = TestBed.inject(VideoService); + navigator.share = () => { + { + return new Promise((resolve, reject) => { + resolve(); + }); + } + }; + + }); class VideoServiceMock { @@ -111,32 +120,34 @@ describe('VideoViewerComponent', () => { it('should return the correct video URL', () => { component.eduplayVideoUrl = 'https://eduplay.rnp.br/portal/video/'; component.idVideo = 190329; - + const expectedUrl = 'https://eduplay.rnp.br/portal/video/190329'; const returnedUrl = component.getVideoUrl(); - + expect(returnedUrl).toEqual(expectedUrl); }); it('should share video with native share API on mobile', fakeAsync(() => { - spyOn(navigator, 'share').and.returnValue(Promise.resolve()); - component.shareVideo(); - tick(); - expect(navigator.share).toHaveBeenCalledWith({ + const shareData = { title: component.video.title, text: component.video.title, url: window.location.href, - }); + }; + spyOn(navigator, 'share').and.callThrough(); + component.shareVideo(); + tick(); + expect(navigator.share).toHaveBeenCalledWith(shareData); })); - + it('should handle unsupported share options gracefully', fakeAsync(() => { spyOn(navigator, 'share').and.returnValue(Promise.reject(new Error('Not supported'))); - spyOn((window as any).navigator.clipboard, 'writeText').and.returnValue(Promise.resolve()); - const consoleWarnSpy = spyOn(console, 'warn'); - + spyOn(navigator.clipboard, 'writeText').and.returnValue(Promise.resolve()); + const consoleWarnSpy = spyOn(console, 'error'); + component.shareVideo(); tick(); - })); - + expect(consoleWarnSpy).toHaveBeenCalledWith('Erro ao compartilhar:', new Error('Not supported')); + })); + });