chore: Enforce a few house rules via eslint (#2539)

This commit is contained in:
Dermot Duffy
2026-06-30 17:45:13 -07:00
committed by dermotduffy
parent 5572ec728e
commit 921d45e577
100 changed files with 479 additions and 295 deletions
@@ -56,6 +56,19 @@ describe('MicrophoneActionsController', () => {
expect(microphoneManager.mute).not.toBeCalled();
});
it('should swallow a rejected auto-unmute so a denied microphone does not surface', async () => {
const microphoneManager = createMicrophoneManager();
vi.mocked(microphoneManager.unmute).mockRejectedValue(new Error('denied'));
const controller = new MicrophoneActionsController();
controller.setOptions({
microphoneManager,
autoUnmuteConditions: ['selected' as const],
});
await expect(controller.setSelectedCamera('camera-1')).resolves.toBeUndefined();
expect(microphoneManager.unmute).toBeCalledTimes(1);
});
it('should mute on unselected when transitioning to a new camera', async () => {
const microphoneManager = createMicrophoneManager();
const controller = new MicrophoneActionsController();
@@ -61,7 +61,7 @@ describe('MediaLoadedInfoSinkController', () => {
// Both cached, but only the selected one is exposed.
expect(controller.get()).toBe(infoA);
// Selecting the other target switches what `get()` returns — without a
// Selecting the other target switches what `get()` returns -- without a
// new event arriving for it.
selected = 'target-B';
controller.hostUpdated();
@@ -102,7 +102,7 @@ describe('MediaLoadedInfoSinkController', () => {
controller.hostConnected();
vi.clearAllMocks();
// Load for an unselected target — cached but inactive.
// Load for an unselected target -- cached but inactive.
host.dispatchEvent(
createMediaLoadedInfoEvent({
info: createMediaLoadedInfo({ targetID: 'target-B' }),
@@ -162,7 +162,7 @@ describe('MediaLoadedInfoSinkController', () => {
controller.hostUpdated();
vi.clearAllMocks();
// Switch to another target with no cached info — active stays null.
// Switch to another target with no cached info -- active stays null.
selected = 'target-B';
controller.hostUpdated();
@@ -126,9 +126,9 @@ describe('MediaLoadedInfoSourceController', () => {
});
it('should abort the prior dispatch when targetID changes between calls', () => {
// Without this, the manager would zombie an entry under the old
// targetID — its `onAbort` cleanup never fires because we never aborted
// the prior signal before overwriting `_abort`.
// Without this, the manager would zombie an entry under the old targetID
// -- its `onAbort` cleanup never fires because we never aborted the prior
// signal before overwriting `_abort`.
let targetID: string | null = 'target-1';
const host = createLitElement();
const controller = new MediaLoadedInfoSourceController(host, {
@@ -164,7 +164,7 @@ describe('MediaLoadedInfoSourceController', () => {
controller.set(createMediaLoadedInfo());
const firstSignal = (handler.mock.calls[0][0] as CustomEvent).detail.signal;
// Disconnect and reconnect — without a fresh `set`.
// Disconnect and reconnect -- without a fresh `set`.
controller.hostDisconnected();
controller.hostConnected();
@@ -201,7 +201,7 @@ describe('MediaLoadedInfoSourceController', () => {
host.addEventListener('advanced-camera-card:media:loaded', handler);
controller.set(createMediaLoadedInfo());
// Active registration, no disconnect — connect should be a no-op.
// Active registration, no disconnect -- connect should be a no-op.
controller.hostConnected();
expect(handler).toBeCalledTimes(1);
@@ -228,7 +228,7 @@ describe('MediaLoadedInfoSourceController', () => {
targetID = 'target-2';
controller.hostConnected();
// No re-dispatch — the stale cache was discarded.
// No re-dispatch -- the stale cache was discarded.
expect(handler).toBeCalledTimes(1);
// A subsequent set() under the new target dispatches fresh.
@@ -771,7 +771,7 @@ describe('SignedURLController', () => {
controller.hostUpdate();
expect(createProxiedEndpointIfNecessary).toHaveBeenCalledTimes(1);
// Resolve the original request — should still succeed.
// Resolve the original request -- should still succeed.
resolveProxy?.({ endpoint: 'http://proxied-url.com', sign: false });
await flushPromises();
@@ -809,7 +809,7 @@ describe('SignedURLController', () => {
expect(createProxiedEndpointIfNecessary).toHaveBeenCalledTimes(1);
expect(controller.getValue()).toBe('http://signed.com');
// Change only the extraneous field — should hit the cache, not re-fetch.
// Change only the extraneous field -- should hit the cache, not re-fetch.
extraneous = false;
await controller.hostUpdate();
expect(createProxiedEndpointIfNecessary).toHaveBeenCalledTimes(1);
@@ -314,12 +314,12 @@ describe('StatusBarController', () => {
sufficient: true,
};
// Start with permanent item — bar stays visible.
// Start with permanent item -- bar stays visible.
controller.setItems([permanentItem, nonPermanentItem]);
vi.advanceTimersByTime(10000);
expect(host.getAttribute('hide')).toBe(null);
// Remove permanent item — popup timer starts.
// Remove permanent item -- popup timer starts.
controller.setItems([nonPermanentItem]);
expect(host.getAttribute('hide')).toBe(null);
@@ -342,7 +342,7 @@ describe('StatusBarController', () => {
string: 'Title',
sufficient: true,
};
// A permanent item that is NOT sufficient — removing it does not
// A permanent item that is NOT sufficient -- removing it does not
// change the sufficient-values set, so the popup timer takes the
// dedicated permanent-removal branch.
const permanentInsufficientItem = {
@@ -356,7 +356,7 @@ describe('StatusBarController', () => {
vi.advanceTimersByTime(10000);
expect(host.getAttribute('hide')).toBe(null);
// Remove the permanent (insufficient) item — sufficient values are
// Remove the permanent (insufficient) item -- sufficient values are
// unchanged, but the popup timer must still start.
controller.setItems([sufficientItem]);
expect(host.getAttribute('hide')).toBe(null);
@@ -1,5 +1,5 @@
import { format } from 'date-fns';
import { describe, expect, it } from 'vitest';
import { assert, describe, expect, it } from 'vitest';
import { mock } from 'vitest-mock-extended';
import { CameraManager } from '../../../../src/camera-manager/manager';
import { ThumbnailFeatureController } from '../../../../src/components-lib/thumbnail/feature/controller';
@@ -12,6 +12,8 @@ describe('ThumbnailFeatureController', () => {
title: 'Test Event',
cameraID: 'camera_1',
});
const itemStartTime = itemWithTime.getStartTime();
assert(itemStartTime);
describe('should set title', () => {
it('should set title with start time ', () => {
@@ -20,7 +22,7 @@ describe('ThumbnailFeatureController', () => {
controller.calculate(null, itemWithTime, false);
// Use format() to generate expected time in local timezone
const expectedTime = format(itemWithTime.getStartTime()!, 'HH:mm');
const expectedTime = format(itemStartTime, 'HH:mm');
expect(controller.getTitle()).toBe(expectedTime);
});
@@ -54,7 +56,7 @@ describe('ThumbnailFeatureController', () => {
controller.calculate(null, itemWithTime, false);
// Use format() to generate expected date string (formats in local time)
const expectedDate = format(itemWithTime.getStartTime()!, 'MMM do');
const expectedDate = format(itemStartTime, 'MMM do');
expect(controller.getSubtitles()).toContain(expectedDate);
});