Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

config-editor-ui: Reworking Config testers based on new backend #750

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion config-editor/config-editor-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rule-editor.ui",
"version": "2.6.6-dev",
"version": "2.6.7-dev",
"license": "MIT",
"scripts": {
"ng": "ng",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { cloneDeep } from 'lodash';
import { Observable, Subject } from 'rxjs';
import { first, takeUntil } from 'rxjs/operators';
import { EditorComponent } from '../editor/editor.component';
import { FILTER_PARAM_KEY, SEARCH_PARAM_KEY, TestingType } from '@app/model/config-model';
import { FILTER_PARAM_KEY, SEARCH_PARAM_KEY, DEFAULT_CONFIG_TESTER_NAME, TestingType } from '@app/model/config-model';
import { SchemaService } from '@app/services/schema/schema.service';

@Component({
Expand Down Expand Up @@ -74,10 +74,13 @@ export class EditorViewComponent implements OnInit, OnDestroy, AfterViewInit {
ngAfterViewInit() {
this.editedConfig$.pipe(takeUntil(this.ngUnsubscribe)).subscribe((config: Config) => {
this.configData = config.configData;
const testConfig = this.editorService.getTestConfig(DEFAULT_CONFIG_TESTER_NAME);
const testConfigIsEnabled = testConfig === undefined ? false : testConfig.config_testing;
const testCaseConfigIsEnabled = testConfig === undefined ? false : testConfig.test_case_testing;
this.testingEnabled = () =>
this.editorService.metaDataMap.testing.perConfigTestEnabled && this.editorComponent.form.valid;
testConfigIsEnabled && this.editorComponent.form.valid;
this.testCaseEnabled = () =>
this.editorService.metaDataMap.testing.testCaseEnabled && this.editorComponent.form.valid && !config.isNew;
testCaseConfigIsEnabled && this.editorComponent.form.valid && !config.isNew;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { take, catchError } from 'rxjs/operators';
import { throwError, of, mergeMap } from 'rxjs';
import { DiffResults } from 'ngx-text-diff/lib/ngx-text-diff.model';
import { AppService } from '@app/services/app.service';
import { ReleaseWrapper, TestingType } from '@app/model/config-model';
import { ReleaseWrapper, TestingType, DEFAULT_CONFIG_TESTER_NAME } from '@app/model/config-model';


@Component({
Expand Down Expand Up @@ -91,7 +91,9 @@ export class ReleaseDialogComponent implements AfterViewChecked {
}
});
}
this.testEnabled = this.uiMetadata.testing.releaseTestEnabled;

const testConfig = this.service.getTestConfig(DEFAULT_CONFIG_TESTER_NAME);
this.testEnabled = testConfig !== undefined ? testConfig.release_testing : false;
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
this.environment = this.config.environment;

this.service.configStore.initialRelease$.subscribe((d: Release) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<mat-card>
<form *ngIf="numTesters > 1" [formGroup]="form">
<formly-form [model]="configTesterModel" [fields]="configTestersFields" [options]="options" [form]="formDropDown"></formly-form>
</form>
<div class="console">
<span class="title">
<h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormGroup } from '@angular/forms';
import { EditorService } from '@app/services/editor.service';
import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core';
import { FormlyForm } from '@ngx-formly/core';
import { ConfigTestResult, TestingType } from '../../../model/config-model';
import { ConfigTestResult, TestingType, TestConfigSpec, DEFAULT_CONFIG_TESTER_NAME } from '../../../model/config-model';
import { take } from 'rxjs/operators';
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
import { SchemaService } from '@app/services/schema/schema.service';
Expand All @@ -24,16 +24,43 @@ export class ConfigTestingComponent implements OnInit {
public isInvalid = false;
public output: any;

private CONFIG_TESTER_KEY = "config_tester";
configTestersFields: FormlyFieldConfig[] = [
{
key: this.CONFIG_TESTER_KEY,
type: "enum",
defaultValue: DEFAULT_CONFIG_TESTER_NAME,
templateOptions: {
label: "Config tester",
hintEnd: "The name of the config tester selected",
change: (field, $event) => {
this.updateConfigTester($event.value);
},
options: []
},
},
];
configTesterModel = {};
formDropDown: FormGroup = new FormGroup({});
private testConfigSpec: TestConfigSpec = undefined;
numTesters = 0;

constructor(private editorService: EditorService, private cd: ChangeDetectorRef) {}

ngOnInit() {
if (this.editorService.metaDataMap.testing.perConfigTestEnabled) {
let schema = this.editorService.testSpecificationSchema;
this.editorService.configSchema.formatTitlesInSchema(schema, '');
this.field = new FormlyJsonschema().toFieldConfig(schema, { map: SchemaService.renameDescription });
this.testConfigSpec = this.editorService.getTestConfig(DEFAULT_CONFIG_TESTER_NAME);
if (this.testConfigSpec !== undefined && this.testConfigSpec.config_testing) {
this.initSchema();
this.initDropdown();
}
}

initSchema() {
let schema = this.testConfigSpec.test_schema;
this.editorService.configSchema.formatTitlesInSchema(schema, '');
this.field = new FormlyJsonschema().toFieldConfig(schema, { map: SchemaService.renameDescription });
}

runTest() {
this.editorService.configStore.testService
.test(this.form.value, this.testingType)
Expand All @@ -44,4 +71,26 @@ export class ConfigTestingComponent implements OnInit {
this.cd.markForCheck();
});
}

initDropdown() {
this.numTesters = this.editorService.testConfigSpec.length;
return this.configTestersFields.map(f => {
if (f.key === this.CONFIG_TESTER_KEY) {
f.templateOptions.options = this.editorService.testConfigSpec.map( tester => {
return { value: tester.name, label: tester.name}
})
}
})
}

updateConfigTester(testerName: string) {
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
const tester = this.editorService.getTestConfig(testerName);
if (tester !== undefined) {
this.testConfigSpec = tester;
if (this.testConfigSpec.config_testing) {
this.initSchema();
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, OnInit, OnDestroy } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { copyHiddenTestCaseFields, TestCaseWrapper } from '@app/model/test-case';
import { Type } from '@app/model/config-model';
import { Type, TestConfigSpec, DEFAULT_CONFIG_TESTER_NAME } from '@app/model/config-model';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { cloneDeep } from 'lodash';
import { EditorService } from '@app/services/editor.service';
Expand Down Expand Up @@ -33,6 +33,7 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy {
testStoreService: TestStoreService;
form: FormGroup = new FormGroup({});
private markHistoryChange = false;
private testConfigSpec: TestConfigSpec = undefined;
constructor(
private appService: AppService,
private editorService: EditorService,
Expand All @@ -45,8 +46,9 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy {
}

ngOnInit() {
if (this.editorService.metaDataMap.testing.testCaseEnabled) {
const subschema = cloneDeep(this.editorService.testSpecificationSchema);
this.testConfigSpec = this.editorService.getTestConfig(DEFAULT_CONFIG_TESTER_NAME);
if (this.testConfigSpec.test_case_testing) {
const subschema = cloneDeep(this.testConfigSpec.test_schema);
const schema = cloneDeep(this.appService.testCaseSchema);
schema.properties.test_specification = subschema;
const schemaConverter = new FormlyJsonschema();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TestStoreService } from '@app/services/store/test-store.service';
import { Router, ActivatedRoute } from '@angular/router';
import { BlockUI, NgBlockUI } from 'ng-block-ui';
import { AppConfigService } from '@app/services/app-config.service';
import { Type } from '@app/model/config-model';
import { Type, DEFAULT_CONFIG_TESTER_NAME } from '@app/model/config-model';

@Component({
selector: 're-test-centre',
Expand Down Expand Up @@ -40,7 +40,9 @@ export class TestCentreComponent implements OnInit, OnDestroy {
}

ngOnInit() {
if (this.editorService.metaDataMap.testing.testCaseEnabled) {
const testConfig = this.editorService.getTestConfig(DEFAULT_CONFIG_TESTER_NAME);
const testCaseConfigEnabled = testConfig !== undefined ? testConfig.test_case_testing : false;
if (testCaseConfigEnabled) {
this.testCases$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(testCases => {
this.testCases = testCases;
});
Expand Down
15 changes: 15 additions & 0 deletions config-editor/config-editor-ui/src/app/model/config-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,18 @@ export interface ErrorDialog {
icon_name: string,
icon_color: string,
}

export interface TestConfigSpec {
name: string;
test_schema: JSONSchema7;
config_testing: boolean;
test_case_testing: boolean;
release_testing: boolean;
incomplete_result: boolean;
}

export interface TestConfigSpecTesters {
config_testers: TestConfigSpec[];
}

export const DEFAULT_CONFIG_TESTER_NAME = "default";
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
GitFiles,
PullRequestInfo,
SchemaInfo,
TestSchemaInfo,
TestConfigSpecTesters,
TestConfigSpec,
AdminSchemaInfo,
AdminConfig,
AdminConfigGitFiles,
Expand All @@ -35,6 +36,7 @@ import { replacer } from '@app/commons/helper-functions';
export class ConfigLoaderService {
// eslint-disable-next-line @typescript-eslint/ban-types
private labelsFunc: Function;
private testConfigSpec: TestConfigSpec = undefined;

constructor(
private http: HttpClient,
Expand Down Expand Up @@ -79,10 +81,10 @@ export class ConfigLoaderService {
}));
}

getTestSpecificationSchema(): Observable<JSONSchema7> {
getTestSpecification(): Observable<TestConfigSpec[]> {
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
return this.http
.get<TestSchemaInfo>(`${this.config.serviceRoot}api/v1/${this.serviceName}/configs/testschema`)
.pipe(map(x => x.test_schema));
.get<TestConfigSpecTesters>(`${this.config.serviceRoot}api/v1/${this.serviceName}/configs/testers`)
.pipe(map(result => result.config_testers));
}

getSchema(): Observable<JSONSchema7> {
Expand Down Expand Up @@ -374,7 +376,8 @@ export class ConfigLoaderService {
null
)
.pipe(map(result => {
if (!result.configs_files || (!result.test_cases_files && this.uiMetadata.testing.testCaseEnabled)) {
const testCaseIsEnabled = this.testConfigSpec !== undefined ? this.testConfigSpec.test_case_testing : false;
if (!result.configs_files || (!result.test_cases_files && testCaseIsEnabled)) {
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
throw new DOMException('bad format response when deleting config');
}
const configAndTestCases = {
Expand Down Expand Up @@ -412,6 +415,14 @@ export class ConfigLoaderService {
.pipe(map(result => result));
}

setConfigTester(testConfig: TestConfigSpec) {
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
this.testConfigSpec = testConfig;
}

getConfigTester() {
return this.testConfigSpec;
}

private testCaseFilesToMap(files: any[]): TestCaseMap {
const testCaseMap: TestCaseMap = {};
if (files && files.length > 0) {
Expand Down
52 changes: 26 additions & 26 deletions config-editor/config-editor-ui/src/app/services/editor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AppService } from './app.service';
import { mergeMap, map } from 'rxjs/operators';
import { ConfigSchemaService } from './schema/config-schema-service';
import { AdminSchemaService } from './schema/admin-schema.service';
import { CheckboxEvent, FILTER_PARAM_KEY, ServiceSearch } from '@app/model/config-model';
import { CheckboxEvent, FILTER_PARAM_KEY, ServiceSearch, TestConfigSpec, DEFAULT_CONFIG_TESTER_NAME } from '@app/model/config-model';
import { SearchHistoryService } from './search-history.service';
import { ParamMap } from '@angular/router';

Expand All @@ -21,9 +21,9 @@ export class ServiceContext {
adminSchema?: AdminSchemaService;
configStore: ConfigStoreService;
serviceName: string;
testSpecificationSchema?: JSONSchema7;
adminMode: boolean;
searchHistoryService?: SearchHistoryService;
testConfigSpec?: TestConfigSpec[];
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
}

@Injectable({
Expand Down Expand Up @@ -56,13 +56,12 @@ export class EditorService {
get adminMode() {
return this.serviceContext.adminMode;
}
get testSpecificationSchema() {
return this.serviceContext.testSpecificationSchema;
}

get searchHistoryService() {
return this.serviceContext.searchHistoryService;
}
get testConfigSpec() {
return this.serviceContext.testConfigSpec;
}

constructor(
private http: HttpClient,
Expand All @@ -78,27 +77,24 @@ export class EditorService {
}

createConfigServiceContext(serviceName: string): Observable<ServiceContext> {
const [metaDataMap, user, configLoader, configStore] = this.initialiseContext(serviceName);
const testSpecificationFun = metaDataMap.testing.perConfigTestEnabled
? configLoader.getTestSpecificationSchema()
: of({});
const testCaseMapFun = metaDataMap.testing.testCaseEnabled ? configLoader.getTestCases() : of({});
const [metaDataMap, user, configLoader, configStore] = this.initialiseContext(serviceName);

return configLoader
.getSchema()
.pipe(
mergeMap(schema =>
forkJoin(
configLoader.getConfigs(),
configLoader.getRelease(),
of(schema),
testCaseMapFun,
testSpecificationFun
)
return forkJoin(configLoader.getSchema(), configLoader.getTestSpecification())
.pipe(mergeMap(([schema, testConfig]) => {
const testConfigInfo = testConfig.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME);
const testCasesConfig = testConfigInfo === undefined ? false : testConfigInfo.test_case_testing;
configLoader.setConfigTester(testConfigInfo);
return forkJoin(
configLoader.getConfigs(),
configLoader.getRelease(),
of(schema),
of(testConfig),
testCasesConfig ? configLoader.getTestCases() : of({})
)
)
.pipe(map(([configs, release, originalSchema, testCaseMap, testSpecSchema]) => {
if (configs && release && originalSchema && testCaseMap && testSpecSchema) {
}))
.pipe(map(([configs, release, originalSchema, testSpec, testCaseMap]) => {
if (configs && release && originalSchema && testSpec && testCaseMap) {

configStore.initialise(configs, release, testCaseMap, user, metaDataMap);
return {
adminMode: false,
Expand All @@ -107,7 +103,7 @@ export class EditorService {
configStore,
metaDataMap,
serviceName,
testSpecificationSchema: testSpecSchema,
testConfigSpec: testSpec,
searchHistoryService: new SearchHistoryService(this.config, serviceName),
};
}
Expand Down Expand Up @@ -151,6 +147,10 @@ export class EditorService {
return filters;
}

getTestConfig(name: string): TestConfigSpec {
return this.testConfigSpec.find(x => x.name === name);
}

onSaveSearch(currentParams: ParamMap): ServiceSearch[] {
return this.serviceContext.searchHistoryService.addToSearchHistory(currentParams);
}
Expand Down
Loading