Skip to content

Commit 80f3a94

Browse files
committed
refactor: fix test and address review comments
1 parent 433d780 commit 80f3a94

File tree

6 files changed

+60
-91
lines changed

6 files changed

+60
-91
lines changed

projects/observability/src/public-api.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ export {
5757
export * from './pages/explorer/explorer-dashboard-builder';
5858
export * from './pages/explorer/explorer.component';
5959

60-
// Gauge
61-
export * from './shared/components/gauge/gauge.component';
62-
export * from './shared/components/gauge/gauge.module';
63-
6460
// Legend
6561
export { LegendPosition } from './shared/components/legend/legend.component';
6662

@@ -215,8 +211,7 @@ export * from './shared/dashboard/data/graphql/specifiers/entity-specification.m
215211
// Explorer service
216212
export * from './pages/explorer/explorer-service';
217213

218-
219214
// Gauge
220215
export * from './shared/components/gauge/gauge.component';
221216
export * from './shared/components/gauge/gauge.module';
222-
export * from './shared/dashboard/widgets/gauge/gauge-widget'
217+
export * from './shared/dashboard/widgets/gauge/gauge-widget';
Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { FormattingModule } from '@hypertrace/common';
1+
import { Color, FormattingModule } from '@hypertrace/common';
22
import { LoadAsyncModule, TitledContentComponent } from '@hypertrace/components';
33
import { RENDERER_API } from '@hypertrace/hyperdash-angular';
44
import { createComponentFactory } from '@ngneat/spectator/jest';
55
import { MockComponent } from 'ng-mocks';
66
import { EMPTY, of } from 'rxjs';
7-
import { DonutComponent } from '../../../components/donut/donut.component';
8-
import { LegendPosition } from '../../../components/legend/legend.component';
9-
import { DonutWidgetRendererComponent } from './gauge-widget-renderer.component';
10-
import { DonutWidgetModel } from './gauge-widget.model';
7+
import { GaugeComponent } from './../../../components/gauge/gauge.component';
8+
import { GaugeWidgetRendererComponent } from './gauge-widget-renderer.component';
9+
import { GaugeWidgetModel } from './gauge-widget.model';
1110

12-
describe('Donut widget renderer component', () => {
13-
let mockModel: Partial<DonutWidgetModel> = {};
11+
describe('Gauge widget renderer component', () => {
12+
let mockModel: Partial<GaugeWidgetModel> = {};
1413
const componentFactory = createComponentFactory({
15-
component: DonutWidgetRendererComponent,
14+
component: GaugeWidgetRendererComponent,
1615
shallow: true,
1716
imports: [FormattingModule, LoadAsyncModule],
1817
providers: [
@@ -27,53 +26,42 @@ describe('Donut widget renderer component', () => {
2726
})
2827
}
2928
],
30-
declarations: [MockComponent(DonutComponent), MockComponent(TitledContentComponent)]
29+
declarations: [MockComponent(GaugeComponent), MockComponent(TitledContentComponent)]
3130
});
32-
test('should render provided data with title and legend', () => {
31+
32+
test('should render provided data with title', () => {
3333
mockModel = {
34-
header: {
35-
title: 'Test title'
36-
},
37-
legendPosition: LegendPosition.Right,
34+
title: 'Test title',
3835
getData: jest.fn(() =>
3936
of({
40-
series: [
41-
{
42-
name: 'first',
43-
value: 3
44-
},
37+
value: 5,
38+
maxValue: 10,
39+
thresholds: [
4540
{
46-
name: 'second',
47-
value: 5
41+
start: 0,
42+
end: 6,
43+
label: 'Medium',
44+
color: Color.Brown1
4845
}
49-
],
50-
center: {
51-
title: 'total',
52-
value: 2
53-
}
46+
]
5447
})
55-
),
56-
displayLegendCounts: false
48+
)
5749
};
5850

5951
const spectator = componentFactory();
6052
expect(spectator.query(TitledContentComponent)!.title).toBe('TEST TITLE');
6153

62-
expect(spectator.query(DonutComponent)!.series).toEqual([
63-
{
64-
name: 'first',
65-
value: 3
66-
},
54+
const gaugeComponent = spectator.query(GaugeComponent);
55+
expect(gaugeComponent).toExist();
56+
expect(gaugeComponent!.value).toEqual(5);
57+
expect(gaugeComponent!.maxValue).toEqual(10);
58+
expect(gaugeComponent!.thresholds).toEqual([
6759
{
68-
name: 'second',
69-
value: 5
60+
start: 0,
61+
end: 6,
62+
label: 'Medium',
63+
color: Color.Brown1
7064
}
7165
]);
72-
expect(spectator.query(DonutComponent)!.center).toEqual({
73-
title: 'total',
74-
value: 2
75-
});
76-
expect(spectator.query(DonutComponent)!.legendPosition).toEqual(LegendPosition.Right);
77-
expect(spectator.query(DonutComponent)!.displayLegendCounts).toEqual(false);
7866
});
7967
});

projects/observability/src/shared/dashboard/widgets/gauge/gauge-widget-renderer.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
22
import { WidgetRenderer } from '@hypertrace/dashboards';
33
import { Renderer } from '@hypertrace/hyperdash';
44
import { Observable } from 'rxjs';
5-
import { GaugeWidgetModel } from './gauge-widget.model';
65
import { GaugeWidgetData } from './gauge-widget';
6+
import { GaugeWidgetModel } from './gauge-widget.model';
77

88
@Renderer({ modelClass: GaugeWidgetModel })
99
@Component({

projects/observability/src/shared/dashboard/widgets/gauge/gauge-widget.model.test.ts

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,54 @@
1-
import { DEFAULT_COLOR_PALETTE } from '@hypertrace/common';
1+
import { Color } from '@hypertrace/common';
22
import { createModelFactory } from '@hypertrace/dashboards/testing';
33
import { MODEL_PROPERTY_TYPES } from '@hypertrace/hyperdash-angular';
4-
import { DonutSeriesResults } from '@hypertrace/observability';
54
import { runFakeRxjs } from '@hypertrace/test-utils';
65
import { of } from 'rxjs';
7-
import { DonutWidgetModel } from './gauge-widget.model';
6+
import { GaugeWidgetData } from './gauge-widget';
7+
import { GaugeWidgetModel } from './gauge-widget.model';
88

9-
describe('Donut widget model', () => {
9+
describe('Gauge widget model', () => {
1010
test('uses colors from color map', () => {
1111
const modelFactory = createModelFactory();
1212

13-
const series: DonutSeriesResults = {
14-
series: [
13+
const data: GaugeWidgetData = {
14+
value: 5,
15+
maxValue: 10,
16+
thresholds: [
1517
{
16-
name: 'first',
17-
value: 10
18-
},
19-
{
20-
name: 'second',
21-
value: 20
18+
start: 0,
19+
end: 6,
20+
label: 'Medium',
21+
color: Color.Brown1
2222
}
23-
],
24-
total: 2
23+
]
2524
};
2625

27-
const spectator = modelFactory(DonutWidgetModel, {
26+
const spectator = modelFactory(GaugeWidgetModel, {
2827
api: {
29-
getData: () => of(series)
28+
getData: () => of(data)
3029
},
3130
providers: [
32-
{
33-
provide: DEFAULT_COLOR_PALETTE,
34-
useValue: {
35-
name: 'default',
36-
colors: []
37-
}
38-
},
3931
{
4032
provide: MODEL_PROPERTY_TYPES,
4133
useValue: []
4234
}
43-
]
35+
],
36+
properties: {
37+
title: 'Test Title'
38+
}
4439
});
4540

46-
spectator.model.colorPalette = ['red', 'blue'];
47-
4841
runFakeRxjs(({ expectObservable }) => {
4942
expectObservable(spectator.model.getData()).toBe('(x|)', {
5043
x: {
51-
series: [
52-
{
53-
color: 'rgb(255, 0, 0)',
54-
name: 'first',
55-
value: 10
56-
},
44+
value: 5,
45+
maxValue: 10,
46+
thresholds: [
5747
{
58-
color: 'rgb(0, 0, 255)',
59-
name: 'second',
60-
value: 20
48+
start: 0,
49+
end: 6,
50+
label: 'Medium',
51+
color: Color.Brown1
6152
}
6253
]
6354
}

projects/observability/src/shared/dashboard/widgets/gauge/gauge-widget.model.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import {
2-
Model,
3-
ModelApi,
4-
ModelProperty,
5-
STRING_PROPERTY
6-
} from '@hypertrace/hyperdash';
1+
import { Model, ModelApi, ModelProperty, STRING_PROPERTY } from '@hypertrace/hyperdash';
2+
import { ModelInject, MODEL_API } from '@hypertrace/hyperdash-angular';
73
import { Observable } from 'rxjs';
84
import { GaugeWidgetData } from './gauge-widget';
9-
import { ModelInject, MODEL_API } from '@hypertrace/hyperdash-angular';
105

116
@Model({
127
type: 'gauge-widget'

projects/observability/src/shared/dashboard/widgets/observability-dashboard-widgets.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { ObservabilityTableCellRendererModule } from '../../components/table/obs
33
import { CardListWidgetModule } from './card-list/card-list-widget.module';
44
import { CartesianWidgetModule } from './charts/cartesian-widget/cartesian-widget.module';
55
import { DonutWidgetModule } from './donut/donut-widget.module';
6+
import { GaugeWidgetModule } from './gauge/gauge-widget.module';
67
import { MetricDisplayWidgetModule } from './metric-display/metric-display-widget.module';
78
import { RadarWidgetModule } from './radar/radar-widget.module';
89
import { TopNWidgetModule } from './top-n/top-n-widget.module';
910
import { TopologyWidgetModule } from './topology/topology-widget.module';
10-
import { GaugeWidgetModule } from './gauge/gauge-widget.module';
1111

1212
@NgModule({
1313
imports: [

0 commit comments

Comments
 (0)