let httpTesting: HttpTestingController;
let selectDaemonSpy: jasmine.Spy;
- const daemonList = RgwHelper.getDaemonList();
+ const daemonList: Array<RgwDaemon> = RgwHelper.getDaemonList();
const retrieveDaemonList = (reqDaemonList: RgwDaemon[], daemon: RgwDaemon) => {
service
.request((params) => of(params))
expect(selectDaemonSpy).toHaveBeenCalledTimes(1);
expect(selectDaemonSpy).toHaveBeenCalledWith(noDefaultDaemonList[0]);
}));
+
+ it('should update default daemon if not exist in daemon list', fakeAsync(() => {
+ const tmpDaemonList = [...daemonList];
+ service.selectDaemon(tmpDaemonList[1]); // Select 'default' daemon.
+ tmpDaemonList.splice(1, 1); // Remove 'default' daemon.
+ tmpDaemonList[0].default = true; // Set new 'default' daemon.
+ service.list().subscribe();
+ const testReq = httpTesting.expectOne('api/rgw/daemon');
+ testReq.flush(tmpDaemonList);
+ expect(service['selectedDaemon'].getValue()).toEqual(tmpDaemonList[0]);
+ }));
});
return this.http.get<RgwDaemon[]>(this.url).pipe(
tap((daemons: RgwDaemon[]) => {
this.daemons.next(daemons);
- if (_.isEmpty(this.selectedDaemon.getValue())) {
+ const selectedDaemon = this.selectedDaemon.getValue();
+ // Set or re-select the default daemon if the current one is not
+ // in the list anymore.
+ if (_.isEmpty(selectedDaemon) || undefined === _.find(daemons, { id: selectedDaemon.id })) {
this.selectDefaultDaemon(daemons);
}
})