Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/material/bottom-sheet/bottom-sheet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {SpyLocation} from '@angular/common/testing';
import {
Component,
ComponentRef,
createNgModuleRef,
createNgModule,
Directive,
Injectable,
Injector,
Expand Down Expand Up @@ -1098,7 +1098,7 @@ class ModuleBoundBottomSheetParentComponent {
private _bottomSheet = inject(MatBottomSheet);

openBottomSheet(): void {
const ngModuleRef = createNgModuleRef(
const ngModuleRef = createNgModule(
ModuleBoundBottomSheetModule,
/* parentInjector */ this._injector,
);
Expand Down
4 changes: 2 additions & 2 deletions src/material/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {SpyLocation} from '@angular/common/testing';
import {
ChangeDetectionStrategy,
Component,
createNgModuleRef,
createNgModule,
Directive,
Injectable,
Injector,
Expand Down Expand Up @@ -2445,7 +2445,7 @@ class ModuleBoundDialogParentComponent {
private _dialog = inject(MatDialog);

openDialog(): void {
const ngModuleRef = createNgModuleRef(
const ngModuleRef = createNgModule(
ModuleBoundDialogModule,
/* parentInjector */ this._injector,
);
Expand Down
39 changes: 22 additions & 17 deletions src/youtube-player/youtube-player.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const TEST_PROVIDERS: (Provider | EnvironmentProviders)[] = [
];

describe('YoutubePlayer', () => {
const ytWindow = window as Window &
typeof globalThis & {
YT?: typeof YT | undefined;
onYouTubeIframeAPIReady?: (() => void) | undefined;
};
let playerCtorSpy: jasmine.Spy;
let playerSpy: jasmine.SpyObj<YT.Player>;
let fixture: ComponentFixture<TestApp>;
Expand All @@ -35,7 +40,7 @@ describe('YoutubePlayer', () => {
const fake = createFakeYtNamespace();
playerCtorSpy = fake.playerCtorSpy;
playerSpy = fake.playerSpy;
window.YT = fake.namespace;
ytWindow.YT = fake.namespace;
events = fake.events;
}));

Expand All @@ -58,8 +63,8 @@ describe('YoutubePlayer', () => {
});

afterEach(() => {
window.YT = undefined;
window.onYouTubeIframeAPIReady = undefined;
ytWindow.YT = undefined!;
ytWindow.onYouTubeIframeAPIReady = undefined;
});

it('initializes a youtube player when the placeholder is clicked', () => {
Expand Down Expand Up @@ -215,7 +220,7 @@ describe('YoutubePlayer', () => {

expect(playerSpy.cueVideoById).not.toHaveBeenCalled();

playerSpy.getPlayerState.and.returnValue(window.YT!.PlayerState.CUED);
playerSpy.getPlayerState.and.returnValue(ytWindow.YT!.PlayerState.CUED);
events.onReady({target: playerSpy});

expect(playerSpy.cueVideoById).toHaveBeenCalledWith(
Expand Down Expand Up @@ -542,17 +547,17 @@ describe('YoutubePlayer', () => {
let api: typeof YT;

beforeEach(() => {
api = window.YT!;
window.YT = undefined;
api = ytWindow.YT!;
ytWindow.YT = undefined!;
});

afterEach(() => {
window.YT = undefined;
window.onYouTubeIframeAPIReady = undefined;
ytWindow.YT = undefined!;
ytWindow.onYouTubeIframeAPIReady = undefined;
});

it('waits until the api is ready before initializing', () => {
window.YT = YT_LOADING_STATE_MOCK;
ytWindow.YT = YT_LOADING_STATE_MOCK;
TestBed.configureTestingModule({providers: TEST_PROVIDERS});
fixture = TestBed.createComponent(TestApp);
testComponent = fixture.debugElement.componentInstance;
Expand All @@ -562,8 +567,8 @@ describe('YoutubePlayer', () => {

expect(playerCtorSpy).not.toHaveBeenCalled();

window.YT = api;
window.onYouTubeIframeAPIReady!();
ytWindow.YT = api;
ytWindow.onYouTubeIframeAPIReady!();

expect(playerCtorSpy).toHaveBeenCalledWith(
getVideoHost(fixture),
Expand All @@ -577,7 +582,7 @@ describe('YoutubePlayer', () => {

it('should not override any pre-existing API loaded callbacks', () => {
const spy = jasmine.createSpy('other API loaded spy');
window.onYouTubeIframeAPIReady = spy;
ytWindow.onYouTubeIframeAPIReady = spy;
TestBed.configureTestingModule({providers: TEST_PROVIDERS});
fixture = TestBed.createComponent(TestApp);
testComponent = fixture.debugElement.componentInstance;
Expand All @@ -587,8 +592,8 @@ describe('YoutubePlayer', () => {

expect(playerCtorSpy).not.toHaveBeenCalled();

window.YT = api;
window.onYouTubeIframeAPIReady!();
ytWindow.YT = api;
ytWindow.onYouTubeIframeAPIReady!();

expect(spy).toHaveBeenCalled();
});
Expand All @@ -603,7 +608,7 @@ describe('YoutubePlayer', () => {
});

afterEach(() => {
fixture = testComponent = window.YT = window.onYouTubeIframeAPIReady = undefined!;
fixture = testComponent = ytWindow.YT = ytWindow.onYouTubeIframeAPIReady = undefined!;
});

it('should show a placeholder', () => {
Expand Down Expand Up @@ -687,7 +692,7 @@ describe('YoutubePlayer', () => {
fixture.detectChanges();

// Simulate player state being PLAYING (autoplay has started the video)
playerSpy.getPlayerState.and.returnValue(window.YT!.PlayerState.PLAYING);
playerSpy.getPlayerState.and.returnValue(ytWindow.YT!.PlayerState.PLAYING);
events.onReady({target: playerSpy});

// Should use seekTo instead of cueVideoById when player is already playing
Expand Down Expand Up @@ -724,7 +729,7 @@ describe('YoutubePlayer', () => {
getPlaceholder(staticSecondsApp).click();
staticSecondsApp.detectChanges();

playerSpy.getPlayerState.and.returnValue(window.YT!.PlayerState.CUED);
playerSpy.getPlayerState.and.returnValue(ytWindow.YT!.PlayerState.CUED);
events.onReady({target: playerSpy});

expect(playerSpy.cueVideoById).toHaveBeenCalledWith(
Expand Down
15 changes: 6 additions & 9 deletions src/youtube-player/youtube-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ import {Observable, of as observableOf, Subject, BehaviorSubject, fromEventPatte
import {takeUntil, switchMap} from 'rxjs/operators';
import {PlaceholderImageQuality, YouTubePlayerPlaceholder} from './youtube-player-placeholder';

declare global {
interface Window {
YT: typeof YT | undefined;
onYouTubeIframeAPIReady: (() => void) | undefined;
}
}
type YoutubeWindow = {
onYouTubeIframeAPIReady?: (() => void) | undefined;
};

/** Injection token used to configure the `YouTubePlayer`. */
export const YOUTUBE_PLAYER_CONFIG = new InjectionToken<YouTubePlayerConfig>(
Expand Down Expand Up @@ -292,7 +289,7 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {

if (this._player) {
this._player.destroy();
window.onYouTubeIframeAPIReady = this._existingApiReadyCallback;
(window as YoutubeWindow).onYouTubeIframeAPIReady = this._existingApiReadyCallback;
}

this._playerChanges.complete();
Expand Down Expand Up @@ -513,9 +510,9 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
);
}

this._existingApiReadyCallback = window.onYouTubeIframeAPIReady;
this._existingApiReadyCallback = (window as YoutubeWindow).onYouTubeIframeAPIReady;

window.onYouTubeIframeAPIReady = () => {
(window as YoutubeWindow).onYouTubeIframeAPIReady = () => {
this._existingApiReadyCallback?.();
this._ngZone.run(() => this._createPlayer(playVideo));
};
Expand Down
Loading