Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 5b0ea14

Browse files
oodamienBoykoAlex
authored andcommitted
Stream Creation: deploy option conditional show
The deploy option is not available if skipper is enabled and more than one platform available Resolves #783
1 parent ae33f85 commit 5b0ea14

File tree

3 files changed

+152
-4
lines changed

3 files changed

+152
-4
lines changed

ui/src/app/streams/stream-create/create-dialog/create-dialog.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h4 class="modal-title pull-left">Create Stream</h4>
4949
</div>
5050
</div>
5151
</div>
52-
<div class="row row-stream-deploy">
52+
<div class="row row-stream-deploy" *ngIf="isDeployEnabled">
5353
<div class="col-sm-offset-4 col-sm-18">
5454
<label class="checkbox-inline">
5555
<input [disabled]="isStreamCreationInProgress()" type="checkbox" [(ngModel)]="deploy"
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { StreamCreateDialogComponent } from './create-dialog.component';
2+
import { NgBusyModule } from 'ng-busy';
3+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4+
import { ComponentFixture, TestBed } from '@angular/core/testing';
5+
import { MockStreamsService } from '../../../tests/mocks/streams';
6+
import { RouterTestingModule } from '@angular/router/testing';
7+
import { StreamsService } from '../../streams.service';
8+
import { FloModule } from 'spring-flo';
9+
import { BsModalRef, ModalModule } from 'ngx-bootstrap';
10+
import { ParserService } from '../../../shared/services/parser.service';
11+
import { BusyService } from '../../../shared/services/busy.service';
12+
import { LoggerService } from '../../../shared/services/logger.service';
13+
import { MockNotificationService } from '../../../tests/mocks/notification';
14+
import { NotificationService } from '../../../shared/services/notification.service';
15+
import { SharedAboutService } from '../../../shared/services/shared-about.service';
16+
import { MocksSharedAboutService } from '../../../tests/mocks/shared-about';
17+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
18+
import { SharedModule } from '../../../shared/shared.module';
19+
import { By } from '@angular/platform-browser';
20+
import { Observable } from 'rxjs/Observable';
21+
import { FeatureInfo } from '../../../shared/model/about/feature-info.model';
22+
import { Platform } from '../../model/platform';
23+
24+
/**
25+
* Test {@link StreamCreateDialogComponent}.
26+
*
27+
* @author Alex Boyko
28+
*/
29+
describe('StreamCreateDialogComponent', () => {
30+
let component: StreamCreateDialogComponent;
31+
let fixture: ComponentFixture<StreamCreateDialogComponent>;
32+
const streamsService = new MockStreamsService();
33+
const busyService = new BusyService();
34+
const loggerService = new LoggerService();
35+
const parserService = new ParserService();
36+
const notificationService = new MockNotificationService();
37+
const aboutService = new MocksSharedAboutService();
38+
39+
40+
beforeEach(async () => {
41+
TestBed.configureTestingModule({
42+
declarations: [
43+
StreamCreateDialogComponent
44+
],
45+
imports: [
46+
RouterTestingModule.withRoutes([]),
47+
SharedModule,
48+
FormsModule,
49+
ReactiveFormsModule,
50+
ModalModule,
51+
FloModule,
52+
NgBusyModule,
53+
NoopAnimationsModule
54+
],
55+
providers: [
56+
{ provide: StreamsService, useValue: streamsService },
57+
{ provide: BusyService, useValue: busyService },
58+
{ provide: ParserService, useValue: parserService },
59+
{ provide: LoggerService, useValue: loggerService },
60+
{ provide: NotificationService, useValue: notificationService },
61+
{ provide: SharedAboutService, useValue: aboutService },
62+
{ provide: BsModalRef, useValue: null },
63+
]
64+
})
65+
.compileComponents();
66+
});
67+
68+
beforeEach(() => {
69+
fixture = TestBed.createComponent(StreamCreateDialogComponent);
70+
component = fixture.componentInstance;
71+
});
72+
73+
it('should be created', () => {
74+
fixture.detectChanges();
75+
expect(component).toBeTruthy();
76+
});
77+
78+
it('default mocks: single deployment platform (skipper mode off, multiple platforms)', () => {
79+
fixture.detectChanges();
80+
const deployDiv = fixture.debugElement.query(By.css('.row .row-stream-deploy'));
81+
expect(deployDiv).toBeDefined();
82+
});
83+
84+
it('skipper mode and multiple platforms => deploy checkbox is hidden', () => {
85+
const featureInfo = new FeatureInfo();
86+
featureInfo.skipperEnabled = true;
87+
spyOn(aboutService, 'getFeatureInfo').and.returnValue(Observable.of(featureInfo));
88+
fixture.detectChanges();
89+
const deployDiv = fixture.debugElement.query(By.css('.row .row-stream-deploy'));
90+
expect(deployDiv).toBeFalsy();
91+
});
92+
93+
it('skipper mode on and single platform => deploy checkbox is shown', () => {
94+
const featureInfo = new FeatureInfo();
95+
featureInfo.skipperEnabled = true;
96+
spyOn(aboutService, 'getFeatureInfo').and.returnValue(Observable.of(featureInfo));
97+
spyOn(streamsService, 'platforms').and.returnValue(Observable.of([
98+
new Platform('default', 'local')
99+
]));
100+
fixture.detectChanges();
101+
const deployDiv = fixture.debugElement.query(By.css('.row .row-stream-deploy'));
102+
expect(deployDiv).toBeDefined();
103+
});
104+
105+
// it('skipper mode errors out => deploy checkbox is hidden', () => {
106+
// const featureInfo = new FeatureInfo();
107+
// featureInfo.skipperEnabled = true;
108+
// spyOn(aboutService, 'getFeatureInfo').and.returnValue(Observable.throw('Error'));
109+
// fixture.detectChanges();
110+
// const deployDiv = fixture.debugElement.query(By.css('.row .row-stream-deploy'));
111+
// expect(deployDiv).toBeFalsy();
112+
// });
113+
114+
it('platforms() call errors out => deploy checkbox is hidden', () => {
115+
spyOn(streamsService, 'platforms').and.returnValue(Observable.throw('Error'));
116+
fixture.detectChanges();
117+
const deployDiv = fixture.debugElement.query(By.css('.row .row-stream-deploy'));
118+
expect(deployDiv).toBeFalsy();
119+
});
120+
121+
});

