test: Split test utilities to improve test times (#2622)
This commit is contained in:
@@ -19,7 +19,7 @@ describe('FullscreenManager', () => {
|
||||
const manager = new FullscreenManager(api, mock<FullscreenProvider>());
|
||||
|
||||
manager.initialize();
|
||||
expect(api.getConditionStateManager().setState).toBeCalledWith({
|
||||
expect(api.getConditionStateManager().setState).toHaveBeenCalledWith({
|
||||
fullscreen: false,
|
||||
});
|
||||
});
|
||||
@@ -49,7 +49,7 @@ describe('FullscreenManager', () => {
|
||||
|
||||
manager.toggleFullscreen();
|
||||
|
||||
expect(provider.setFullscreen).toBeCalledWith(expected);
|
||||
expect(provider.setFullscreen).toHaveBeenCalledWith(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('FullscreenManager', () => {
|
||||
|
||||
manager.setFullscreen(fullscreen);
|
||||
|
||||
expect(provider.setFullscreen).toBeCalledWith(fullscreen);
|
||||
expect(provider.setFullscreen).toHaveBeenCalledWith(fullscreen);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('FullscreenManager', () => {
|
||||
|
||||
manager.connect();
|
||||
|
||||
expect(provider.connect).toBeCalled();
|
||||
expect(provider.connect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
@@ -79,7 +79,7 @@ describe('FullscreenManager', () => {
|
||||
|
||||
manager.disconnect();
|
||||
|
||||
expect(provider.disconnect).toBeCalled();
|
||||
expect(provider.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('should confirm whether fullscreen is supported', () => {
|
||||
@@ -137,7 +137,7 @@ describe('FullscreenManager', () => {
|
||||
|
||||
handler();
|
||||
|
||||
expect(api.getConditionStateManager().setState).toBeCalledWith({
|
||||
expect(api.getConditionStateManager().setState).toHaveBeenCalledWith({
|
||||
fullscreen: fullscreen,
|
||||
});
|
||||
});
|
||||
@@ -148,6 +148,9 @@ describe('FullscreenManager', () => {
|
||||
|
||||
new FullscreenManager(api);
|
||||
|
||||
expect(FullscreenProviderFactory.create).toBeCalledWith(api, expect.anything());
|
||||
expect(FullscreenProviderFactory.create).toHaveBeenCalledWith(
|
||||
api,
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('ScreenfullFullScreenProvider', () => {
|
||||
|
||||
provider.connect();
|
||||
|
||||
expect(on).toBeCalledWith('change', expect.anything());
|
||||
expect(on).toHaveBeenCalledWith('change', expect.anything());
|
||||
});
|
||||
|
||||
it('should not connect if not enabled', () => {
|
||||
@@ -52,7 +52,7 @@ describe('ScreenfullFullScreenProvider', () => {
|
||||
|
||||
provider.connect();
|
||||
|
||||
expect(on).not.toBeCalled();
|
||||
expect(on).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,7 +65,7 @@ describe('ScreenfullFullScreenProvider', () => {
|
||||
|
||||
provider.disconnect();
|
||||
|
||||
expect(off).toBeCalledWith('change', expect.anything());
|
||||
expect(off).toHaveBeenCalledWith('change', expect.anything());
|
||||
});
|
||||
|
||||
it('should not disconnect if not enabled', () => {
|
||||
@@ -76,7 +76,7 @@ describe('ScreenfullFullScreenProvider', () => {
|
||||
|
||||
provider.disconnect();
|
||||
|
||||
expect(off).not.toBeCalled();
|
||||
expect(off).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -138,7 +138,7 @@ describe('ScreenfullFullScreenProvider', () => {
|
||||
|
||||
provider.setFullscreen(true);
|
||||
|
||||
expect(screenfull.request).toBeCalledWith(element);
|
||||
expect(screenfull.request).toHaveBeenCalledWith(element);
|
||||
});
|
||||
|
||||
it('should exit fullscreen if fullscreen is false', () => {
|
||||
@@ -148,7 +148,7 @@ describe('ScreenfullFullScreenProvider', () => {
|
||||
|
||||
provider.setFullscreen(false);
|
||||
|
||||
expect(screenfull.exit).toBeCalled();
|
||||
expect(screenfull.exit).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should take no action if not supported', () => {
|
||||
@@ -162,8 +162,8 @@ describe('ScreenfullFullScreenProvider', () => {
|
||||
provider.setFullscreen(true);
|
||||
provider.setFullscreen(false);
|
||||
|
||||
expect(screenfull.request).not.toBeCalled();
|
||||
expect(screenfull.exit).not.toBeCalled();
|
||||
expect(screenfull.request).not.toHaveBeenCalled();
|
||||
expect(screenfull.exit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should swallow a rejected fullscreen request', async () => {
|
||||
@@ -177,7 +177,7 @@ describe('ScreenfullFullScreenProvider', () => {
|
||||
provider.setFullscreen(true);
|
||||
await flushPromises();
|
||||
|
||||
expect(screenfull.request).toBeCalledWith(element);
|
||||
expect(screenfull.request).toHaveBeenCalledWith(element);
|
||||
});
|
||||
|
||||
it('should swallow a rejected fullscreen exit', async () => {
|
||||
@@ -188,7 +188,7 @@ describe('ScreenfullFullScreenProvider', () => {
|
||||
provider.setFullscreen(false);
|
||||
await flushPromises();
|
||||
|
||||
expect(screenfull.exit).toBeCalled();
|
||||
expect(screenfull.exit).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -40,7 +40,9 @@ describe('WebkitFullScreenProvider', () => {
|
||||
|
||||
provider.connect();
|
||||
|
||||
expect(api.getConditionStateManager().addListener).toBeCalledWith(expect.anything());
|
||||
expect(api.getConditionStateManager().addListener).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
@@ -49,7 +51,7 @@ describe('WebkitFullScreenProvider', () => {
|
||||
|
||||
provider.disconnect();
|
||||
|
||||
expect(api.getConditionStateManager().removeListener).toBeCalledWith(
|
||||
expect(api.getConditionStateManager().removeListener).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
@@ -110,7 +112,7 @@ describe('WebkitFullScreenProvider', () => {
|
||||
|
||||
provider.setFullscreen(true);
|
||||
|
||||
expect(element.webkitEnterFullscreen).toBeCalled();
|
||||
expect(element.webkitEnterFullscreen).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should exit fullscreen if fullscreen is true', () => {
|
||||
@@ -130,7 +132,7 @@ describe('WebkitFullScreenProvider', () => {
|
||||
|
||||
provider.setFullscreen(false);
|
||||
|
||||
expect(element.webkitExitFullscreen).toBeCalled();
|
||||
expect(element.webkitExitFullscreen).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should take no action if not supported', () => {
|
||||
@@ -152,8 +154,8 @@ describe('WebkitFullScreenProvider', () => {
|
||||
provider.setFullscreen(true);
|
||||
provider.setFullscreen(false);
|
||||
|
||||
expect(element.webkitEnterFullscreen).not.toBeCalled();
|
||||
expect(element.webkitExitFullscreen).not.toBeCalled();
|
||||
expect(element.webkitEnterFullscreen).not.toHaveBeenCalled();
|
||||
expect(element.webkitExitFullscreen).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should take no action if element is not a video', () => {
|
||||
@@ -175,8 +177,8 @@ describe('WebkitFullScreenProvider', () => {
|
||||
provider.setFullscreen(true);
|
||||
provider.setFullscreen(false);
|
||||
|
||||
expect(element.webkitEnterFullscreen).not.toBeCalled();
|
||||
expect(element.webkitExitFullscreen).not.toBeCalled();
|
||||
expect(element.webkitEnterFullscreen).not.toHaveBeenCalled();
|
||||
expect(element.webkitExitFullscreen).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -205,7 +207,7 @@ describe('WebkitFullScreenProvider', () => {
|
||||
|
||||
element_1.dispatchEvent(new Event(event));
|
||||
|
||||
expect(handler).toBeCalledTimes(1);
|
||||
expect(handler).toHaveBeenCalledTimes(1);
|
||||
|
||||
const element_2 = createWebkitVideoElement();
|
||||
const mediaPlayerController_2 = mock<MediaPlayerController>();
|
||||
@@ -218,12 +220,12 @@ describe('WebkitFullScreenProvider', () => {
|
||||
|
||||
element_2.dispatchEvent(new Event(event));
|
||||
|
||||
expect(handler).toBeCalledTimes(2);
|
||||
expect(handler).toHaveBeenCalledTimes(2);
|
||||
|
||||
// Events on the old element should be ignored.
|
||||
element_1.dispatchEvent(new Event(event));
|
||||
|
||||
expect(handler).toBeCalledTimes(2);
|
||||
expect(handler).toHaveBeenCalledTimes(2);
|
||||
|
||||
// Test the media loaded info changing, but the player not changing.
|
||||
stateManager.setState({
|
||||
@@ -233,7 +235,7 @@ describe('WebkitFullScreenProvider', () => {
|
||||
// Events on the new element should still be handled.
|
||||
element_2.dispatchEvent(new Event(event));
|
||||
|
||||
expect(handler).toBeCalledTimes(3);
|
||||
expect(handler).toHaveBeenCalledTimes(3);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -265,11 +267,11 @@ describe('WebkitFullScreenProvider', () => {
|
||||
|
||||
element.dispatchEvent(new Event('webkitendfullscreen'));
|
||||
|
||||
expect(element.play).not.toBeCalled();
|
||||
expect(element.play).not.toHaveBeenCalled();
|
||||
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(element.play).toBeCalled();
|
||||
expect(element.play).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should swallow a rejected video replay after fullscreen ends', async () => {
|
||||
@@ -295,6 +297,6 @@ describe('WebkitFullScreenProvider', () => {
|
||||
vi.runOnlyPendingTimers();
|
||||
await flushPromises();
|
||||
|
||||
expect(element.play).toBeCalled();
|
||||
expect(element.play).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user