Skip to content

Commit 6de74e9

Browse files
authored
UI: Fix unit tests (#1977)
* Fix Katib unit tests. Signed-off-by: Elena Zioga <[email protected]> Signed-off-by: Elena Zioga <[email protected]>
1 parent e444ea9 commit 6de74e9

File tree

40 files changed

+875
-89
lines changed

40 files changed

+875
-89
lines changed

pkg/new-ui/v1beta1/frontend/angular.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
"karmaConfig": "karma.conf.js",
9595
"assets": ["src/favicon.ico", "src/assets"],
9696
"styles": ["src/styles.scss"],
97-
"scripts": []
97+
"scripts": [],
98+
"preserveSymlinks": true
9899
}
99100
},
100101
"lint": {

pkg/new-ui/v1beta1/frontend/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/new-ui/v1beta1/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"echarts-stat": "^1.2.0",
3838
"js-yaml": "^4.0.0",
3939
"lodash-es": "4.17.11",
40-
"material-icons": "^0.3.1",
40+
"material-icons": "^0.7.7",
4141
"ng2-ace-editor": "^0.3.9",
4242
"ngx-echarts": "^8.0.1",
4343
"ngx-json-viewer": "^2.4.0",
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { TestBed, waitForAsync } from '@angular/core/testing';
22
import { AppComponent } from './app.component';
3+
import { BrowserModule } from '@angular/platform-browser';
4+
import { AppRoutingModule } from './app-routing.module';
35

46
describe('AppComponent', () => {
57
beforeEach(
68
waitForAsync(() => {
79
TestBed.configureTestingModule({
10+
imports: [BrowserModule, AppRoutingModule],
811
declarations: [AppComponent],
912
}).compileComponents();
1013
}),
@@ -21,13 +24,4 @@ describe('AppComponent', () => {
2124
const app = fixture.debugElement.componentInstance;
2225
expect(app.title).toEqual('frontend');
2326
});
24-
25-
it('should render title', () => {
26-
const fixture = TestBed.createComponent(AppComponent);
27-
fixture.detectChanges();
28-
const compiled = fixture.debugElement.nativeElement;
29-
expect(compiled.querySelector('.content span').textContent).toContain(
30-
'frontend app is running!',
31-
);
32-
});
3327
});

pkg/new-ui/v1beta1/frontend/src/app/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { AppComponent } from './app.component';
88
import { ExperimentsModule } from './pages/experiments/experiments.module';
99
import { ExperimentDetailsModule } from './pages/experiment-details/experiment-details.module';
1010
import { ExperimentCreationModule } from './pages/experiment-creation/experiment-creation.module';
11-
import { TrialModalModule } from './pages/experiment-details/trials-table/trial-modal/trial-modal.module';
1211

1312
@NgModule({
1413
declarations: [AppComponent],
@@ -20,7 +19,6 @@ import { TrialModalModule } from './pages/experiment-details/trials-table/trial-
2019
ExperimentDetailsModule,
2120
ReactiveFormsModule,
2221
ExperimentCreationModule,
23-
TrialModalModule,
2422
],
2523
providers: [],
2624
bootstrap: [AppComponent],

pkg/new-ui/v1beta1/frontend/src/app/models/trial.k8s.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ interface TrialStatus {
7676

7777
interface TrialStatusCondition {
7878
type: string;
79-
status: boolean;
79+
status: string;
8080
reason: string;
8181
message: string;
8282
lastUpdateTime: string;

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/algorithm/algorithm.component.spec.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,46 @@
1+
import { CommonModule } from '@angular/common';
12
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3+
import { FormArray, FormControl, FormGroup } from '@angular/forms';
4+
import { MatFormFieldModule } from '@angular/material/form-field';
5+
import { MatInputModule } from '@angular/material/input';
6+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
7+
import { MatSelectModule } from '@angular/material/select';
8+
import { MatRadioModule } from '@angular/material/radio';
9+
import { FormModule } from 'kubeflow';
210

3-
import { AlgorithmComponent } from './algorithm.component';
11+
import { FormAlgorithmComponent } from './algorithm.component';
12+
import { FormAlgorithmModule } from './algorithm.module';
413

5-
describe('AlgorithmComponent', () => {
6-
let component: AlgorithmComponent;
7-
let fixture: ComponentFixture<AlgorithmComponent>;
14+
describe('FormAlgorithmComponent', () => {
15+
let component: FormAlgorithmComponent;
16+
let fixture: ComponentFixture<FormAlgorithmComponent>;
817

918
beforeEach(
1019
waitForAsync(() => {
1120
TestBed.configureTestingModule({
12-
declarations: [AlgorithmComponent],
21+
imports: [
22+
CommonModule,
23+
BrowserAnimationsModule,
24+
MatFormFieldModule,
25+
MatInputModule,
26+
MatSelectModule,
27+
MatRadioModule,
28+
FormModule,
29+
FormAlgorithmModule,
30+
],
31+
declarations: [FormAlgorithmComponent],
1332
}).compileComponents();
1433
}),
1534
);
1635

1736
beforeEach(() => {
18-
fixture = TestBed.createComponent(AlgorithmComponent);
37+
fixture = TestBed.createComponent(FormAlgorithmComponent);
1938
component = fixture.componentInstance;
39+
component.algorithmForm = new FormGroup({
40+
algorithmSettings: new FormArray([]),
41+
algorithm: new FormControl('tpe'),
42+
type: new FormControl(),
43+
});
2044
fixture.detectChanges();
2145
});
2246

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/algorithm/setting/setting.component.spec.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
11
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2+
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
23

3-
import { SettingComponent } from './setting.component';
4+
import { FormAlgorithmSettingComponent } from './setting.component';
5+
import { CommonModule } from '@angular/common';
6+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
7+
import { MatFormFieldModule } from '@angular/material/form-field';
8+
import { MatInputModule } from '@angular/material/input';
9+
import { MatSelectModule } from '@angular/material/select';
410

5-
describe('SettingComponent', () => {
6-
let component: SettingComponent;
7-
let fixture: ComponentFixture<SettingComponent>;
11+
describe('FormAlgorithmSettingComponent', () => {
12+
let component: FormAlgorithmSettingComponent;
13+
let fixture: ComponentFixture<FormAlgorithmSettingComponent>;
814

915
beforeEach(
1016
waitForAsync(() => {
1117
TestBed.configureTestingModule({
12-
declarations: [SettingComponent],
18+
imports: [
19+
CommonModule,
20+
BrowserAnimationsModule,
21+
MatFormFieldModule,
22+
MatInputModule,
23+
MatSelectModule,
24+
ReactiveFormsModule,
25+
],
26+
declarations: [FormAlgorithmSettingComponent],
1327
}).compileComponents();
1428
}),
1529
);
1630

1731
beforeEach(() => {
18-
fixture = TestBed.createComponent(SettingComponent);
32+
fixture = TestBed.createComponent(FormAlgorithmSettingComponent);
1933
component = fixture.componentInstance;
34+
component.setting = new FormGroup({
35+
value: new FormControl(),
36+
name: new FormControl(),
37+
type: new FormControl(),
38+
values: new FormControl([]),
39+
});
2040
fixture.detectChanges();
2141
});
2242

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/early-stopping/early-stopping.component.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
import { CommonModule } from '@angular/common';
12
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3+
import { FormControl, FormGroup } from '@angular/forms';
4+
import { MatFormFieldModule } from '@angular/material/form-field';
5+
import { MatInputModule } from '@angular/material/input';
6+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
7+
import { FormModule } from 'kubeflow';
28

39
import { EarlyStoppingComponent } from './early-stopping.component';
410

@@ -9,6 +15,13 @@ describe('EarlyStoppingComponent', () => {
915
beforeEach(
1016
waitForAsync(() => {
1117
TestBed.configureTestingModule({
18+
imports: [
19+
CommonModule,
20+
BrowserAnimationsModule,
21+
MatFormFieldModule,
22+
MatInputModule,
23+
FormModule,
24+
],
1225
declarations: [EarlyStoppingComponent],
1326
}).compileComponents();
1427
}),
@@ -17,6 +30,9 @@ describe('EarlyStoppingComponent', () => {
1730
beforeEach(() => {
1831
fixture = TestBed.createComponent(EarlyStoppingComponent);
1932
component = fixture.componentInstance;
33+
component.formGroup = new FormGroup({
34+
algorithmName: new FormControl(),
35+
});
2036
fixture.detectChanges();
2137
});
2238

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/experiment-creation.component.spec.ts

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,109 @@
11
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2+
import { MatDialog } from '@angular/material/dialog';
3+
import { Router } from '@angular/router';
4+
import { KWABackendService } from 'src/app/services/backend.service';
5+
import { ExperimentFormService } from 'src/app/services/experiment-form.service';
6+
import {
7+
NamespaceService,
8+
SnackBarService,
9+
TitleActionsToolbarModule,
10+
FormModule,
11+
} from 'kubeflow';
212

313
import { ExperimentCreationComponent } from './experiment-creation.component';
14+
import { FormArray, FormControl, FormGroup } from '@angular/forms';
15+
import { CommonModule } from '@angular/common';
16+
import { MatIconModule } from '@angular/material/icon';
17+
import { MatStepperModule } from '@angular/material/stepper';
18+
import { FormMetadataModule } from './metadata/metadata.module';
19+
import { FormTrialThresholdsModule } from './trial-thresholds/trial-thresholds.module';
20+
import { FormObjectiveModule } from './objective/objective.module';
21+
import { FormAlgorithmModule } from './algorithm/algorithm.module';
22+
import { FormHyperParametersModule } from './hyper-parameters/hyper-parameters.module';
23+
import { FormNasGraphModule } from './nas-graph/nas-graph.module';
24+
import { FormNasOperationsModule } from './nas-operations/nas-operations.module';
25+
import { FormMetricsCollectorModule } from './metrics-collector/metrics-collector.module';
26+
import { FormTrialTemplateModule } from './trial-template/trial-template.module';
27+
import { YamlModalModule } from './yaml-modal/yaml-modal.module';
28+
import { FormEarlyStoppingModule } from './early-stopping/early-stopping.module';
29+
import { of } from 'rxjs';
30+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
31+
32+
let ExperimentFormServiceStub: Partial<ExperimentFormService>;
33+
let KWABackendServiceStub: Partial<KWABackendService>;
34+
let NamespaceServiceStub: Partial<NamespaceService>;
35+
36+
ExperimentFormServiceStub = {
37+
createMetadataForm: () =>
38+
new FormGroup({
39+
name: new FormControl(),
40+
namespace: new FormControl(),
41+
}),
42+
createTrialThresholdForm: () =>
43+
new FormGroup({
44+
parallelTrialCount: new FormControl(),
45+
maxTrialCount: new FormControl(),
46+
maxFailedTrialCount: new FormControl(),
47+
resumePolicy: new FormControl(),
48+
}),
49+
createObjectiveForm: () =>
50+
new FormGroup({
51+
strategiesArray: new FormArray([]),
52+
type: new FormControl(),
53+
metricName: new FormControl(),
54+
goal: new FormControl(),
55+
setStrategies: new FormControl(),
56+
additionalMetricNames: new FormControl([]),
57+
metricStrategy: new FormControl('test'),
58+
metricStrategies: new FormArray([]),
59+
}),
60+
createAlgorithmObjectiveForm: () =>
61+
new FormGroup({
62+
type: new FormControl(),
63+
algorithmSettings: new FormArray([]),
64+
algorithm: new FormControl('tpe'),
65+
}),
66+
createEarlyStoppingForm: () => new FormGroup({}),
67+
createHyperParametersForm: () => new FormArray([]),
68+
createNasGraphForm: () =>
69+
new FormGroup({
70+
layers: new FormControl(),
71+
inputSizes: new FormControl([]),
72+
outputSizes: new FormControl([]),
73+
}),
74+
createNasOperationsForm: () => new FormArray([]),
75+
createMetricsForm: () =>
76+
new FormGroup({
77+
kind: new FormControl(),
78+
metricsFile: new FormControl(),
79+
tfDir: new FormControl(),
80+
port: new FormControl(),
81+
path: new FormControl(),
82+
scheme: new FormControl(),
83+
host: new FormControl(),
84+
}),
85+
createTrialTemplateForm: () =>
86+
new FormGroup({
87+
trialParameters: new FormArray([]),
88+
podLabels: new FormControl(),
89+
containerName: new FormControl(),
90+
successCond: new FormControl(),
91+
failureCond: new FormControl(),
92+
retain: new FormControl(),
93+
type: new FormControl(),
94+
cmNamespace: new FormControl(),
95+
cmName: new FormControl(),
96+
cmTrialPath: new FormControl(),
97+
}),
98+
};
99+
100+
KWABackendServiceStub = {
101+
getTrialTemplates: () => of({ Data: [] }),
102+
};
103+
104+
NamespaceServiceStub = {
105+
getSelectedNamespace: () => of(),
106+
};
4107

5108
describe('ExperimentCreationComponent', () => {
6109
let component: ExperimentCreationComponent;
@@ -9,7 +112,37 @@ describe('ExperimentCreationComponent', () => {
9112
beforeEach(
10113
waitForAsync(() => {
11114
TestBed.configureTestingModule({
115+
imports: [
116+
CommonModule,
117+
BrowserAnimationsModule,
118+
MatIconModule,
119+
MatStepperModule,
120+
FormModule,
121+
TitleActionsToolbarModule,
122+
FormMetadataModule,
123+
FormTrialThresholdsModule,
124+
FormObjectiveModule,
125+
FormAlgorithmModule,
126+
FormEarlyStoppingModule,
127+
FormHyperParametersModule,
128+
FormNasGraphModule,
129+
FormNasOperationsModule,
130+
FormMetricsCollectorModule,
131+
FormTrialTemplateModule,
132+
YamlModalModule,
133+
],
12134
declarations: [ExperimentCreationComponent],
135+
providers: [
136+
{
137+
provide: ExperimentFormService,
138+
useValue: ExperimentFormServiceStub,
139+
},
140+
{ provide: Router, useValue: {} },
141+
{ provide: MatDialog, useValue: {} },
142+
{ provide: KWABackendService, useValue: KWABackendServiceStub },
143+
{ provide: NamespaceService, useValue: NamespaceServiceStub },
144+
{ provide: SnackBarService, useValue: {} },
145+
],
13146
}).compileComponents();
14147
}),
15148
);

0 commit comments

Comments
 (0)