Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions modules/ui/src/app/app.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,14 @@ export class AppStore extends ComponentStore<AppComponentState> {
checkInterfacesInConfig = this.effect(() => {
return combineLatest([this.interfaces$, this.systemConfig$]).pipe(
filter(([, { network }]) => network !== null),
tap(([interfaces, { network }]) => {
tap(([interfaces, { network, single_intf }]) => {
const deviceValid =
network?.device_intf == '' ||
(!!network?.device_intf && !!interfaces[network.device_intf]);
const internetValid =
network?.internet_intf == '' ||
(!!network?.internet_intf && !!interfaces[network.internet_intf]);

const internetValid = single_intf
? true
: network?.internet_intf == '' ||
(!!network?.internet_intf && !!interfaces[network.internet_intf]);
this.updateSettingMissedError({
isSettingMissed: !deviceValid || !internetValid,
devicePortMissed: !deviceValid,
Expand Down
15 changes: 10 additions & 5 deletions modules/ui/src/app/mocks/settings.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ export const MOCK_SYSTEM_CONFIG_WITH_DATA: SystemConfig = {
monitor_period: 600,
};

export const MOCK_INTERFACES: SystemInterfaces = {
mockDeviceKey: 'mockDeviceValue',
mockInternetKey: 'mockInternetValue',
export const MOCK_SYSTEM_CONFIG_WITH_SINGLE_PORT: SystemConfig = {
network: {
device_intf: 'mockDeviceKey',
internet_intf: '',
},
log_level: 'DEBUG',
monitor_period: 600,
single_intf: true,
};

export const MOCK_INTERNET_OPTIONS: SystemInterfaces = {
'': 'Not specified',
export const MOCK_INTERFACES: SystemInterfaces = {
mockDeviceKey: 'mockDeviceValue',
mockInternetKey: 'mockInternetValue',
};

export const MOCK_DEVICE_VALUE: SystemInterfaces = {
key: 'mockDeviceKey',
value: 'mockDeviceValue',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@

.setting-field {
width: 100%;

&.mat-form-field-disabled {
opacity: 0.6;
}

::ng-deep .mat-mdc-form-field-infix {
min-height: 76px;
display: flex;
Expand Down
5 changes: 4 additions & 1 deletion modules/ui/src/app/pages/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ <h2 class="settings-drawer-header-title">System settings</h2>
*ngIf="(vm.interfaces | keyvalue).length > 0; else warning_message">
<app-callout
[type]="CalloutType.Warning"
*ngIf="(vm.interfaces | keyvalue).length === 1"
*ngIf="
(vm.interfaces | keyvalue).length === 1 &&
!isInternetControlDisabled
"
class="two-ports-message">
Warning! Testrun requires two ports to operate correctly.
</app-callout>
Expand Down
3 changes: 1 addition & 2 deletions modules/ui/src/app/pages/settings/settings.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { LoaderService } from '../../services/loader.service';
import { SettingsStore } from './settings.store';
import {
MOCK_INTERFACES,
MOCK_INTERNET_OPTIONS,
MOCK_SYSTEM_CONFIG_WITH_DATA,
} from '../../mocks/settings.mock';
import { SettingsDropdownComponent } from './components/settings-dropdown/settings-dropdown.component';
Expand Down Expand Up @@ -331,7 +330,7 @@ describe('GeneralSettingsComponent', () => {
isLessThanOneInterface: false,
interfaces: MOCK_INTERFACES,
deviceOptions: MOCK_INTERFACES,
internetOptions: MOCK_INTERNET_OPTIONS,
internetOptions: MOCK_INTERFACES,
logLevelOptions: {},
monitoringPeriodOptions: {},
});
Expand Down
15 changes: 11 additions & 4 deletions modules/ui/src/app/pages/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ export class SettingsComponent implements OnInit, OnDestroy {
}

get isFormValues(): boolean {
return this.internetControl?.value.value && this.deviceControl?.value.value;
return (
this.deviceControl?.value.value &&
(this.isInternetControlDisabled || this.internetControl?.value.value)
);
}

get isInternetControlDisabled(): boolean {
return this.internetControl?.disabled;
}

get isFormError(): boolean {
Expand All @@ -102,7 +109,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
this.createSettingForm();
this.cleanFormErrorMessage();
this.settingsStore.getInterfaces();
this.settingsStore.getSystemConfig();
this.getSystemConfig();
this.setDefaultFormValues();
}

Expand All @@ -112,7 +119,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
}
this.showLoading();
this.getSystemInterfaces();
this.settingsStore.getSystemConfig();
this.getSystemConfig();
this.setDefaultFormValues();
}
closeSetting(message: string): void {
Expand Down Expand Up @@ -177,7 +184,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
const data: SystemConfig = {
network: {
device_intf: device_intf.key,
internet_intf: internet_intf.key,
internet_intf: this.isInternetControlDisabled ? '' : internet_intf.key,
},
log_level: log_level.key,
monitor_period: Number(monitor_period.key),
Expand Down
36 changes: 25 additions & 11 deletions modules/ui/src/app/pages/settings/settings.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
DEFAULT_INTERNET_OPTION,
LOG_LEVELS,
MONITORING_PERIOD,
SettingsStore,
} from './settings.store';
import { LOG_LEVELS, MONITORING_PERIOD, SettingsStore } from './settings.store';
import { TestRunService } from '../../services/test-run.service';
import SpyObj = jasmine.SpyObj;
import { TestBed } from '@angular/core/testing';
Expand All @@ -39,11 +34,11 @@ import {
MOCK_DEVICE_VALUE,
MOCK_INTERFACE_VALUE,
MOCK_INTERFACES,
MOCK_INTERNET_OPTIONS,
MOCK_LOG_VALUE,
MOCK_PERIOD_VALUE,
MOCK_SYSTEM_CONFIG_WITH_DATA,
MOCK_SYSTEM_CONFIG_WITH_NO_DATA,
MOCK_SYSTEM_CONFIG_WITH_SINGLE_PORT,
} from '../../mocks/settings.mock';

describe('SettingsStore', () => {
Expand Down Expand Up @@ -120,7 +115,6 @@ describe('SettingsStore', () => {
expect(store.interfaces).toEqual(MOCK_INTERFACES);
expect(store.deviceOptions).toEqual(MOCK_INTERFACES);
expect(store.internetOptions).toEqual({
'': 'Not specified',
mockDeviceKey: 'mockDeviceValue',
mockInternetKey: 'mockInternetValue',
});
Expand Down Expand Up @@ -193,7 +187,7 @@ describe('SettingsStore', () => {
settingsStore.viewModel$.pipe(skip(3), take(1)).subscribe(store => {
expect(store.interfaces).toEqual(interfaces);
expect(store.deviceOptions).toEqual(interfaces);
expect(store.internetOptions).toEqual(MOCK_INTERNET_OPTIONS);
expect(store.internetOptions).toEqual(interfaces);
done();
});

Expand Down Expand Up @@ -279,6 +273,27 @@ describe('SettingsStore', () => {
});
});

describe('with single port mode', () => {
beforeEach(() => {
settingsStore.setSystemConfig(MOCK_SYSTEM_CONFIG_WITH_SINGLE_PORT);
settingsStore.setInterfaces(MOCK_INTERFACES);
});

it('should disable internet control', () => {
const form = fb.group({
device_intf: ['value'],
internet_intf: [''],
log_level: [''],
monitor_period: ['value'],
});
settingsStore.setDefaultFormValues(form);

expect(
(form.get(FormKey.INTERNET) as FormControl).disabled
).toBeTrue();
});
});

describe('when values are empty', () => {
beforeEach(() => {
settingsStore.setSystemConfig(MOCK_SYSTEM_CONFIG_WITH_NO_DATA);
Expand All @@ -300,7 +315,7 @@ describe('SettingsStore', () => {
});
expect((form.get(FormKey.INTERNET) as FormControl).value).toEqual({
key: '',
value: DEFAULT_INTERNET_OPTION[''],
value: undefined,
});
expect((form.get(FormKey.LOG_LEVEL) as FormControl).value).toEqual({
key: 'INFO',
Expand All @@ -322,7 +337,6 @@ describe('SettingsStore', () => {
mockNewInternetKey: 'mockNewInternetValue',
};
const updateInternetOptions = {
'': 'Not specified',
mockDeviceKey: 'mockDeviceValue',
mockNewInternetKey: 'mockNewInternetValue',
};
Expand Down
29 changes: 16 additions & 13 deletions modules/ui/src/app/pages/settings/settings.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ export interface SettingsComponentState {
monitoringPeriodOptions: SystemInterfaces;
}

export const DEFAULT_INTERNET_OPTION = {
'': 'Not specified',
};

export const LOG_LEVELS = {
DEBUG: 'Every event will be logged',
INFO: 'Normal events and issues',
Expand Down Expand Up @@ -118,10 +114,7 @@ export class SettingsStore extends ComponentStore<SettingsComponentState> {
...state,
interfaces,
deviceOptions: interfaces,
internetOptions: {
...DEFAULT_INTERNET_OPTION,
...interfaces,
},
internetOptions: interfaces,
isLessThanOneInterface: Object.keys(interfaces).length < 1,
};
});
Expand Down Expand Up @@ -180,16 +173,21 @@ export class SettingsStore extends ComponentStore<SettingsComponentState> {
this.systemConfig$.pipe(
withLatestFrom(this.deviceOptions$, this.internetOptions$),
tap(([config, deviceOptions, internetOptions]) => {
if (config.single_intf) {
this.disableInternetInterface(formGroup);
} else {
this.setDefaultInternetInterfaceValue(
config.network?.internet_intf,
internetOptions,
formGroup
);
}

this.setDefaultDeviceInterfaceValue(
config.network?.device_intf,
deviceOptions,
formGroup
);
this.setDefaultInternetInterfaceValue(
config.network?.internet_intf,
internetOptions,
formGroup
);
this.setDefaultLogLevelValue(
config.log_level,
LOG_LEVELS,
Expand Down Expand Up @@ -300,6 +298,11 @@ export class SettingsStore extends ComponentStore<SettingsComponentState> {
);
}

private disableInternetInterface(formGroup: FormGroup) {
const internetControl = formGroup.get(FormKey.INTERNET) as FormControl;
internetControl.disable();
}

private setDefaultValue(
value: string | undefined,
defaultValue: string | undefined,
Expand Down