ui/src/app/streams/stream-create/create-dialog/create-dialog.component.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import { Router } from '@angular/router';
1111
import { SharedAboutService } from '../../../shared/services/shared-about.service';
1212
import { FeatureInfo } from '../../../shared/model/about/feature-info.model';
1313
import { Observable } from 'rxjs/Observable';
14-
import { share, takeUntil } from 'rxjs/operators';
14+
import { mergeMap, share, takeUntil } from 'rxjs/operators';
1515
import { Subject } from 'rxjs/Subject';
1616
import { Modal } from '../../../shared/components/modal/modal-abstract';
1717
import { BusyService } from '../../../shared/services/busy.service';
1818
import { NotificationService } from '../../../shared/services/notification.service';
1919
import { LoggerService } from '../../../shared/services/logger.service';
20+
import { Platform } from '../../model/platform';
2021

2122
/**
2223
* Stores progress percentage.
@@ -69,6 +70,11 @@ export class StreamCreateDialogComponent extends Modal implements OnInit, OnDest
6970
*/
7071
streamDefs: Array<any> = [];
7172

73+
/**
74+
* Is deploy option enabled
75+
*/
76+
isDeployEnabled = false;
77+
7278
/**
7379
* Errors
7480
*/
@@ -94,8 +100,15 @@ export class StreamCreateDialogComponent extends Modal implements OnInit, OnDest
94100
*/
95101
confirm: EventEmitter<boolean> = new EventEmitter();
96102

103+
/**
104+
* FeatureInfo Observable
105+
*/
106+
featureInfo$: Observable<FeatureInfo>;
97107

98-
featureInfo: Observable<FeatureInfo>;
108+
/**
109+
* FeatureInfo Subscription
110+
*/
111+
featureInfoSubscription: Subscription;
99112

100113
/**
101114
* Constructor
@@ -125,7 +138,20 @@ export class StreamCreateDialogComponent extends Modal implements OnInit, OnDest
125138
*/
126139
ngOnInit() {
127140
this.form = new FormGroup({}, this.uniqueStreamNames());
128-
this.featureInfo = this.aboutService.getFeatureInfo().pipe(share());
141+
this.featureInfo$ = this.aboutService.getFeatureInfo()
142+
.pipe(mergeMap(
143+
(featureInfo: FeatureInfo) => {
144+
return featureInfo.skipperEnabled ? this.streamService.platforms() : Observable.of([]);
145+
},
146+
(featureInfo: FeatureInfo, platforms: Platform[]) => {
147+
if (platforms.length < 2) {
148+
this.isDeployEnabled = true;
149+
}
150+
return featureInfo;
151+
}))
152+
.pipe(share());
153+
154+
this.featureInfoSubscription = this.featureInfo$.subscribe();
129155
}
130156

131157
/**
@@ -145,6 +171,7 @@ export class StreamCreateDialogComponent extends Modal implements OnInit, OnDest
145171
ngOnDestroy() {
146172
this.ngUnsubscribe$.next();
147173
this.ngUnsubscribe$.complete();
174+
this.featureInfoSubscription.unsubscribe();
148175
}
149176

150177
/**

0 commit comments

Comments
 (0)