Skip to content

Commit 70e7ed1

Browse files
refactor test imports and rollback methods for consistency
Standardize imports across test files by replacing inline React imports with named imports. Simplify code structure for readability by reformatting multiline arrays and conditionals. Remove the «override» keyword from rollback methods in multiple classes to align with TypeScript conventions and ensure compatibility. Improve readability in «derivePossibleCauses» by reformatting conditional checks for network issues. These changes enhance code consistency, maintainability, and readability.
1 parent 8228704 commit 70e7ed1

File tree

9 files changed

+21
-25
lines changed

9 files changed

+21
-25
lines changed

public/dashboard-assistant/components/__tests__/model-register.test.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import React from 'react';
6+
import React, { useState, useCallback, useEffect } from 'react';
77
import userEvent from '@testing-library/user-event';
88
import { render, screen, waitFor } from '../../../../test/test_utils';
9+
import { ExecutionState } from '../../modules/installation-manager/domain';
910

1011
jest.mock('../model-form', () => {
11-
const React = require('react');
12-
1312
const MockModelForm = ({ onChange, onValidationChange }: any) => {
14-
React.useEffect(() => {
13+
useEffect(() => {
1514
onChange?.({
1615
modelProvider: 'OpenAI',
1716
model: 'gpt-4o',
@@ -31,9 +30,6 @@ jest.mock('../model-form', () => {
3130
});
3231

3332
jest.mock('../../modules/installation-manager/hooks/use-assistant-installation', () => {
34-
const React = require('react');
35-
const { ExecutionState } = require('../../modules/installation-manager/domain');
36-
3733
const failedStep = {
3834
stepName: 'Create Model',
3935
state: ExecutionState.FAILED,
@@ -58,9 +54,9 @@ jest.mock('../../modules/installation-manager/hooks/use-assistant-installation',
5854
return {
5955
__esModule: true,
6056
useAssistantInstallation: () => {
61-
const [error, setError] = React.useState<string | undefined>(undefined);
57+
const [error, setError] = useState<string | undefined>(undefined);
6258

63-
const install = React.useCallback(async () => {
59+
const install = useCallback(async () => {
6460
setError('Steps: "Create Model" has failed');
6561
}, []);
6662

public/dashboard-assistant/modules/installation-manager/domain/entities/install-dashboard-assistant-response.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ describe('InstallDashboardAssistantResponse', () => {
3434

3535
it('failure() should accept rollbacks to describe reverted steps', () => {
3636
const progress = new InstallationProgress();
37-
const res = InstallDashboardAssistantResponse.failure(
38-
'Failed with rollbacks',
39-
progress,
40-
['Create Connector', 'Persist ML Commons settings']
41-
);
37+
const res = InstallDashboardAssistantResponse.failure('Failed with rollbacks', progress, [
38+
'Create Connector',
39+
'Persist ML Commons settings',
40+
]);
4241

4342
expect(res.rollbacks).toEqual(['Create Connector', 'Persist ML Commons settings']);
4443
});

public/dashboard-assistant/modules/installation-manager/domain/entities/installation-progress-manager.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ describe('InstallationProgressManager', () => {
125125
).rejects.toThrow('boom');
126126

127127
expect(rollbackOrder).toEqual(['S3', 'S2', 'S1']);
128-
expect(mgr.getRollbackErrors()).toEqual([
129-
{ step: 'S2', message: 'S2 rollback failed' },
130-
]);
128+
expect(mgr.getRollbackErrors()).toEqual([{ step: 'S2', message: 'S2 rollback failed' }]);
131129
});
132130

133131
it('prevents concurrent step execution', async () => {

public/dashboard-assistant/modules/installation-manager/infrastructure/steps/create-agent-step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class CreateAgentStep extends InstallationAIAssistantStep {
9595
return 'Failed to create agent. Please check the configuration and try again.';
9696
}
9797

98-
public override async rollback(
98+
public async rollback(
9999
_request: InstallAIDashboardAssistantDto,
100100
context: InstallationContext,
101101
_error: Error

public/dashboard-assistant/modules/installation-manager/infrastructure/steps/create-connector-step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class CreateConnectorStep extends InstallationAIAssistantStep {
7272
return 'Failed to create connector. Please check the configuration and try again.';
7373
}
7474

75-
public override async rollback(
75+
public async rollback(
7676
_request: InstallAIDashboardAssistantDto,
7777
context: InstallationContext,
7878
_error: Error

public/dashboard-assistant/modules/installation-manager/infrastructure/steps/create-model-step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class CreateModelStep extends InstallationAIAssistantStep {
6363
return 'Failed to create model. Please check the configuration and try again.';
6464
}
6565

66-
public override async rollback(
66+
public async rollback(
6767
_request: InstallAIDashboardAssistantDto,
6868
context: InstallationContext,
6969
_error: Error

public/dashboard-assistant/modules/installation-manager/infrastructure/steps/register-agent-step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class RegisterAgentStep extends InstallationAIAssistantStep {
4848
return 'Failed to register agent. Please check the configuration and try again.';
4949
}
5050

51-
public override async rollback(
51+
public async rollback(
5252
_request: InstallAIDashboardAssistantDto,
5353
_context: InstallationContext,
5454
_error: Error

public/dashboard-assistant/modules/installation-manager/infrastructure/steps/test-model-connection-step.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const extractStatusCode = (error: unknown): number | undefined => {
4848
const derivePossibleCauses = (error: unknown, modelId?: string): string[] => {
4949
const causes = new Set<string>();
5050
const status = extractStatusCode(error);
51-
const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
51+
const message =
52+
error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
5253

5354
if (status === 401 || status === 403) {
5455
causes.add('Verify the API key; it may be incorrect or lack permissions.');
@@ -64,7 +65,9 @@ const derivePossibleCauses = (error: unknown, modelId?: string): string[] => {
6465

6566
const indicatesNetworkIssue =
6667
!status &&
67-
(error instanceof TypeError || message.includes('failed to fetch') || message.includes('network'));
68+
(error instanceof TypeError ||
69+
message.includes('failed to fetch') ||
70+
message.includes('network'));
6871

6972
if (indicatesNetworkIssue) {
7073
causes.add('Check the API URL for typos and ensure the endpoint is reachable.');
@@ -116,7 +119,7 @@ export class TestModelConnectionStep extends InstallationAIAssistantStep {
116119
return 'Failed to test model connection. Please check the model configuration and try again.';
117120
}
118121

119-
public override async rollback(
122+
public async rollback(
120123
_request: InstallAIDashboardAssistantDto,
121124
_context: InstallationContext,
122125
_error: Error

public/dashboard-assistant/modules/installation-manager/infrastructure/steps/update-ml-commons-settings-step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class UpdateMlCommonsSettingsStep extends InstallationAIAssistantStep {
5959
return 'Failed to update ML Commons settings. Please check the configuration and try again.';
6060
}
6161

62-
public override async rollback(
62+
public async rollback(
6363
_request: InstallAIDashboardAssistantDto,
6464
_context: InstallationContext,
6565
_error: Error

0 commit comments

Comments
 (0)