Fix message on initialization rendering.

This commit is contained in:
Dermot Duffy
2023-10-02 19:00:30 -07:00
parent a3b1e5f834
commit d23f87a39b
3 changed files with 18 additions and 5 deletions
-1
View File
@@ -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: Test HA state connection/disconnect logic in real life.
// TODO: Should not need to import screenfull anywhere except the fullscreen manager. // 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. // TODO: executeMediaQueryForView should not need a HTMLElement host parameter see the view-manager.ts call in particular.
+9 -4
View File
@@ -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; const aspectRatioMode = config.dimensions.aspect_ratio_mode;
// Do not artifically constrain aspect ratio if: // Do not artifically constrain aspect ratio if:
@@ -88,8 +91,10 @@ export class StyleManager {
this._api.getExpandManager().isExpanded() || this._api.getExpandManager().isExpanded() ||
aspectRatioMode === 'unconstrained' || aspectRatioMode === 'unconstrained' ||
(aspectRatioMode === 'dynamic' && (aspectRatioMode === 'dynamic' &&
(view.isAnyMediaView() || view.is('timeline'))) || (!view ||
view.is('diagnostics') view?.isAnyMediaView() ||
view?.is('timeline') ||
view?.is('diagnostics')))
); );
} }
@@ -102,7 +107,7 @@ export class StyleManager {
const config = this._api.getConfigManager().getConfig(); const config = this._api.getConfigManager().getConfig();
const view = this._api.getViewManager().getView(); const view = this._api.getViewManager().getView();
if (config && view) { if (config) {
if (!this._isAspectRatioEnforced(config, view)) { if (!this._isAspectRatioEnforced(config, view)) {
return 'auto'; return 'auto';
} }
@@ -285,6 +285,15 @@ describe('StyleManager', () => {
expect(manager.getAspectRatioStyle()).toBe('auto'); 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', () => { describe('should be auto when dynamic in certain views', () => {
it.each([ it.each([
['clip' as const], ['clip' as const],