feat: Add hardened error handling and retries (#2451)
- Closes #1830 - Closes #2099
This commit is contained in:
committed by
dermotduffy
parent
4bc787e2b7
commit
47bcce93d3
@@ -1,34 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { hasHAConnectionStateChanged } from '../../src/ha/has-hass-connection-changed';
|
||||
import { createHASS } from '../test-utils';
|
||||
|
||||
describe('hasHAConnectionStateChanged', () => {
|
||||
it('returns false if both oldHass and newHass are undefined', () => {
|
||||
expect(hasHAConnectionStateChanged()).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if both oldHass and newHass are null', () => {
|
||||
expect(hasHAConnectionStateChanged(null, null)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if both oldHass and newHass are the same object', () => {
|
||||
const hass = createHASS();
|
||||
expect(hasHAConnectionStateChanged(hass, hass)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if both oldHass.connected and newHass.connected are the same', () => {
|
||||
const oldHass = createHASS();
|
||||
const newHass = createHASS();
|
||||
oldHass.connected = true;
|
||||
newHass.connected = true;
|
||||
expect(hasHAConnectionStateChanged(oldHass, newHass)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true if oldHass.connected and newHass.connected are different', () => {
|
||||
const oldHass = createHASS();
|
||||
const newHass = createHASS();
|
||||
oldHass.connected = true;
|
||||
newHass.connected = false;
|
||||
expect(hasHAConnectionStateChanged(oldHass, newHass)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -14,12 +14,12 @@ describe('sideLoadHomeAssistantElements', () => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it('returns true if all elements already registered', async () => {
|
||||
it('should return if all elements already registered', async () => {
|
||||
vi.mocked(customElements.get).mockResolvedValue(LitElement);
|
||||
expect(await sideLoadHomeAssistantElements()).toBe(true);
|
||||
await sideLoadHomeAssistantElements();
|
||||
});
|
||||
|
||||
it('returns false when the picture glance card cannot be found', async () => {
|
||||
it('should throw when the picture glance card cannot be found', async () => {
|
||||
vi.mocked(customElements.get).mockReturnValue(undefined);
|
||||
|
||||
const createCardElement = vi.fn();
|
||||
@@ -29,10 +29,10 @@ describe('sideLoadHomeAssistantElements', () => {
|
||||
}),
|
||||
});
|
||||
|
||||
expect(await sideLoadHomeAssistantElements()).toBe(false);
|
||||
await expect(sideLoadHomeAssistantElements()).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('returns true when elements are loaded', async () => {
|
||||
it('should return when elements are loaded', async () => {
|
||||
vi.mocked(customElements.get).mockImplementation((name: string) => {
|
||||
if (name === 'hui-picture-glance-card') {
|
||||
const result = LitElement;
|
||||
@@ -50,7 +50,7 @@ describe('sideLoadHomeAssistantElements', () => {
|
||||
}),
|
||||
});
|
||||
|
||||
expect(await sideLoadHomeAssistantElements()).toBe(true);
|
||||
await sideLoadHomeAssistantElements();
|
||||
|
||||
expect(customElements.whenDefined).toHaveBeenCalledWith('hui-picture-glance-card');
|
||||
expect(createCardElement).toHaveBeenCalledWith({
|
||||
|
||||
Reference in New Issue
Block a user