From fd35b6cc9bdc0964a441a270352c64aa1e18f7a4 Mon Sep 17 00:00:00 2001 From: Yassin Raman Date: Tue, 2 Aug 2022 23:13:50 +0100 Subject: [PATCH 01/10] support for new config testers endpoint --- .../editor-view/editor-view.component.ts | 9 ++-- .../release-dialog.component.ts | 6 ++- .../config-testing.component.html | 3 ++ .../config-testing.component.ts | 51 ++++++++++++++++-- .../test-case-editor.component.ts | 8 +-- .../test-centre/test-centre.component.ts | 6 ++- .../src/app/model/config-model.ts | 15 ++++++ .../src/app/services/config-loader.service.ts | 16 +++--- .../src/app/services/editor.service.ts | 54 +++++++++---------- .../services/store/config-store.service.ts | 14 +++-- 10 files changed, 130 insertions(+), 52 deletions(-) diff --git a/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts b/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts index f690dd1b4..d734bc5d0 100644 --- a/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts +++ b/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts @@ -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({ @@ -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); + 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; }); } diff --git a/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts b/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts index 4c07655cb..fa44d5e41 100644 --- a/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts +++ b/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts @@ -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({ @@ -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); + this.testEnabled = testConfig !== undefined ? testConfig.release_testing : false; this.environment = this.config.environment; this.service.configStore.initialRelease$.subscribe((d: Release) => { diff --git a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html index eee87224d..7c8933791 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html +++ b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html @@ -1,4 +1,7 @@ +
+ +

diff --git a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts index 2897a8445..a2728742c 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts @@ -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'; @@ -24,13 +24,35 @@ export class ConfigTestingComponent implements OnInit { public isInvalid = false; public output: any; + private CONFIG_TESTER_KEY = "config_tester"; + fields: FormlyFieldConfig[] = [ + { + key: this.CONFIG_TESTER_KEY, + type: "enum", + defaultValue: "default", + templateOptions: { + label: "Config tester", + hintEnd: "The name of the config tester selected", + change: (field, $event) => { + this.updateConfigTester($event.value); + }, + options: [] + }, + }, + ]; + model = {}; + 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); + 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(); } } @@ -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) { + const tester = this.editorService.testConfigSpec.find(x => x.name === testerName); + 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 }); + } + } + + } } diff --git a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts index 155b136f0..158a92960 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts @@ -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'; @@ -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, @@ -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); + 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(); diff --git a/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts b/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts index 74c2aa4a6..a6bb64039 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts @@ -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', @@ -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); + const testCaseConfigEnabled = testConfig !== undefined ? testConfig.test_case_testing : false; + if (testCaseConfigEnabled) { this.testCases$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(testCases => { this.testCases = testCases; }); diff --git a/config-editor/config-editor-ui/src/app/model/config-model.ts b/config-editor/config-editor-ui/src/app/model/config-model.ts index 183cf90b2..d29818ce2 100644 --- a/config-editor/config-editor-ui/src/app/model/config-model.ts +++ b/config-editor/config-editor-ui/src/app/model/config-model.ts @@ -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"; \ No newline at end of file diff --git a/config-editor/config-editor-ui/src/app/services/config-loader.service.ts b/config-editor/config-editor-ui/src/app/services/config-loader.service.ts index 49e92a600..6e005279d 100644 --- a/config-editor/config-editor-ui/src/app/services/config-loader.service.ts +++ b/config-editor/config-editor-ui/src/app/services/config-loader.service.ts @@ -11,7 +11,8 @@ import { GitFiles, PullRequestInfo, SchemaInfo, - TestSchemaInfo, + TestConfigSpecTesters, + TestConfigSpec, AdminSchemaInfo, AdminConfig, AdminConfigGitFiles, @@ -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'; import { TestCaseEvaluationResult, isNewTestCase } from '../model/test-case'; import { replacer } from '@app/commons/helper-functions'; @@ -79,10 +80,10 @@ export class ConfigLoaderService { })); } - getTestSpecificationSchema(): Observable { + getTestSpecification(): Observable { return this.http - .get(`${this.config.serviceRoot}api/v1/${this.serviceName}/configs/testschema`) - .pipe(map(x => x.test_schema)); + .get(`${this.config.serviceRoot}api/v1/${this.serviceName}/configs/testers`) + .pipe(map(result => result.config_testers)); } getSchema(): Observable { @@ -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)) { throw new DOMException('bad format response when deleting config'); } const configAndTestCases = { diff --git a/config-editor/config-editor-ui/src/app/services/editor.service.ts b/config-editor/config-editor-ui/src/app/services/editor.service.ts index f9affc198..8273e922b 100644 --- a/config-editor/config-editor-ui/src/app/services/editor.service.ts +++ b/config-editor/config-editor-ui/src/app/services/editor.service.ts @@ -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'; @@ -21,9 +21,9 @@ export class ServiceContext { adminSchema?: AdminSchemaService; configStore: ConfigStoreService; serviceName: string; - testSpecificationSchema?: JSONSchema7; adminMode: boolean; searchHistoryService?: SearchHistoryService; + testConfigSpec: TestConfigSpec[]; } @Injectable({ @@ -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, @@ -78,27 +77,23 @@ export class EditorService { } createConfigServiceContext(serviceName: string): Observable { - 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, @@ -107,7 +102,7 @@ export class EditorService { configStore, metaDataMap, serviceName, - testSpecificationSchema: testSpecSchema, + testConfigSpec: testSpec, searchHistoryService: new SearchHistoryService(this.config, serviceName), }; } @@ -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()])), + map(([adminConfig, originalSchema, testSpec]) => { + if (adminConfig && originalSchema && testSpec) { configStore.updateAdmin(adminConfig); return { adminMode: true, @@ -132,6 +127,7 @@ export class EditorService { configStore, metaDataMap, serviceName, + testConfigSpec: testSpec, }; } throwError(() => 'Can not load admin service'); diff --git a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts index 171798e87..19d1dd295 100644 --- a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts +++ b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts @@ -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'; @@ -225,12 +225,18 @@ export class ConfigStoreService { } reloadStoreAndRelease(): Observable { - const testCaseMapFun = this.metaDataMap.testing.testCaseEnabled ? this.configLoaderService.getTestCases() : of({}); 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); } From b3cc6f41a621debfb0c5a2253faaa20963dd99ad Mon Sep 17 00:00:00 2001 From: yasram1 Date: Tue, 2 Aug 2022 23:24:43 +0100 Subject: [PATCH 02/10] support for new config testers endpoint --- config/config-editor-ui/ui-bootstrap.json | 42 ++++------------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/config/config-editor-ui/ui-bootstrap.json b/config/config-editor-ui/ui-bootstrap.json index 06e80f4dc..fef8c0933 100644 --- a/config/config-editor-ui/ui-bootstrap.json +++ b/config/config-editor-ui/ui-bootstrap.json @@ -13,12 +13,7 @@ "version": "rule_version", "author": "rule_author", "description": "rule_description", - "labelsFunc": "const ret = []; if (model.evaluators && model.evaluators.length > 0){for(const e of model.evaluators) {ret.push(e.evaluator_type);} } return ret;", - "testing": { - "perConfigTestEnabled": true, - "releaseTestEnabled": true, - "testCaseEnabled": false - } + "labelsFunc": "const ret = []; if (model.evaluators && model.evaluators.length > 0){for(const e of model.evaluators) {ret.push(e.evaluator_type);} } return ret;" }, "alert": { "release": { @@ -34,12 +29,7 @@ "version": "rule_version", "author": "rule_author", "description": "rule_description", - "labelsFunc": "const ret = ['SourceType:' + model.source_type]; if (model.tags !== undefined) { ret.push(...model.tags.map(t => t.tag_name + ':' + t.tag_value));} return ret;", - "testing": { - "perConfigTestEnabled": true, - "releaseTestEnabled": true, - "testCaseEnabled": true - } + "labelsFunc": "const ret = ['SourceType:' + model.source_type]; if (model.tags !== undefined) { ret.push(...model.tags.map(t => t.tag_name + ':' + t.tag_value));} return ret;" }, "correlationalert": { "release": { @@ -55,12 +45,7 @@ "version": "rule_version", "author": "rule_author", "description": "rule_description", - "labelsFunc": "const ret = []; if(model.correlation_attributes.length > 0) { for(const alert of model.correlation_attributes[0].alerts){ret.push(alert.alert);}} if(model.tags !== undefined) { ret.push(...model.tags.map(t => t.tag_name + ':' + t.tag_value));} return ret;", - "testing": { - "perConfigTestEnabled": false, - "releaseTestEnabled": false, - "testCaseEnabled": false - } + "labelsFunc": "const ret = []; if(model.correlation_attributes.length > 0) { for(const alert of model.correlation_attributes[0].alerts){ret.push(alert.alert);}} if(model.tags !== undefined) { ret.push(...model.tags.map(t => t.tag_name + ':' + t.tag_value));} return ret;" }, "parserconfig": { "release": { @@ -72,12 +57,7 @@ "version": "parser_version", "author": "parser_author", "description": "parser_description", - "labelsFunc": "const ret = []; if (model.parser_attributes) {ret.push(model.parser_attributes.parser_type);} if (model.parser_extractors && model.parser_extractors.length > 0){for(const p of model.parser_extractors) {ret.push(p.extractor_type)} } return ret;", - "testing": { - "perConfigTestEnabled": true, - "releaseTestEnabled": false, - "testCaseEnabled": true - } + "labelsFunc": "const ret = []; if (model.parser_attributes) {ret.push(model.parser_attributes.parser_type);} if (model.parser_extractors && model.parser_extractors.length > 0){for(const p of model.parser_extractors) {ret.push(p.extractor_type)} } return ret;" }, "parsingapp": { "release": { @@ -89,12 +69,7 @@ "version": "parsing_app_version", "author": "parsing_app_author", "description": "parsing_app_description", - "labelsFunc": "const ret = []; if (model.parsing_app_settings) {ret.push(model.parsing_app_settings.parsing_app_type); for(const topic of model.parsing_app_settings.input_topics){ ret.push(topic);}} return ret;", - "testing": { - "perConfigTestEnabled": false, - "releaseTestEnabled": false, - "testCaseEnabled": false - } + "labelsFunc": "const ret = []; if (model.parsing_app_settings) {ret.push(model.parsing_app_settings.parsing_app_type); for(const topic of model.parsing_app_settings.input_topics){ ret.push(topic);}} return ret;" }, "enrichment": { "release": { @@ -106,11 +81,6 @@ "version": "rule_version", "author": "rule_author", "description": "rule_description", - "labelsFunc": "const ret = []; if(model.source_type) {ret.push(model.source_type);} if(model.table_mapping) {if(model.table_mapping.table_name){ret.push(model.table_mapping.table_name);} if(model.table_mapping.joining_key){ret.push(model.table_mapping.joining_key);}} return ret;", - "testing": { - "perConfigTestEnabled": true, - "releaseTestEnabled": false, - "testCaseEnabled": true - } + "labelsFunc": "const ret = []; if(model.source_type) {ret.push(model.source_type);} if(model.table_mapping) {if(model.table_mapping.table_name){ret.push(model.table_mapping.table_name);} if(model.table_mapping.joining_key){ret.push(model.table_mapping.joining_key);}} return ret;" } } From c763ffab4c4cd87a6a281009272fce2dff5321a8 Mon Sep 17 00:00:00 2001 From: yasram1 Date: Wed, 3 Aug 2022 08:33:39 +0100 Subject: [PATCH 03/10] increase version --- config-editor/config-editor-ui/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-editor/config-editor-ui/package.json b/config-editor/config-editor-ui/package.json index 3d448ee4e..7c14c037f 100644 --- a/config-editor/config-editor-ui/package.json +++ b/config-editor/config-editor-ui/package.json @@ -1,6 +1,6 @@ { "name": "rule-editor.ui", - "version": "2.6.6-dev", + "version": "2.6.7-dev", "license": "MIT", "scripts": { "ng": "ng", From 816d47987d6b68a8d3aaac60a37bc7bbaa6e3e12 Mon Sep 17 00:00:00 2001 From: yasram1 Date: Wed, 3 Aug 2022 13:51:23 +0100 Subject: [PATCH 04/10] clean up after review --- .../editor-view/editor-view.component.ts | 2 +- .../release-dialog/release-dialog.component.ts | 2 +- .../config-testing/config-testing.component.html | 2 +- .../config-testing/config-testing.component.ts | 10 +++++----- .../test-case-editor/test-case-editor.component.ts | 2 +- .../testing/test-centre/test-centre.component.ts | 2 +- .../src/app/services/config-loader.service.ts | 9 ++++++--- .../src/app/services/editor.service.ts | 14 +++++++++----- 8 files changed, 25 insertions(+), 18 deletions(-) diff --git a/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts b/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts index d734bc5d0..0eda56a50 100644 --- a/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts +++ b/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts @@ -74,7 +74,7 @@ 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); + 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 = () => diff --git a/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts b/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts index fa44d5e41..81dcbb2d9 100644 --- a/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts +++ b/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts @@ -92,7 +92,7 @@ export class ReleaseDialogComponent implements AfterViewChecked { }); } - const testConfig = this.service.testConfigSpec.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME); + const testConfig = this.service.getTestConfig(DEFAULT_CONFIG_TESTER_NAME); this.testEnabled = testConfig !== undefined ? testConfig.release_testing : false; this.environment = this.config.environment; diff --git a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html index 7c8933791..fee3b16b4 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html +++ b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html @@ -1,6 +1,6 @@
- +
diff --git a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts index a2728742c..714918b19 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts @@ -29,7 +29,7 @@ export class ConfigTestingComponent implements OnInit { { key: this.CONFIG_TESTER_KEY, type: "enum", - defaultValue: "default", + defaultValue: DEFAULT_CONFIG_TESTER_NAME, templateOptions: { label: "Config tester", hintEnd: "The name of the config tester selected", @@ -40,15 +40,15 @@ export class ConfigTestingComponent implements OnInit { }, }, ]; - model = {}; + configTesterModel = {}; formDropDown: FormGroup = new FormGroup({}); private testConfigSpec: TestConfigSpec = undefined; constructor(private editorService: EditorService, private cd: ChangeDetectorRef) {} ngOnInit() { - this.testConfigSpec = this.editorService.testConfigSpec.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME); - if (this.testConfigSpec.config_testing) { + this.testConfigSpec = this.editorService.getTestConfig(DEFAULT_CONFIG_TESTER_NAME); + if (this.testConfigSpec !== undefined && this.testConfigSpec.config_testing) { let schema = this.testConfigSpec.test_schema; this.editorService.configSchema.formatTitlesInSchema(schema, ''); this.field = new FormlyJsonschema().toFieldConfig(schema, { map: SchemaService.renameDescription }); @@ -78,7 +78,7 @@ export class ConfigTestingComponent implements OnInit { } updateConfigTester(testerName: string) { - const tester = this.editorService.testConfigSpec.find(x => x.name === testerName); + const tester = this.editorService.getTestConfig(testerName); if (tester !== undefined) { this.testConfigSpec = tester; if (this.testConfigSpec.config_testing) { diff --git a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts index 158a92960..2fd09f98a 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts @@ -46,7 +46,7 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy { } ngOnInit() { - this.testConfigSpec = this.editorService.testConfigSpec.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME); + 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); diff --git a/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts b/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts index a6bb64039..c90427b86 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts @@ -40,7 +40,7 @@ export class TestCentreComponent implements OnInit, OnDestroy { } ngOnInit() { - const testConfig = this.editorService.testConfigSpec.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME); + 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 => { diff --git a/config-editor/config-editor-ui/src/app/services/config-loader.service.ts b/config-editor/config-editor-ui/src/app/services/config-loader.service.ts index 6e005279d..4e286a863 100644 --- a/config-editor/config-editor-ui/src/app/services/config-loader.service.ts +++ b/config-editor/config-editor-ui/src/app/services/config-loader.service.ts @@ -36,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, @@ -375,9 +376,7 @@ export class ConfigLoaderService { null ) .pipe(map(result => { - const testCaseIsEnabled = this.getTestSpecification().pipe(map( resp => { - return resp ? resp.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME).test_case_testing : false; - })); + const testCaseIsEnabled = this.testConfigSpec !== undefined ? this.testConfigSpec.test_case_testing : false; if (!result.configs_files || (!result.test_cases_files && testCaseIsEnabled)) { throw new DOMException('bad format response when deleting config'); } @@ -416,6 +415,10 @@ export class ConfigLoaderService { .pipe(map(result => result)); } + setConfigTester(testConfig: TestConfigSpec) { + this.testConfigSpec = testConfig; + } + private testCaseFilesToMap(files: any[]): TestCaseMap { const testCaseMap: TestCaseMap = {}; if (files && files.length > 0) { diff --git a/config-editor/config-editor-ui/src/app/services/editor.service.ts b/config-editor/config-editor-ui/src/app/services/editor.service.ts index 8273e922b..1e217a0b9 100644 --- a/config-editor/config-editor-ui/src/app/services/editor.service.ts +++ b/config-editor/config-editor-ui/src/app/services/editor.service.ts @@ -23,7 +23,7 @@ export class ServiceContext { serviceName: string; adminMode: boolean; searchHistoryService?: SearchHistoryService; - testConfigSpec: TestConfigSpec[]; + testConfigSpec?: TestConfigSpec[]; } @Injectable({ @@ -83,6 +83,7 @@ export class EditorService { .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(), @@ -116,9 +117,9 @@ export class EditorService { return configLoader .getAdminSchema() .pipe( - mergeMap(schema => forkJoin([configLoader.getAdminConfig(), of(schema), configLoader.getTestSpecification()])), - map(([adminConfig, originalSchema, testSpec]) => { - if (adminConfig && originalSchema && testSpec) { + mergeMap(schema => forkJoin([configLoader.getAdminConfig(), of(schema)])), + map(([adminConfig, originalSchema]) => { + if (adminConfig && originalSchema) { configStore.updateAdmin(adminConfig); return { adminMode: true, @@ -127,7 +128,6 @@ export class EditorService { configStore, metaDataMap, serviceName, - testConfigSpec: testSpec, }; } throwError(() => 'Can not load admin service'); @@ -147,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); } From abd57336ceac6ff9fb3c1826a87edc178a3b2b10 Mon Sep 17 00:00:00 2001 From: yasram1 Date: Wed, 3 Aug 2022 16:52:44 +0100 Subject: [PATCH 05/10] improvements --- .../config-testing.component.html | 4 ++-- .../config-testing/config-testing.component.ts | 18 ++++++++++-------- .../src/app/services/config-loader.service.ts | 6 +++++- .../app/services/store/config-store.service.ts | 7 +++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html index fee3b16b4..464133ce7 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html +++ b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html @@ -1,6 +1,6 @@ -
- + +
diff --git a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts index 714918b19..233dc4ce5 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts @@ -25,7 +25,7 @@ export class ConfigTestingComponent implements OnInit { public output: any; private CONFIG_TESTER_KEY = "config_tester"; - fields: FormlyFieldConfig[] = [ + configTestersFields: FormlyFieldConfig[] = [ { key: this.CONFIG_TESTER_KEY, type: "enum", @@ -49,13 +49,17 @@ export class ConfigTestingComponent implements OnInit { ngOnInit() { this.testConfigSpec = this.editorService.getTestConfig(DEFAULT_CONFIG_TESTER_NAME); if (this.testConfigSpec !== undefined && 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.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) @@ -68,7 +72,7 @@ export class ConfigTestingComponent implements OnInit { } initDropdown() { - return this.fields.map(f => { + 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} @@ -82,9 +86,7 @@ export class ConfigTestingComponent implements OnInit { 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 }); + this.initSchema(); } } diff --git a/config-editor/config-editor-ui/src/app/services/config-loader.service.ts b/config-editor/config-editor-ui/src/app/services/config-loader.service.ts index 4e286a863..e0d9f6b9d 100644 --- a/config-editor/config-editor-ui/src/app/services/config-loader.service.ts +++ b/config-editor/config-editor-ui/src/app/services/config-loader.service.ts @@ -29,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, DEFAULT_CONFIG_TESTER_NAME } from '../model/config-model'; +import { TestCaseEvaluation, TestCaseResultAttributes } from '../model/config-model'; import { TestCaseEvaluationResult, isNewTestCase } from '../model/test-case'; import { replacer } from '@app/commons/helper-functions'; @@ -419,6 +419,10 @@ export class ConfigLoaderService { this.testConfigSpec = testConfig; } + getConfigTester() { + return this.testConfigSpec; + } + private testCaseFilesToMap(files: any[]): TestCaseMap { const testCaseMap: TestCaseMap = {}; if (files && files.length > 0) { diff --git a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts index 19d1dd295..d7aa04107 100644 --- a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts +++ b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts @@ -227,13 +227,12 @@ export class ConfigStoreService { reloadStoreAndRelease(): Observable { return forkJoin( this.configLoaderService.getConfigs(), - this.configLoaderService.getRelease(), - this.configLoaderService.getTestSpecification() - ).pipe(mergeMap(([configs, release, testConfig]) => { + this.configLoaderService.getRelease() + ).pipe(mergeMap(([configs, release]) => { return forkJoin( of(configs), of(release), - testConfig.find(x => x.name === DEFAULT_CONFIG_TESTER_NAME).test_case_testing ? this.configLoaderService.getTestCases() : of({}) + this.configLoaderService.getConfigTester().config_testing ? this.configLoaderService.getTestCases() : of({}) ) })) .pipe(map(([configs, release, testCaseMap]) => { From d850a075ff0d093c45b5c34518b1a8a010bdbae5 Mon Sep 17 00:00:00 2001 From: yasram1 Date: Wed, 3 Aug 2022 16:54:48 +0100 Subject: [PATCH 06/10] improvements --- .../src/app/services/store/config-store.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts index d7aa04107..c4ae907a1 100644 --- a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts +++ b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts @@ -232,7 +232,7 @@ export class ConfigStoreService { return forkJoin( of(configs), of(release), - this.configLoaderService.getConfigTester().config_testing ? this.configLoaderService.getTestCases() : of({}) + this.configLoaderService.getConfigTester().test_case_testing ? this.configLoaderService.getTestCases() : of({}) ) })) .pipe(map(([configs, release, testCaseMap]) => { From dba46e5bbe5b2e5c05ca721fcea609cb4d32a606 Mon Sep 17 00:00:00 2001 From: yasram1 Date: Wed, 3 Aug 2022 17:03:08 +0100 Subject: [PATCH 07/10] fix --- .../testing/config-testing/config-testing.component.html | 2 +- .../testing/config-testing/config-testing.component.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html index 464133ce7..af332886f 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html +++ b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.html @@ -1,5 +1,5 @@ -
+
diff --git a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts index 233dc4ce5..5f8d836e6 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts @@ -43,6 +43,7 @@ export class ConfigTestingComponent implements OnInit { configTesterModel = {}; formDropDown: FormGroup = new FormGroup({}); private testConfigSpec: TestConfigSpec = undefined; + numTesters = 0; constructor(private editorService: EditorService, private cd: ChangeDetectorRef) {} @@ -72,6 +73,7 @@ export class ConfigTestingComponent implements OnInit { } 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 => { From a03b92f939b3e22ba348d939829717f7b1060438 Mon Sep 17 00:00:00 2001 From: yasram1 Date: Fri, 5 Aug 2022 09:28:41 +0100 Subject: [PATCH 08/10] support testing per tester type --- .../editor-view/editor-view.component.ts | 9 +- .../release-dialog.component.ts | 6 +- .../config-testing.component.ts | 16 ++-- .../test-case-editor.component.html | 3 + .../test-case-editor.component.ts | 93 ++++++++++++++----- .../test-centre/test-centre.component.ts | 6 +- .../src/app/model/config-model.ts | 6 +- .../src/app/model/store-state.ts | 3 +- .../src/app/services/config-loader.service.ts | 16 +--- .../src/app/services/editor.service.ts | 37 ++++++-- .../store/config-store-state.builder.ts | 7 +- .../services/store/config-store.service.ts | 14 ++- .../config-editor-ui/src/testing/store.ts | 1 + 13 files changed, 145 insertions(+), 72 deletions(-) diff --git a/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts b/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts index 0eda56a50..fe683f82c 100644 --- a/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts +++ b/config-editor/config-editor-ui/src/app/components/editor-view/editor-view.component.ts @@ -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, DEFAULT_CONFIG_TESTER_NAME, TestingType } from '@app/model/config-model'; +import { FILTER_PARAM_KEY, SEARCH_PARAM_KEY, TestingType } from '@app/model/config-model'; import { SchemaService } from '@app/services/schema/schema.service'; @Component({ @@ -74,13 +74,10 @@ 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 = () => - testConfigIsEnabled && this.editorComponent.form.valid; + this.editorService.testSpecificationTesters.config_testing.length > 0 && this.editorComponent.form.valid; this.testCaseEnabled = () => - testCaseConfigIsEnabled && this.editorComponent.form.valid && !config.isNew; + this.editorService.testSpecificationTesters.test_case_testing.length > 0 && this.editorComponent.form.valid && !config.isNew; }); } diff --git a/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts b/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts index 81dcbb2d9..5888e3161 100644 --- a/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts +++ b/config-editor/config-editor-ui/src/app/components/release-dialog/release-dialog.component.ts @@ -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, DEFAULT_CONFIG_TESTER_NAME } from '@app/model/config-model'; +import { ReleaseWrapper, TestingType } from '@app/model/config-model'; @Component({ @@ -91,9 +91,7 @@ export class ReleaseDialogComponent implements AfterViewChecked { } }); } - - const testConfig = this.service.getTestConfig(DEFAULT_CONFIG_TESTER_NAME); - this.testEnabled = testConfig !== undefined ? testConfig.release_testing : false; + this.testEnabled = this.service.testSpecificationTesters.release_testing.length > 0; this.environment = this.config.environment; this.service.configStore.initialRelease$.subscribe((d: Release) => { diff --git a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts index 5f8d836e6..7ddb3db23 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/config-testing/config-testing.component.ts @@ -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, TestConfigSpec, DEFAULT_CONFIG_TESTER_NAME } from '../../../model/config-model'; +import { ConfigTestResult, TestingType, TestConfigSpec } 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'; @@ -29,7 +29,6 @@ export class ConfigTestingComponent implements OnInit { { key: this.CONFIG_TESTER_KEY, type: "enum", - defaultValue: DEFAULT_CONFIG_TESTER_NAME, templateOptions: { label: "Config tester", hintEnd: "The name of the config tester selected", @@ -48,8 +47,9 @@ export class ConfigTestingComponent implements OnInit { constructor(private editorService: EditorService, private cd: ChangeDetectorRef) {} ngOnInit() { - this.testConfigSpec = this.editorService.getTestConfig(DEFAULT_CONFIG_TESTER_NAME); - if (this.testConfigSpec !== undefined && this.testConfigSpec.config_testing) { + this.numTesters = this.editorService.testSpecificationTesters.config_testing.length; + if (this.numTesters > 0) { + this.testConfigSpec = this.editorService.getTestConfig(this.editorService.testSpecificationTesters.config_testing[0]); this.initSchema(); this.initDropdown(); } @@ -73,11 +73,11 @@ export class ConfigTestingComponent implements OnInit { } 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} + f.defaultValue = this.editorService.testSpecificationTesters.config_testing[0]; + f.templateOptions.options = this.editorService.testSpecificationTesters.config_testing.map(testerName => { + return { value: testerName, label: testerName} }) } }) @@ -91,6 +91,6 @@ export class ConfigTestingComponent implements OnInit { this.initSchema(); } } - } + } diff --git a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.html b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.html index cec237927..18f445aad 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.html +++ b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.html @@ -1,3 +1,6 @@ +
+ +

{{ testCase.test_case_name }} v{{ testCase.version }}

diff --git a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts index 2fd09f98a..1cd1d03d3 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts @@ -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, TestConfigSpec, DEFAULT_CONFIG_TESTER_NAME } from '@app/model/config-model'; +import { Type, TestConfigSpec } from '@app/model/config-model'; import { FormlyFieldConfig } from '@ngx-formly/core'; import { cloneDeep } from 'lodash'; import { EditorService } from '@app/services/editor.service'; @@ -34,6 +34,25 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy { form: FormGroup = new FormGroup({}); private markHistoryChange = false; private testConfigSpec: TestConfigSpec = undefined; + private TEST_CASE_TESTER_KEY = "test_case_tester"; + testCaseConfigTestersFields: FormlyFieldConfig[] = [ + { + key: this.TEST_CASE_TESTER_KEY, + type: "enum", + templateOptions: { + label: "Config tester", + hintEnd: "The name of the config tester selected", + change: (field, $event) => { + this.updateConfigTester($event.value); + }, + options: [] + }, + }, + ]; + testCaseConfigTesterModel = {}; + dropDownForm: FormGroup = new FormGroup({}); + numTesters = 0; + constructor( private appService: AppService, private editorService: EditorService, @@ -46,28 +65,12 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy { } ngOnInit() { - 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(); - this.editorService.configSchema.formatTitlesInSchema(schema, ''); - this.options = { - resetOnHide: false, - map: SchemaService.renameDescription, - }; - this.field = schemaConverter.toFieldConfig(schema, this.options); - - this.editedTestCase$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(testCaseWrapper => { - this.testCaseWrapper = testCaseWrapper; - if ( - testCaseWrapper && - !this.editorService.configSchema.areTestCasesEqual(testCaseWrapper.testCase, this.testCase) - ) { - this.testCase = cloneDeep(this.testCaseWrapper.testCase); - } - }); + console.log("here"); + this.numTesters = this.editorService.testSpecificationTesters.test_case_testing.length; + if (this.numTesters > 0) { + this.testConfigSpec = this.editorService.getTestConfig(this.editorService.testSpecificationTesters.test_case_testing[0]); + this.initSchema(); + this.initDropdown(); } this.form.valueChanges.pipe(debounceTime(300), takeUntil(this.ngUnsubscribe)).subscribe(() => { if (this.form.valid && !this.markHistoryChange) { @@ -76,6 +79,28 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy { this.markHistoryChange = false; }); } + initSchema() { + const subschema = cloneDeep(this.testConfigSpec.test_schema); + const schema = cloneDeep(this.appService.testCaseSchema); + schema.properties.test_specification = subschema; + const schemaConverter = new FormlyJsonschema(); + this.editorService.configSchema.formatTitlesInSchema(schema, ''); + this.options = { + resetOnHide: false, + map: SchemaService.renameDescription, + }; + this.field = schemaConverter.toFieldConfig(schema, this.options); + + this.editedTestCase$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(testCaseWrapper => { + this.testCaseWrapper = testCaseWrapper; + if ( + testCaseWrapper && + !this.editorService.configSchema.areTestCasesEqual(testCaseWrapper.testCase, this.testCase) + ) { + this.testCase = cloneDeep(this.testCaseWrapper.testCase); + } + }); + } ngOnDestroy() { this.ngUnsubscribe.next(); @@ -152,4 +177,26 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy { ret.testCase = copyHiddenTestCaseFields(cloneDeep(testCase), this.testCase); return ret; } + + initDropdown() { + return this.testCaseConfigTestersFields.map(f => { + if (f.key === this.TEST_CASE_TESTER_KEY) { + f.defaultValue = this.editorService.testSpecificationTesters.test_case_testing[0]; + f.templateOptions.options = this.editorService.testSpecificationTesters.test_case_testing.map(testerName => { + return { value: testerName, label: testerName} + }) + } + }) + } + + updateConfigTester(testerName: string) { + const tester = this.editorService.getTestConfig(testerName); + if (tester !== undefined) { + this.testConfigSpec = tester; + if (this.testConfigSpec.test_case_testing) { + this.initSchema(); + } + } + } + } diff --git a/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts b/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts index c90427b86..6070e3f08 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/test-centre/test-centre.component.ts @@ -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, DEFAULT_CONFIG_TESTER_NAME } from '@app/model/config-model'; +import { Type } from '@app/model/config-model'; @Component({ selector: 're-test-centre', @@ -40,9 +40,7 @@ export class TestCentreComponent implements OnInit, OnDestroy { } ngOnInit() { - const testConfig = this.editorService.getTestConfig(DEFAULT_CONFIG_TESTER_NAME); - const testCaseConfigEnabled = testConfig !== undefined ? testConfig.test_case_testing : false; - if (testCaseConfigEnabled) { + if (this.editorService.testSpecificationTesters.test_case_testing.length > 0) { this.testCases$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(testCases => { this.testCases = testCases; }); diff --git a/config-editor/config-editor-ui/src/app/model/config-model.ts b/config-editor/config-editor-ui/src/app/model/config-model.ts index d29818ce2..e84998a73 100644 --- a/config-editor/config-editor-ui/src/app/model/config-model.ts +++ b/config-editor/config-editor-ui/src/app/model/config-model.ts @@ -305,4 +305,8 @@ export interface TestConfigSpecTesters { config_testers: TestConfigSpec[]; } -export const DEFAULT_CONFIG_TESTER_NAME = "default"; \ No newline at end of file +export interface TestSpecificationTesters { + config_testing: string[]; + test_case_testing: string[]; + release_testing: string[]; +} \ No newline at end of file diff --git a/config-editor/config-editor-ui/src/app/model/store-state.ts b/config-editor/config-editor-ui/src/app/model/store-state.ts index 91d7ec6e3..83b9a5911 100644 --- a/config-editor/config-editor-ui/src/app/model/store-state.ts +++ b/config-editor/config-editor-ui/src/app/model/store-state.ts @@ -1,6 +1,6 @@ import { Config, Release, FileHistory } from '.'; import { TestCaseMap, TestCaseWrapper } from './test-case'; -import { AdminConfig, ConfigManagerRow } from './config-model'; +import { AdminConfig, ConfigManagerRow, TestSpecificationTesters } from './config-model'; import { FilterConfig } from './ui-metadata-map'; export interface ConfigStoreState { @@ -22,4 +22,5 @@ export interface ConfigStoreState { isAnyFilterPresent: boolean; user: string; serviceFilterConfig: FilterConfig; + testSpecificationTesters: TestSpecificationTesters; } diff --git a/config-editor/config-editor-ui/src/app/services/config-loader.service.ts b/config-editor/config-editor-ui/src/app/services/config-loader.service.ts index e0d9f6b9d..6266543b3 100644 --- a/config-editor/config-editor-ui/src/app/services/config-loader.service.ts +++ b/config-editor/config-editor-ui/src/app/services/config-loader.service.ts @@ -36,7 +36,6 @@ 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, @@ -81,7 +80,7 @@ export class ConfigLoaderService { })); } - getTestSpecification(): Observable { + getConfigTesters(): Observable { return this.http .get(`${this.config.serviceRoot}api/v1/${this.serviceName}/configs/testers`) .pipe(map(result => result.config_testers)); @@ -369,14 +368,13 @@ export class ConfigLoaderService { .pipe(map(x => x.test_case_result)); } - deleteConfig(configName: string): Observable { + deleteConfig(configName: string, testCaseIsEnabled: boolean): Observable { return this.http .post>( `${this.config.serviceRoot}api/v1/${this.serviceName}/configstore/configs/delete?configName=${configName}`, null ) - .pipe(map(result => { - const testCaseIsEnabled = this.testConfigSpec !== undefined ? this.testConfigSpec.test_case_testing : false; + .pipe(map(result => { if (!result.configs_files || (!result.test_cases_files && testCaseIsEnabled)) { throw new DOMException('bad format response when deleting config'); } @@ -415,14 +413,6 @@ export class ConfigLoaderService { .pipe(map(result => result)); } - setConfigTester(testConfig: TestConfigSpec) { - this.testConfigSpec = testConfig; - } - - getConfigTester() { - return this.testConfigSpec; - } - private testCaseFilesToMap(files: any[]): TestCaseMap { const testCaseMap: TestCaseMap = {}; if (files && files.length > 0) { diff --git a/config-editor/config-editor-ui/src/app/services/editor.service.ts b/config-editor/config-editor-ui/src/app/services/editor.service.ts index 1e217a0b9..fd787a6cb 100644 --- a/config-editor/config-editor-ui/src/app/services/editor.service.ts +++ b/config-editor/config-editor-ui/src/app/services/editor.service.ts @@ -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, TestConfigSpec, DEFAULT_CONFIG_TESTER_NAME } from '@app/model/config-model'; +import { CheckboxEvent, FILTER_PARAM_KEY, ServiceSearch, TestConfigSpec, TestSpecificationTesters } from '@app/model/config-model'; import { SearchHistoryService } from './search-history.service'; import { ParamMap } from '@angular/router'; @@ -24,6 +24,7 @@ export class ServiceContext { adminMode: boolean; searchHistoryService?: SearchHistoryService; testConfigSpec?: TestConfigSpec[]; + testSpecificationTesters?: TestSpecificationTesters; } @Injectable({ @@ -62,6 +63,9 @@ export class EditorService { get testConfigSpec() { return this.serviceContext.testConfigSpec; } + get testSpecificationTesters() { + return this.serviceContext.testSpecificationTesters; + } constructor( private http: HttpClient, @@ -79,23 +83,23 @@ export class EditorService { createConfigServiceContext(serviceName: string): Observable { const [metaDataMap, user, configLoader, configStore] = this.initialiseContext(serviceName); - return forkJoin(configLoader.getSchema(), configLoader.getTestSpecification()) + return forkJoin(configLoader.getSchema(), configLoader.getConfigTesters()) .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); + let testers: TestSpecificationTesters = this.getTestersPerType(testConfig); return forkJoin( configLoader.getConfigs(), configLoader.getRelease(), of(schema), of(testConfig), - testCasesConfig ? configLoader.getTestCases() : of({}) + testers.config_testing.length > 0 ? configLoader.getTestCases() : of({}), + of(testers) ) })) - .pipe(map(([configs, release, originalSchema, testSpec, testCaseMap]) => { - if (configs && release && originalSchema && testSpec && testCaseMap) { + .pipe(map(([configs, release, originalSchema, testSpec, testCaseMap, testersType]) => { + if (configs && release && originalSchema && testSpec && testCaseMap && testersType) { configStore.initialise(configs, release, testCaseMap, user, metaDataMap); + configStore.updateConfigTesters(testersType); return { adminMode: false, configLoader, @@ -104,6 +108,7 @@ export class EditorService { metaDataMap, serviceName, testConfigSpec: testSpec, + testSpecificationTesters: testersType, searchHistoryService: new SearchHistoryService(this.config, serviceName), }; } @@ -151,6 +156,22 @@ export class EditorService { return this.testConfigSpec.find(x => x.name === name); } + getTestersPerType(testConfig: TestConfigSpec[]): TestSpecificationTesters { + let testers: TestSpecificationTesters = {config_testing: [], test_case_testing: [], release_testing: []}; + testConfig.forEach((tester: TestConfigSpec) => { + if (tester.config_testing) { + testers.config_testing.push(tester.name); + } + if (tester.test_case_testing) { + testers.test_case_testing.push(tester.name); + } + if (tester.release_testing) { + testers.release_testing.push(tester.name); + } + }); + return testers; + } + onSaveSearch(currentParams: ParamMap): ServiceSearch[] { return this.serviceContext.searchHistoryService.addToSearchHistory(currentParams); } diff --git a/config-editor/config-editor-ui/src/app/services/store/config-store-state.builder.ts b/config-editor/config-editor-ui/src/app/services/store/config-store-state.builder.ts index 71a53ef85..a1afdb6be 100644 --- a/config-editor/config-editor-ui/src/app/services/store/config-store-state.builder.ts +++ b/config-editor/config-editor-ui/src/app/services/store/config-store-state.builder.ts @@ -4,7 +4,7 @@ import { moveItemInArray } from '@angular/cdk/drag-drop'; import { Config, Release, FileHistory } from '../../model'; import { TestCaseMap } from '@app/model/test-case'; import { TestCaseWrapper, TestCaseResult } from '../../model/test-case'; -import { AdminConfig, ConfigManagerRow, ConfigStatus, FILTER_DELIMITER } from '@app/model/config-model'; +import { AdminConfig, ConfigManagerRow, ConfigStatus, FILTER_DELIMITER, TestSpecificationTesters } from '@app/model/config-model'; import { FilterConfig, UiMetadata } from '@app/model/ui-metadata-map'; export class ConfigStoreStateBuilder { @@ -287,4 +287,9 @@ export class ConfigStoreStateBuilder { }, } } + + updateConfigTesters(testers: TestSpecificationTesters) { + this.state.testSpecificationTesters = testers; + return this; + } } diff --git a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts index c4ae907a1..ced1f25a9 100644 --- a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts +++ b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts @@ -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, DEFAULT_CONFIG_TESTER_NAME, Type } from '@app/model/config-model'; +import { AdminConfig, ConfigAndTestsToClone, ConfigToImport, ExistingConfigError, FILTER_PARAM_KEY, Importers, SEARCH_PARAM_KEY, Type, TestSpecificationTesters } from '@app/model/config-model'; import { ClipboardStoreService } from '../clipboard-store.service'; import { ConfigHistoryService } from '../config-history.service'; import { AppConfigService } from '../app-config.service'; @@ -33,6 +33,7 @@ const initialConfigStoreState: ConfigStoreState = { isAnyFilterPresent: false, serviceFilterConfig: undefined, user: undefined, + testSpecificationTesters: undefined, }; const initialPullRequestState: PullRequestInfo = { @@ -71,6 +72,7 @@ export class ConfigStoreService { public readonly isAnyFilterPresent$ = this.store.asObservable().pipe(map(x => x.isAnyFilterPresent)); public readonly serviceFilterConfig$ = this.store.asObservable().pipe(map(x => x.serviceFilterConfig)); public readonly serviceFilters$ = this.store.asObservable().pipe(map(x => x.serviceFilters)); + public readonly testSpecificationTesters$ = this.store.asObservable(); /*eslint-enable */ @@ -131,6 +133,11 @@ export class ConfigStoreService { } } + updateConfigTesters(testers: TestSpecificationTesters) { + const newState = new ConfigStoreStateBuilder(this.store.getValue()).updateConfigTesters(testers).build(); + this.store.next(newState); + } + updateAdmin(config: AdminConfig) { const newState = new ConfigStoreStateBuilder(this.store.getValue()).adminConfig(config).build(); this.store.next(newState); @@ -232,7 +239,7 @@ export class ConfigStoreService { return forkJoin( of(configs), of(release), - this.configLoaderService.getConfigTester().test_case_testing ? this.configLoaderService.getTestCases() : of({}) + this.store.getValue().testSpecificationTesters.test_case_testing.length > 0 ? this.configLoaderService.getTestCases() : of({}) ) })) .pipe(map(([configs, release, testCaseMap]) => { @@ -427,7 +434,8 @@ export class ConfigStoreService { } deleteConfig(configName: string): Observable { - return this.configLoaderService.deleteConfig(configName).pipe(map(data => { + const testCaseIsEnabled = this.store.getValue().testSpecificationTesters.test_case_testing.length > 0; + return this.configLoaderService.deleteConfig(configName, testCaseIsEnabled).pipe(map(data => { const newState = new ConfigStoreStateBuilder(this.store.getValue()) .testCaseMap(data.testCases) .configs(data.configs) diff --git a/config-editor/config-editor-ui/src/testing/store.ts b/config-editor/config-editor-ui/src/testing/store.ts index 87d462018..1b384fc3a 100644 --- a/config-editor/config-editor-ui/src/testing/store.ts +++ b/config-editor/config-editor-ui/src/testing/store.ts @@ -24,4 +24,5 @@ export const mockStore: ConfigStoreState = { isAnyFilterPresent: false, serviceFilterConfig: {}, user: "siembol", + testSpecificationTesters: undefined }; From 51255f06b8e66f563e182435ff698817069df389 Mon Sep 17 00:00:00 2001 From: yasram1 Date: Fri, 5 Aug 2022 10:10:08 +0100 Subject: [PATCH 09/10] clean --- .../testing/test-case-editor/test-case-editor.component.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts index 1cd1d03d3..18b51931d 100644 --- a/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts +++ b/config-editor/config-editor-ui/src/app/components/testing/test-case-editor/test-case-editor.component.ts @@ -40,8 +40,8 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy { key: this.TEST_CASE_TESTER_KEY, type: "enum", templateOptions: { - label: "Config tester", - hintEnd: "The name of the config tester selected", + label: "Test case tester", + hintEnd: "The name of the test case tester selected", change: (field, $event) => { this.updateConfigTester($event.value); }, @@ -65,7 +65,6 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy { } ngOnInit() { - console.log("here"); this.numTesters = this.editorService.testSpecificationTesters.test_case_testing.length; if (this.numTesters > 0) { this.testConfigSpec = this.editorService.getTestConfig(this.editorService.testSpecificationTesters.test_case_testing[0]); From 0e84f0370bfaaa8c58d381d08e35cf2958fd8b97 Mon Sep 17 00:00:00 2001 From: yasram1 Date: Fri, 5 Aug 2022 11:59:06 +0100 Subject: [PATCH 10/10] refactoring --- .../src/app/services/editor.service.ts | 3 +-- .../services/store/config-store.service.ts | 24 +++++++------------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/config-editor/config-editor-ui/src/app/services/editor.service.ts b/config-editor/config-editor-ui/src/app/services/editor.service.ts index fd787a6cb..9d7ff4dc0 100644 --- a/config-editor/config-editor-ui/src/app/services/editor.service.ts +++ b/config-editor/config-editor-ui/src/app/services/editor.service.ts @@ -98,8 +98,7 @@ export class EditorService { .pipe(map(([configs, release, originalSchema, testSpec, testCaseMap, testersType]) => { if (configs && release && originalSchema && testSpec && testCaseMap && testersType) { - configStore.initialise(configs, release, testCaseMap, user, metaDataMap); - configStore.updateConfigTesters(testersType); + configStore.initialise(configs, release, testCaseMap, user, metaDataMap, testersType); return { adminMode: false, configLoader, diff --git a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts index ced1f25a9..470bd55df 100644 --- a/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts +++ b/config-editor/config-editor-ui/src/app/services/store/config-store.service.ts @@ -72,7 +72,7 @@ export class ConfigStoreService { public readonly isAnyFilterPresent$ = this.store.asObservable().pipe(map(x => x.isAnyFilterPresent)); public readonly serviceFilterConfig$ = this.store.asObservable().pipe(map(x => x.serviceFilterConfig)); public readonly serviceFilters$ = this.store.asObservable().pipe(map(x => x.serviceFilters)); - public readonly testSpecificationTesters$ = this.store.asObservable(); + public readonly testSpecificationTesters$ = this.store.asObservable().pipe(map(x => x.testSpecificationTesters)); /*eslint-enable */ @@ -110,7 +110,8 @@ export class ConfigStoreService { release: any, testCaseMap: TestCaseMap, user: string, - uiMetadata: UiMetadata + uiMetadata: UiMetadata, + testers?: TestSpecificationTesters ) { const newState = new ConfigStoreStateBuilder(this.store.getValue()) .user(user) @@ -124,6 +125,7 @@ export class ConfigStoreService { .detectOutdatedConfigs() .reorderConfigsByRelease() .computeConfigManagerRowData() + .updateConfigTesters(testers) .build(); this.store.next(newState); @@ -133,11 +135,6 @@ export class ConfigStoreService { } } - updateConfigTesters(testers: TestSpecificationTesters) { - const newState = new ConfigStoreStateBuilder(this.store.getValue()).updateConfigTesters(testers).build(); - this.store.next(newState); - } - updateAdmin(config: AdminConfig) { const newState = new ConfigStoreStateBuilder(this.store.getValue()).adminConfig(config).build(); this.store.next(newState); @@ -232,17 +229,12 @@ export class ConfigStoreService { } reloadStoreAndRelease(): Observable { + const testCaseMapFun = this.store.getValue().testSpecificationTesters.test_case_testing.length > 0 ? this.configLoaderService.getTestCases() : of({}); return forkJoin( this.configLoaderService.getConfigs(), - this.configLoaderService.getRelease() - ).pipe(mergeMap(([configs, release]) => { - return forkJoin( - of(configs), - of(release), - this.store.getValue().testSpecificationTesters.test_case_testing.length > 0 ? this.configLoaderService.getTestCases() : of({}) - ) - })) - .pipe(map(([configs, release, testCaseMap]) => { + this.configLoaderService.getRelease(), + testCaseMapFun + ).pipe(map(([configs, release, testCaseMap]) => { if (configs && release && testCaseMap) { this.initialise(configs, release, testCaseMap, this.user, this.metaDataMap); }