refactor: Retire the use of unmaintained custom-card-helpers (#1956)
- Closes #1295
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { hasAction as customCardHasAction } from '@dermotduffy/custom-card-helpers';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { mock } from 'vitest-mock-extended';
|
||||
import { actionSchema, INTERNAL_CALLBACK_ACTION } from '../../src/config/types';
|
||||
import { actionSchema, INTERNAL_CALLBACK_ACTION } from '../../src/config/types.js';
|
||||
import { hasAction as customCardHasAction } from '../../src/ha/has-action.js';
|
||||
import {
|
||||
convertActionToCardCustomAction,
|
||||
createCameraAction,
|
||||
@@ -19,9 +19,9 @@ import {
|
||||
getActionConfigGivenAction,
|
||||
hasAction,
|
||||
stopEventFromActivatingCardWideActions,
|
||||
} from '../../src/utils/action';
|
||||
} from '../../src/utils/action.js';
|
||||
|
||||
vi.mock('@dermotduffy/custom-card-helpers');
|
||||
vi.mock('../../src/ha/has-action.js');
|
||||
|
||||
describe('convertActionToAdvancedCameraCardCustomAction', () => {
|
||||
it('should skip null action', () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { afterAll, describe, expect, it, vi } from 'vitest';
|
||||
import { AdvancedCameraCardError } from '../../src/types';
|
||||
import { AdvancedCameraCardError } from '../../src/types.js';
|
||||
import {
|
||||
allPromises,
|
||||
arefloatsApproximatelyEqual,
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
contentsChanged,
|
||||
dayToDate,
|
||||
desparsifyArrays,
|
||||
dispatchAdvancedCameraCardEvent,
|
||||
errorToConsole,
|
||||
formatDate,
|
||||
formatDateAndTime,
|
||||
@@ -28,32 +27,8 @@ import {
|
||||
setify,
|
||||
setOrRemoveAttribute,
|
||||
sleep,
|
||||
} from '../../src/utils/basic';
|
||||
import { createSlot, createSlotHost } from '../test-utils';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('dispatchAdvancedCameraCardEvent', () => {
|
||||
it('should dispatch event without data', () => {
|
||||
const element = document.createElement('div');
|
||||
const handler = vi.fn();
|
||||
element.addEventListener('advanced-camera-card:foo', handler);
|
||||
|
||||
dispatchAdvancedCameraCardEvent(element, 'foo');
|
||||
expect(handler).toBeCalled();
|
||||
});
|
||||
|
||||
it('should dispatch event with data', () => {
|
||||
const element = document.createElement('div');
|
||||
const data = { bar: 2 };
|
||||
const handler = vi.fn((ev) => {
|
||||
expect(ev.detail).toBe(data);
|
||||
});
|
||||
|
||||
element.addEventListener('advanced-camera-card:foo', handler);
|
||||
dispatchAdvancedCameraCardEvent(element, 'foo', data);
|
||||
expect(handler).toBeCalled();
|
||||
});
|
||||
});
|
||||
} from '../../src/utils/basic.js';
|
||||
import { createSlot, createSlotHost } from '../test-utils.js';
|
||||
|
||||
describe('prettifyTitle', () => {
|
||||
it('should return undefined when passed undefined', () => {
|
||||
@@ -130,6 +105,7 @@ describe('errorToConsole', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('isHoverableDevice', () => {
|
||||
afterAll(() => {
|
||||
vi.restoreAllMocks();
|
||||
@@ -163,6 +139,7 @@ describe('formatDate', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('runWhenIdleIfSupported', () => {
|
||||
const originalRequestIdleCallback = window.requestIdleCallback;
|
||||
afterAll(() => {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { fireAdvancedCameraCardEvent } from '../../src/utils/fire-advanced-camera-card-event.js';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('fireAdvancedCameraCardEvent', () => {
|
||||
it('should fire event without data', () => {
|
||||
const element = document.createElement('div');
|
||||
const handler = vi.fn();
|
||||
element.addEventListener('advanced-camera-card:foo', handler);
|
||||
|
||||
fireAdvancedCameraCardEvent(element, 'foo');
|
||||
expect(handler).toBeCalled();
|
||||
});
|
||||
|
||||
it('should fire event with data', () => {
|
||||
const element = document.createElement('div');
|
||||
const data = { bar: 2 };
|
||||
const handler = vi.fn((ev) => {
|
||||
expect(ev.detail).toBe(data);
|
||||
});
|
||||
|
||||
element.addEventListener('advanced-camera-card:foo', handler);
|
||||
fireAdvancedCameraCardEvent(element, 'foo', data);
|
||||
expect(handler).toBeCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { HomeAssistant } from '@dermotduffy/custom-card-helpers';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { HomeAssistant } from '../../../src/ha/types.js';
|
||||
import {
|
||||
canonicalizeHAURL,
|
||||
hasHAConnectionStateChanged,
|
||||
|
||||
Reference in New Issue
Block a user