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 9 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 @@ -75,9 +75,9 @@ export class EditorViewComponent implements OnInit, OnDestroy, AfterViewInit {
this.editedConfig$.pipe(takeUntil(this.ngUnsubscribe)).subscribe((config: Config) => {
this.configData = config.configData;
this.testingEnabled = () =>
this.editorService.metaDataMap.testing.perConfigTestEnabled && this.editorComponent.form.valid;
this.editorService.testSpecificationTesters.config_testing.length > 0 && this.editorComponent.form.valid;
this.testCaseEnabled = () =>
this.editorService.metaDataMap.testing.testCaseEnabled && this.editorComponent.form.valid && !config.isNew;
this.editorService.testSpecificationTesters.test_case_testing.length > 0 && this.editorComponent.form.valid && !config.isNew;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class ReleaseDialogComponent implements AfterViewChecked {
}
});
}
this.testEnabled = this.uiMetadata.testing.releaseTestEnabled;
this.testEnabled = this.service.testSpecificationTesters.release_testing.length > 0;
this.environment = this.config.environment;

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

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

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

ngOnInit() {
if (this.editorService.metaDataMap.testing.perConfigTestEnabled) {
let schema = this.editorService.testSpecificationSchema;
this.editorService.configSchema.formatTitlesInSchema(schema, '');
this.field = new FormlyJsonschema().toFieldConfig(schema, { map: SchemaService.renameDescription });
this.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();
}
}

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

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

initDropdown() {
return this.configTestersFields.map(f => {
if (f.key === this.CONFIG_TESTER_KEY) {
f.defaultValue = this.editorService.testSpecificationTesters.config_testing[0];
f.templateOptions.options = this.editorService.testSpecificationTesters.config_testing.map(testerName => {
return { value: testerName, label: testerName}
})
}
})
}

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

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<form *ngIf="numTesters > 1" [formGroup]="form">
<formly-form [model]="testCaseConfigTesterModel" [fields]="testCaseConfigTestersFields" [options]="options" [form]="dropDownForm"></formly-form>
</form>
<mat-card-title>
<button mat-raised-button title="Test Suite" (click)="onCancelEditing()"><</button>
<h2>{{ testCase.test_case_name }} v{{ testCase.version }}</h2>
Expand Down
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 } 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,26 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy {
testStoreService: TestStoreService;
form: FormGroup = new FormGroup({});
private markHistoryChange = false;
private testConfigSpec: TestConfigSpec = undefined;
private TEST_CASE_TESTER_KEY = "test_case_tester";
testCaseConfigTestersFields: FormlyFieldConfig[] = [
yasram1 marked this conversation as resolved.
Show resolved Hide resolved
{
key: this.TEST_CASE_TESTER_KEY,
type: "enum",
templateOptions: {
label: "Test case tester",
hintEnd: "The name of the test case tester selected",
change: (field, $event) => {
this.updateConfigTester($event.value);
},
options: []
},
},
];
testCaseConfigTesterModel = {};
dropDownForm: FormGroup = new FormGroup({});
numTesters = 0;

constructor(
private appService: AppService,
private editorService: EditorService,
Expand All @@ -45,27 +65,11 @@ export class TestCaseEditorComponent implements OnInit, OnDestroy {
}

ngOnInit() {
if (this.editorService.metaDataMap.testing.testCaseEnabled) {
const subschema = cloneDeep(this.editorService.testSpecificationSchema);
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);
}
});
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) {
Expand All @@ -74,6 +78,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();
Expand Down Expand Up @@ -150,4 +176,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();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class TestCentreComponent implements OnInit, OnDestroy {
}

ngOnInit() {
if (this.editorService.metaDataMap.testing.testCaseEnabled) {
if (this.editorService.testSpecificationTesters.test_case_testing.length > 0) {
this.testCases$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(testCases => {
this.testCases = testCases;
});
Expand Down
19 changes: 19 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,22 @@ 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 interface TestSpecificationTesters {
config_testing: string[];
test_case_testing: string[];
release_testing: string[];
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -22,4 +22,5 @@ export interface ConfigStoreState {
isAnyFilterPresent: boolean;
user: string;
serviceFilterConfig: FilterConfig;
testSpecificationTesters: TestSpecificationTesters;
}
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 Down Expand Up @@ -79,10 +80,10 @@ export class ConfigLoaderService {
}));
}

getTestSpecificationSchema(): Observable<JSONSchema7> {
getConfigTesters(): Observable<TestConfigSpec[]> {
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 @@ -367,14 +368,14 @@ export class ConfigLoaderService {
.pipe(map(x => x.test_case_result));
}

deleteConfig(configName: string): Observable<ConfigAndTestCases> {
deleteConfig(configName: string, testCaseIsEnabled: boolean): Observable<ConfigAndTestCases> {
return this.http
.post<GitFilesDelete<any>>(
`${this.config.serviceRoot}api/v1/${this.serviceName}/configstore/configs/delete?configName=${configName}`,
null
)
.pipe(map(result => {
if (!result.configs_files || (!result.test_cases_files && this.uiMetadata.testing.testCaseEnabled)) {
.pipe(map(result => {
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
Loading