test: Split test utilities to improve test times (#2622)
This commit is contained in:
@@ -31,7 +31,7 @@ describe('ConfigUpgradeFailureIssue', () => {
|
||||
await issue.detectStatic();
|
||||
|
||||
expect(issue.hasIssue()).toBe(true);
|
||||
expect(hasConfigUpgradeFailures).toBeCalledWith(rawConfig);
|
||||
expect(hasConfigUpgradeFailures).toHaveBeenCalledWith(rawConfig);
|
||||
expect(issue.getIssue()).toEqual(
|
||||
expect.objectContaining({
|
||||
icon: 'mdi:update',
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('ConfigUpgradeIssue', () => {
|
||||
await issue.detectStatic();
|
||||
|
||||
expect(issue.hasIssue()).toBe(true);
|
||||
expect(isConfigUpgradeable).toBeCalledWith(rawConfig);
|
||||
expect(isConfigUpgradeable).toHaveBeenCalledWith(rawConfig);
|
||||
});
|
||||
|
||||
it('should detect non-upgradeable config', async () => {
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('EventSubscriptionIssue', () => {
|
||||
|
||||
new EventSubscriptionIssue(health, changeCallback);
|
||||
|
||||
expect(health.addListener).toBeCalledWith(changeCallback);
|
||||
expect(health.addListener).toHaveBeenCalledWith(changeCallback);
|
||||
});
|
||||
|
||||
it('should have no issue when there are no failures', () => {
|
||||
@@ -65,7 +65,7 @@ describe('EventSubscriptionIssue', () => {
|
||||
const issue = new EventSubscriptionIssue(health, vi.fn());
|
||||
|
||||
expect(issue.retry()).toBe(true);
|
||||
expect(health.retry).toBeCalledTimes(1);
|
||||
expect(health.retry).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not opt into IssueManager-scheduled retries', () => {
|
||||
@@ -84,6 +84,6 @@ describe('EventSubscriptionIssue', () => {
|
||||
|
||||
issue.destroy();
|
||||
|
||||
expect(unsubscribe).toBeCalledTimes(1);
|
||||
expect(unsubscribe).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -77,7 +77,7 @@ describe('InitializationIssue', () => {
|
||||
const tapAction = control.actions?.tap_action as InternalCallbackActionConfig;
|
||||
await tapAction.callback(api);
|
||||
|
||||
expect(api.getIssueManager().retry).toBeCalledWith('initialization', true);
|
||||
expect(api.getIssueManager().retry).toHaveBeenCalledWith('initialization', true);
|
||||
});
|
||||
|
||||
describe('detectDynamic', () => {
|
||||
@@ -190,8 +190,8 @@ describe('InitializationIssue', () => {
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(issue.hasIssue()).toBe(false);
|
||||
expect(api.getInitializationManager().uninitializeMandatory).toBeCalled();
|
||||
expect(api.getCameraManager().destroy).toBeCalled();
|
||||
expect(api.getInitializationManager().uninitializeMandatory).toHaveBeenCalled();
|
||||
expect(api.getCameraManager().destroy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should be a no-op while a retry is already in flight', () => {
|
||||
@@ -205,8 +205,10 @@ describe('InitializationIssue', () => {
|
||||
const result = issue.retry();
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(api.getInitializationManager().uninitializeMandatory).not.toBeCalled();
|
||||
expect(api.getCameraManager().destroy).not.toBeCalled();
|
||||
expect(
|
||||
api.getInitializationManager().uninitializeMandatory,
|
||||
).not.toHaveBeenCalled();
|
||||
expect(api.getCameraManager().destroy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -179,14 +179,14 @@ describe('LegacyResourceIssue', () => {
|
||||
const result = await issue.fix(hass);
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(hass.callWS).toBeCalledWith(
|
||||
expect(hass.callWS).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'lovelace/resources/delete',
|
||||
resource_id: '1',
|
||||
}),
|
||||
);
|
||||
expect(issue.hasIssue()).toBe(false);
|
||||
expect(onChange).toBeCalled();
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not fix when only legacy resource exists', async () => {
|
||||
@@ -238,7 +238,7 @@ describe('LegacyResourceIssue', () => {
|
||||
|
||||
const result = await issue.fix(hass);
|
||||
expect(result).toBe(false);
|
||||
expect(onChange).not.toBeCalled();
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return false when the verification fetch silently fails after a successful delete', async () => {
|
||||
@@ -272,7 +272,7 @@ describe('LegacyResourceIssue', () => {
|
||||
const result = await issue.fix(hass);
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(onChange).not.toBeCalled();
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return false when re-detection still finds legacy resource', async () => {
|
||||
@@ -314,7 +314,7 @@ describe('LegacyResourceIssue', () => {
|
||||
const result = await issue.fix(hass);
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(onChange).not.toBeCalled();
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should fix multiple legacy resources', async () => {
|
||||
@@ -437,7 +437,7 @@ describe('LegacyResourceIssue', () => {
|
||||
|
||||
await callback?.(api);
|
||||
|
||||
expect(hass.callWS).toBeCalledWith(
|
||||
expect(hass.callWS).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'lovelace/resources/delete',
|
||||
}),
|
||||
|
||||
@@ -87,7 +87,7 @@ describe('MediaQueryIssue', () => {
|
||||
const tapAction = control?.actions?.tap_action as InternalCallbackActionConfig;
|
||||
await tapAction.callback(api);
|
||||
|
||||
expect(api.getIssueManager().retry).toBeCalledWith('media_query', true);
|
||||
expect(api.getIssueManager().retry).toHaveBeenCalledWith('media_query', true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -133,7 +133,7 @@ describe('MediaQueryIssue', () => {
|
||||
const result = issue.retry();
|
||||
|
||||
expect(result).toEqual(true);
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toHaveBeenCalledWith({
|
||||
intent: 'retry',
|
||||
});
|
||||
|
||||
@@ -189,7 +189,9 @@ describe('MediaQueryIssue', () => {
|
||||
const result = issue.retry();
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledTimes(1);
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toHaveBeenCalledTimes(
|
||||
1,
|
||||
);
|
||||
});
|
||||
|
||||
it('should stop treating the retry as in flight once the query settles without an outcome', async () => {
|
||||
|
||||
@@ -69,7 +69,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
vi.advanceTimersByTime(10000);
|
||||
|
||||
expect(issue.hasIssue()).toBe(true);
|
||||
expect(onChange).toBeCalled();
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not start timer when targetID is null (no provider rendering)', () => {
|
||||
@@ -229,7 +229,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
// Full 10s from camera-2's timer start.
|
||||
vi.advanceTimersByTime(5000);
|
||||
expect(issue.hasIssue()).toBe(true);
|
||||
expect(onChange).toBeCalledTimes(1);
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not restart timer for same target while running', () => {
|
||||
@@ -251,7 +251,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
// 5 more seconds completes the original 10s timer.
|
||||
vi.advanceTimersByTime(5000);
|
||||
expect(issue.hasIssue()).toBe(true);
|
||||
expect(onChange).toBeCalledTimes(1);
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not restart timer when targetID is undefined and matches', () => {
|
||||
@@ -266,7 +266,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
|
||||
vi.advanceTimersByTime(5000);
|
||||
expect(issue.hasIssue()).toBe(true);
|
||||
expect(onChange).toBeCalledTimes(1);
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not restart timer if already timed out', () => {
|
||||
@@ -275,12 +275,12 @@ describe('MediaUnavailableIssue', () => {
|
||||
|
||||
issue.detectDynamic({ targetID: 'camera-1', view: 'live' });
|
||||
vi.advanceTimersByTime(10000);
|
||||
expect(onChange).toBeCalledTimes(1);
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Calling detectDynamic again should not restart timer.
|
||||
issue.detectDynamic({ targetID: 'camera-1', view: 'live' });
|
||||
vi.advanceTimersByTime(10000);
|
||||
expect(onChange).toBeCalledTimes(1);
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -535,7 +535,10 @@ describe('MediaUnavailableIssue', () => {
|
||||
const tapAction = control?.actions?.tap_action as InternalCallbackActionConfig;
|
||||
await tapAction.callback(api);
|
||||
|
||||
expect(api.getIssueManager().retry).toBeCalledWith('media_unavailable', true);
|
||||
expect(api.getIssueManager().retry).toHaveBeenCalledWith(
|
||||
'media_unavailable',
|
||||
true,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -618,7 +621,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
const result = issue.retry();
|
||||
|
||||
expect(result).toEqual(false);
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
mediaEpoch: { 'camera-1': 1, 'media-1': 1 },
|
||||
});
|
||||
});
|
||||
@@ -633,7 +636,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
const result = issue.retry();
|
||||
|
||||
expect(result).toEqual(false);
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
mediaEpoch: { [IMAGE_VIEW_TARGET_ID_SENTINEL]: 1 },
|
||||
});
|
||||
});
|
||||
@@ -650,7 +653,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
const result = issue.retry();
|
||||
|
||||
expect(result).toEqual(false);
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
mediaEpoch: { 'camera-1': 6, 'camera-2': 3 },
|
||||
});
|
||||
});
|
||||
@@ -665,7 +668,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
|
||||
issue.retry();
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
mediaEpoch: { 'camera-1': 1 },
|
||||
});
|
||||
});
|
||||
@@ -701,7 +704,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
vi.advanceTimersByTime(10000);
|
||||
|
||||
expect(issue.hasIssue()).toBe(false);
|
||||
expect(onChange).not.toBeCalled();
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -714,7 +717,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
issue.trigger({ targetID: 'camera-1', reason: 'stalled' });
|
||||
fireMediaLoad(api, 'camera-1');
|
||||
|
||||
expect(onChange).toBeCalled();
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should unsubscribe from media loads on destroy', () => {
|
||||
@@ -725,7 +728,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
|
||||
issue.destroy();
|
||||
|
||||
expect(unsubscribe).toBeCalled();
|
||||
expect(unsubscribe).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -746,7 +749,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
// offscreen and that time does not count against them.
|
||||
vi.advanceTimersByTime(20000);
|
||||
expect(issue.hasIssue()).toBe(false);
|
||||
expect(onChange).not.toBeCalled();
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should preserve an already-active issue across suspend', () => {
|
||||
@@ -780,7 +783,7 @@ describe('MediaUnavailableIssue', () => {
|
||||
expect(issue.hasIssue()).toBe(false);
|
||||
vi.advanceTimersByTime(1);
|
||||
expect(issue.hasIssue()).toBe(true);
|
||||
expect(onChange).toBeCalled();
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user