test: Add a test harness for the built card (#2653)
Mounts the card from `dist/` the way Home Assistant does, by URL with a HACS tag, and asserts the entry stays a facade, that no chunk imports it, that the browser is served the file unmodified, and that the card starts up and fetches a language chunk lazily. Runs in Chromium, Firefox and WebKit, so a change of bundler or minifier is checked against every engine.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { MountedCard } from '../browser/mounted-card';
|
||||
import { MountedCardFactory, type MountedCard } from '../browser/mounted-card';
|
||||
import {
|
||||
createStillCameraHASS,
|
||||
createStillImageCardConfig,
|
||||
@@ -10,7 +10,7 @@ const TRIGGER_ENTITY = 'input_boolean.zoom';
|
||||
|
||||
const mount = async (): Promise<MountedCard> => {
|
||||
const hass = createStillCameraHASS({ entities: { [TRIGGER_ENTITY]: 'off' } });
|
||||
return await MountedCard.create(
|
||||
return await MountedCardFactory.createFromSource(
|
||||
createStillImageCardConfig({
|
||||
automations: [
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it, onTestFinished } from 'vitest';
|
||||
|
||||
import { createLogAction } from '../../src/utils/action';
|
||||
import { MountedCard } from '../browser/mounted-card';
|
||||
import { MountedCardFactory, type MountedCard } from '../browser/mounted-card';
|
||||
import {
|
||||
CARD_INITIALIZED_MESSAGE,
|
||||
createInitializedAutomation,
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
const KEY_MESSAGE = /key pressed/;
|
||||
|
||||
const mountCard = async (): Promise<MountedCard> => {
|
||||
const card = await MountedCard.create(
|
||||
const card = await MountedCardFactory.createFromSource(
|
||||
createStillImageCardConfig({
|
||||
automations: [
|
||||
createInitializedAutomation(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import type { RawAdvancedCameraCardConfig } from '../../../src/config/types';
|
||||
import { MountedCard } from '../../browser/mounted-card';
|
||||
import { MountedCardFactory, type MountedCard } from '../../browser/mounted-card';
|
||||
import {
|
||||
CARD_INITIALIZED_MESSAGE,
|
||||
createInitializedAutomation,
|
||||
@@ -24,7 +24,7 @@ const createConfig = (
|
||||
const mount = async (
|
||||
overrides?: Partial<RawAdvancedCameraCardConfig>,
|
||||
): Promise<MountedCard> =>
|
||||
await MountedCard.create(
|
||||
await MountedCardFactory.createFromSource(
|
||||
createConfig(overrides),
|
||||
createStillCameraHASS({ cameras: [OTHER_CAMERA_ENTITY] }),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { MountedCard } from '../../../browser/mounted-card';
|
||||
import { MountedCardFactory, type MountedCard } from '../../../browser/mounted-card';
|
||||
import {
|
||||
CARD_INITIALIZED_MESSAGE,
|
||||
createInitializedAutomation,
|
||||
@@ -31,7 +31,7 @@ const waitForInitializationFailures = async (card: MountedCard): Promise<void> =
|
||||
* is what makes it initializable, which a test does with `setEntityState`.
|
||||
*/
|
||||
const mountBrokenCard = async (): Promise<MountedCard> =>
|
||||
await MountedCard.create(
|
||||
await MountedCardFactory.createFromSource(
|
||||
createStillImageCardConfig({
|
||||
cameras: [createStillImageCameraConfig(MISSING_CAMERA_ENTITY)],
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@ import { MEDIA_LOADING_TIMEOUT_SECONDS } from '../../../../src/card-controller/i
|
||||
import { LIVENESS_ENTITY_UNAVAILABLE_GRACE_SECONDS } from '../../../../src/components-lib/live/liveness/detectors/entity-availability';
|
||||
import { FRAME_STALL_SECONDS } from '../../../../src/components-lib/media-player/frame-stall-watchdog';
|
||||
import type { RawAdvancedCameraCardConfig } from '../../../../src/config/types';
|
||||
import { MountedCard, type MountOptions } from '../../../browser/mounted-card';
|
||||
import {
|
||||
MountedCardFactory,
|
||||
type MountedCard,
|
||||
type MountOptions,
|
||||
} from '../../../browser/mounted-card';
|
||||
import { useTestMedia } from '../../../browser/test-media';
|
||||
import {
|
||||
createFailingMediaURL,
|
||||
@@ -58,7 +62,7 @@ const mountCard = async (
|
||||
): Promise<MountedCard> => {
|
||||
const { cameras, ...mountOptions } = options ?? {};
|
||||
|
||||
return await MountedCard.create(
|
||||
return await MountedCardFactory.createFromSource(
|
||||
createStillImageCardConfig({ status_bar: { style: 'outside' }, ...config }),
|
||||
createStillCameraHASS({ cameras }),
|
||||
mountOptions,
|
||||
|
||||
@@ -2,7 +2,11 @@ import { assert, describe, expect, it } from 'vitest';
|
||||
|
||||
import type { LogActionConfig } from '../../src/config/schema/actions/custom/log';
|
||||
import { createLogAction } from '../../src/utils/action';
|
||||
import { MountedCard, type MountOptions } from '../browser/mounted-card';
|
||||
import {
|
||||
MountedCardFactory,
|
||||
type MountedCard,
|
||||
type MountOptions,
|
||||
} from '../browser/mounted-card';
|
||||
import {
|
||||
CARD_INITIALIZED_MESSAGE,
|
||||
clickElement,
|
||||
@@ -44,7 +48,7 @@ interface MountCardOptions extends MountOptions {
|
||||
const mountCard = async (options?: MountCardOptions): Promise<MountedCard> => {
|
||||
const { keyMessage, ...mountOptions } = options ?? {};
|
||||
|
||||
const card = await MountedCard.create(
|
||||
const card = await MountedCardFactory.createFromSource(
|
||||
createStillImageCardConfig({
|
||||
menu: { style: 'outside', buttons: { expand: { enabled: true } } },
|
||||
elements: [
|
||||
|
||||
Reference in New Issue
Block a user