Example #1
0
  public tabCreated(tab: ITab) {
    this.tabDictionary.setValue(tab.key, tab);
    this.tabAdded.next(tab);

    if (!this.active || tab.instantOpen) {
      this.tabActivated.next(tab);
    }
  }
    private async _updateUserProgramInCache(program: UserFacingProgram, resp: any): Promise<boolean> {
        if (resp.result === 'updated' || resp.result === 'created') {
            const cache = await this._cache.asObservable().take(1).toPromise();
            const val = cache.find(p => p.guid === program.guid);

            if (val) {
                val.user = program;
                this._cache.next(cache);
            } else {
                this._cache.next([{guid: program.guid, application: [], user: program},  ...cache]);
            }
            return true;
        }
        return false;
    }
Example #3
0
 public remove(key: string): void {
   this.tabDictionary.remove(key);
   this.tabRemoved.next(key);
   if (this.active == key) {
     this.activate(this.tabDictionary.keys[0]);
   }
 }
            .do( ([data, cache]) => {
                let index = cache.findIndex(this._findProgram(data.guid));

                if (index >= 0)
                    cache[index] = data;

                this._cache.next(cache);
            })
Example #5
0
    public refreshProjection() {
        if (this.mCanvas.width == this.mOldWidth && this.mCanvas.height == this.mOldHeight)
            return;
        this.createProjection(this.mCanvas.width, this.mCanvas.height);
        this.mOldWidth = this.mCanvas.width;
        this.mOldHeight = this.mCanvas.height;
        this.mViewBoundsVersion++;
        this.mSizeChanged$.next({ width: this.mOldWidth, height: this.mOldHeight });

    }
  it('Should notify errorneous execution', async () => {
    const error = new Error('');
    const observable = new ReplaySubject<Error | undefined>();
    observable.next(error);

    const notificationService = NotificationService.getInstance();
    await notificationService.reportExecutionError('mock command', observable);

    assert.calledOnce(mShow);
    assert.notCalled(mShowInformation);
    assert.notCalled(mShowWarningMessage);
    assert.calledWith(mShowErrorMessage, 'mock command failed to run');
  });
  it('Should notify unsuccessful execution', async () => {
    const ABNORMAL_EXIT = -1;
    const observable = new ReplaySubject<number | undefined>();
    observable.next(ABNORMAL_EXIT);

    const notificationService = NotificationService.getInstance();
    await notificationService.reportExecutionStatus('mock command', observable);

    assert.calledOnce(mShow);
    assert.notCalled(mShowInformation);
    assert.notCalled(mShowWarningMessage);
    assert.calledWith(mShowErrorMessage, 'mock command failed to run');
  });
  it('Should notify successful execution', async () => {
    const observable = new ReplaySubject<number | undefined>();
    observable.next(0);

    const notificationService = NotificationService.getInstance();
    await notificationService.reportExecutionStatus('mock command', observable);

    assert.notCalled(mShow);
    assert.calledWith(
      mShowInformation,
      'mock command successfully ran',
      SHOW_BUTTON_TEXT
    );
    assert.notCalled(mShowWarningMessage);
    assert.notCalled(mShowErrorMessage);
  });
  it('Should notify cancellation', async () => {
    const observable = new ReplaySubject<number | undefined>();
    observable.next(undefined);
    const cancellationTokenSource = new CancellationTokenSource();
    cancellationTokenSource.cancel();

    const notificationService = NotificationService.getInstance();
    await notificationService.reportExecutionStatus(
      'mock command',
      observable,
      cancellationTokenSource.token
    );

    assert.calledOnce(mShow);
    assert.notCalled(mShowInformation);
    assert.calledWith(mShowWarningMessage, 'mock command was canceled');
    assert.notCalled(mShowErrorMessage);
  });
  it('Should notify successful and show channel as requested', async () => {
    // For this particular test, we need it to return a different value
    mShowInformation.restore();
    mShowInformation = stub(window, 'showInformationMessage').returns(
      Promise.resolve(SHOW_BUTTON_TEXT)
    );
    const observable = new ReplaySubject<number | undefined>();
    observable.next(0);

    const notificationService = NotificationService.getInstance();
    await notificationService.reportExecutionStatus('mock command', observable);

    assert.calledOnce(mShow);
    assert.calledWith(
      mShowInformation,
      'mock command successfully ran',
      SHOW_BUTTON_TEXT
    );
    assert.notCalled(mShowWarningMessage);
    assert.notCalled(mShowErrorMessage);
  });