From d23f87a39b9a1b2ddff68c2917fe4c403f191167 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Mon, 2 Oct 2023 19:00:30 -0700 Subject: [PATCH] Fix message on initialization rendering. --- src/utils/card-controller/controller.ts | 1 - src/utils/card-controller/style-manager.ts | 13 +++++++++---- tests/utils/card-controller/style-manager.test.ts | 9 +++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/utils/card-controller/controller.ts b/src/utils/card-controller/controller.ts index 92faea9d..58bab556 100644 --- a/src/utils/card-controller/controller.ts +++ b/src/utils/card-controller/controller.ts @@ -1,4 +1,3 @@ -// TODO: test errors during rendering to make sure resetMessage is no longer necessary. // TODO: Test HA state connection/disconnect logic in real life. // TODO: Should not need to import screenfull anywhere except the fullscreen manager. // TODO: executeMediaQueryForView should not need a HTMLElement host parameter see the view-manager.ts call in particular. diff --git a/src/utils/card-controller/style-manager.ts b/src/utils/card-controller/style-manager.ts index a55695fd..b7eccccd 100644 --- a/src/utils/card-controller/style-manager.ts +++ b/src/utils/card-controller/style-manager.ts @@ -74,7 +74,10 @@ export class StyleManager { ); } - protected _isAspectRatioEnforced(config: FrigateCardConfig, view: View): boolean { + protected _isAspectRatioEnforced( + config: FrigateCardConfig, + view?: View | null, + ): boolean { const aspectRatioMode = config.dimensions.aspect_ratio_mode; // Do not artifically constrain aspect ratio if: @@ -88,8 +91,10 @@ export class StyleManager { this._api.getExpandManager().isExpanded() || aspectRatioMode === 'unconstrained' || (aspectRatioMode === 'dynamic' && - (view.isAnyMediaView() || view.is('timeline'))) || - view.is('diagnostics') + (!view || + view?.isAnyMediaView() || + view?.is('timeline') || + view?.is('diagnostics'))) ); } @@ -102,7 +107,7 @@ export class StyleManager { const config = this._api.getConfigManager().getConfig(); const view = this._api.getViewManager().getView(); - if (config && view) { + if (config) { if (!this._isAspectRatioEnforced(config, view)) { return 'auto'; } diff --git a/tests/utils/card-controller/style-manager.test.ts b/tests/utils/card-controller/style-manager.test.ts index 01ddd8b8..963b0c6b 100644 --- a/tests/utils/card-controller/style-manager.test.ts +++ b/tests/utils/card-controller/style-manager.test.ts @@ -285,6 +285,15 @@ describe('StyleManager', () => { expect(manager.getAspectRatioStyle()).toBe('auto'); }); + it('should be auto when there is yet to be a view', () => { + const api = createCardAPI(); + vi.mocked(api.getViewManager().getView).mockReturnValue(null); + vi.mocked(api.getConfigManager().getConfig).mockReturnValue(createConfig()); + const manager = new StyleManager(api); + + expect(manager.getAspectRatioStyle()).toBe('auto'); + }); + describe('should be auto when dynamic in certain views', () => { it.each([ ['clip' as const],