Skip to content

Commit cbe3c4e

Browse files
committed
frontend: Create unit tests for trials table (#1441)
* Create unit tests for trials-table component. Signed-off-by: Elena Zioga <[email protected]>
1 parent c30a12c commit cbe3c4e

File tree

1 file changed

+155
-2
lines changed

1 file changed

+155
-2
lines changed

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-details/trials-table/trials-table.component.spec.ts

Lines changed: 155 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import { MatButtonModule } from '@angular/material/button';
1111
import { TrialsTableComponent } from './trials-table.component';
1212
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
1313

14+
import { SimpleChange } from '@angular/core';
15+
import { PropertyValue, StatusValue, ComponentValue } from 'kubeflow';
16+
import { parseStatus } from '../../experiments/utils';
17+
import lowerCase from 'lodash-es/lowerCase';
18+
import { KfpRunComponent } from './kfp-run/kfp-run.component';
19+
1420
describe('TrialsTableComponent', () => {
1521
let component: TrialsTableComponent;
1622
let fixture: ComponentFixture<TrialsTableComponent>;
@@ -38,10 +44,157 @@ describe('TrialsTableComponent', () => {
3844
beforeEach(() => {
3945
fixture = TestBed.createComponent(TrialsTableComponent);
4046
component = fixture.componentInstance;
47+
component.displayedColumns = [
48+
'Status',
49+
'Trial name',
50+
'Validation loss',
51+
'Lr',
52+
'Batch size',
53+
'Embed dim',
54+
'Dropout',
55+
'Sp dropout',
56+
'Kfp run',
57+
];
58+
component.data = [
59+
[
60+
'Succeeded',
61+
'open-vaccine-0f37u-6cd03cbf',
62+
'0.70573',
63+
'0.0001',
64+
'32',
65+
'20',
66+
'0.2',
67+
'0.2',
68+
'9af7c534-689a-48aa-996b-537d13989729',
69+
'0',
70+
],
71+
[
72+
'Succeeded',
73+
'open-vaccine-0f37u-8ec17b8f',
74+
'0.76401',
75+
'0.0001',
76+
'96',
77+
'20',
78+
'0.2',
79+
'0.2',
80+
'19aed8e0-143c-49d8-8bd3-7ebb464181d8',
81+
'1',
82+
],
83+
];
84+
component.ngOnChanges({
85+
displayedColumns: new SimpleChange(
86+
null,
87+
component.displayedColumns,
88+
false,
89+
),
90+
});
91+
4192
fixture.detectChanges();
4293
});
4394

44-
it('should create', () => {
45-
expect(component).toBeTruthy();
95+
it('should create processedData', () => {
96+
expect(component.processedData).toEqual([
97+
{
98+
'trial name': 'open-vaccine-0f37u-6cd03cbf',
99+
status: 'Succeeded',
100+
'validation loss': '0.70573',
101+
lr: '0.0001',
102+
'batch size': '32',
103+
'embed dim': '20',
104+
dropout: '0.2',
105+
'sp dropout': '0.2',
106+
'kfp run': '9af7c534-689a-48aa-996b-537d13989729',
107+
},
108+
{
109+
'trial name': 'open-vaccine-0f37u-8ec17b8f',
110+
status: 'Succeeded',
111+
'validation loss': '0.76401',
112+
lr: '0.0001',
113+
'batch size': '96',
114+
'embed dim': '20',
115+
dropout: '0.2',
116+
'sp dropout': '0.2',
117+
'kfp run': '19aed8e0-143c-49d8-8bd3-7ebb464181d8',
118+
},
119+
]);
120+
});
121+
122+
it('should create config', () => {
123+
expect(component.config).toEqual({
124+
columns: [
125+
{
126+
matColumnDef: 'Status',
127+
matHeaderCellDef: 'Status',
128+
value: new StatusValue({
129+
valueFn: parseStatus,
130+
}),
131+
sort: true,
132+
},
133+
{
134+
matColumnDef: 'name',
135+
matHeaderCellDef: 'Trial name',
136+
value: new PropertyValue({
137+
field: lowerCase(component.displayedColumns[1]),
138+
isLink: true,
139+
}),
140+
sort: true,
141+
},
142+
{
143+
matColumnDef: 'Validation loss',
144+
matHeaderCellDef: 'Validation loss',
145+
value: new PropertyValue({
146+
field: lowerCase(component.displayedColumns[2]),
147+
}),
148+
sort: true,
149+
},
150+
{
151+
matColumnDef: 'Lr',
152+
matHeaderCellDef: 'Lr',
153+
value: new PropertyValue({
154+
field: lowerCase(component.displayedColumns[3]),
155+
}),
156+
sort: true,
157+
},
158+
{
159+
matColumnDef: 'Batch size',
160+
matHeaderCellDef: 'Batch size',
161+
value: new PropertyValue({
162+
field: lowerCase(component.displayedColumns[4]),
163+
}),
164+
sort: true,
165+
},
166+
{
167+
matColumnDef: 'Embed dim',
168+
matHeaderCellDef: 'Embed dim',
169+
value: new PropertyValue({
170+
field: lowerCase(component.displayedColumns[5]),
171+
}),
172+
sort: true,
173+
},
174+
{
175+
matColumnDef: 'Dropout',
176+
matHeaderCellDef: 'Dropout',
177+
value: new PropertyValue({
178+
field: lowerCase(component.displayedColumns[6]),
179+
}),
180+
sort: true,
181+
},
182+
{
183+
matColumnDef: 'Sp dropout',
184+
matHeaderCellDef: 'Sp dropout',
185+
value: new PropertyValue({
186+
field: lowerCase(component.displayedColumns[7]),
187+
}),
188+
sort: true,
189+
},
190+
{
191+
matHeaderCellDef: '',
192+
matColumnDef: 'actions',
193+
value: new ComponentValue({
194+
component: KfpRunComponent,
195+
}),
196+
},
197+
],
198+
});
46199
});
47200
});

0 commit comments

Comments
 (0)