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 3 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.testConfigSpec.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME);
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
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.testConfigSpec.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME);
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
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 [formGroup]="form">
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
<formly-form [model]="model" [fields]="fields" [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,13 +24,35 @@ export class ConfigTestingComponent implements OnInit {
public isInvalid = false;
public output: any;

private CONFIG_TESTER_KEY = "config_tester";
fields: FormlyFieldConfig[] = [
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
{
key: this.CONFIG_TESTER_KEY,
type: "enum",
defaultValue: "default",
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
templateOptions: {
label: "Config tester",
hintEnd: "The name of the config tester selected",
change: (field, $event) => {
this.updateConfigTester($event.value);
},
options: []
},
},
];
model = {};
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
formDropDown: FormGroup = new FormGroup({});
private testConfigSpec: TestConfigSpec = undefined;

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

ngOnInit() {
if (this.editorService.metaDataMap.testing.perConfigTestEnabled) {
let schema = this.editorService.testSpecificationSchema;
this.testConfigSpec = this.editorService.testConfigSpec.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME);
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
if (this.testConfigSpec.config_testing) {
let schema = this.testConfigSpec.test_schema;
this.editorService.configSchema.formatTitlesInSchema(schema, '');
this.field = new FormlyJsonschema().toFieldConfig(schema, { map: SchemaService.renameDescription });
this.initDropdown();
}
}

Expand All @@ -44,4 +66,27 @@ export class ConfigTestingComponent implements OnInit {
this.cd.markForCheck();
});
}

initDropdown() {
return this.fields.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.testConfigSpec.find(x => x.name === testerName);
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
if (tester !== undefined) {
this.testConfigSpec = tester;
if (this.testConfigSpec.config_testing) {
let schema = this.testConfigSpec.test_schema;
this.editorService.configSchema.formatTitlesInSchema(schema, '');
this.field = new FormlyJsonschema().toFieldConfig(schema, { map: SchemaService.renameDescription });
}
}

}
}
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.testConfigSpec.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME);
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
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.testConfigSpec.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME);
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -28,7 +29,7 @@ import { ADMIN_VERSION_FIELD_NAME, UiMetadata } from '@model/ui-metadata-map';
import { cloneDeep } from 'lodash';
import { map, mergeMap } from 'rxjs/operators';
import { JSONSchema7 } from 'json-schema';
import { TestCaseEvaluation, TestCaseResultAttributes } from '../model/config-model';
import { TestCaseEvaluation, TestCaseResultAttributes, DEFAULT_CONFIG_TESTER_NAME } from '../model/config-model';
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
import { TestCaseEvaluationResult, isNewTestCase } from '../model/test-case';
import { replacer } from '@app/commons/helper-functions';

Expand Down Expand Up @@ -79,10 +80,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 +375,10 @@ export class ConfigLoaderService {
null
)
.pipe(map(result => {
if (!result.configs_files || (!result.test_cases_files && this.uiMetadata.testing.testCaseEnabled)) {
const testCaseIsEnabled = this.getTestSpecification().pipe(map( resp => {
return resp ? resp.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME).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
54 changes: 25 additions & 29 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[];
}

@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,23 @@ 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;
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 +102,7 @@ export class EditorService {
configStore,
metaDataMap,
serviceName,
testSpecificationSchema: testSpecSchema,
testConfigSpec: testSpec,
searchHistoryService: new SearchHistoryService(this.config, serviceName),
};
}
Expand All @@ -121,9 +116,9 @@ export class EditorService {
return configLoader
.getAdminSchema()
.pipe(
mergeMap(schema => forkJoin([configLoader.getAdminConfig(), of(schema)])),
map(([adminConfig, originalSchema]) => {
if (adminConfig && originalSchema) {
mergeMap(schema => forkJoin([configLoader.getAdminConfig(), of(schema), configLoader.getTestSpecification()])),
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
map(([adminConfig, originalSchema, testSpec]) => {
if (adminConfig && originalSchema && testSpec) {
configStore.updateAdmin(adminConfig);
return {
adminMode: true,
Expand All @@ -132,6 +127,7 @@ export class EditorService {
configStore,
metaDataMap,
serviceName,
testConfigSpec: testSpec,
};
}
throwError(() => 'Can not load admin service');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { UiMetadata } from '../../model/ui-metadata-map';
import { ConfigLoaderService } from '../config-loader.service';
import { ConfigStoreStateBuilder } from './config-store-state.builder';
import { TestStoreService } from './test-store.service';
import { AdminConfig, ConfigAndTestsToClone, ConfigToImport, ExistingConfigError, FILTER_PARAM_KEY, Importers, SEARCH_PARAM_KEY, Type } from '@app/model/config-model';
import { AdminConfig, ConfigAndTestsToClone, ConfigToImport, ExistingConfigError, FILTER_PARAM_KEY, Importers, SEARCH_PARAM_KEY, DEFAULT_CONFIG_TESTER_NAME, Type } from '@app/model/config-model';
import { ClipboardStoreService } from '../clipboard-store.service';
import { ConfigHistoryService } from '../config-history.service';
import { AppConfigService } from '../app-config.service';
Expand Down Expand Up @@ -225,12 +225,18 @@ export class ConfigStoreService {
}

reloadStoreAndRelease(): Observable<any> {
const testCaseMapFun = this.metaDataMap.testing.testCaseEnabled ? this.configLoaderService.getTestCases() : of({});
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
return forkJoin(
this.configLoaderService.getConfigs(),
this.configLoaderService.getRelease(),
testCaseMapFun
).pipe(map(([configs, release, testCaseMap]) => {
this.configLoaderService.getTestSpecification()
).pipe(mergeMap(([configs, release, testConfig]) => {
return forkJoin(
of(configs),
of(release),
testConfig.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME).test_case_testing ? this.configLoaderService.getTestCases() : of({})
)
}))
.pipe(map(([configs, release, testCaseMap]) => {
if (configs && release && testCaseMap) {
this.initialise(configs, release, testCaseMap, this.user, this.metaDataMap);
}
Expand Down
Loading