GridtNetwork / gridt-client

Official client of the GridtNetwork.
https://gridt.org
Other
3 stars 1 forks source link

The alert.present element is not in register page AlertSpy #146

Closed marickmanrho closed 4 years ago

marickmanrho commented 4 years ago

The present method is not included in the AlertSpy object causing a late security error.

Copy of error:

HeadlessChrome 85.0.4183 (Linux 0.0.0) RegisterPage should alert the user when opening the page FAILED
    Uncaught Error: Uncaught (in promise): TypeError: Cannot read property 'present' of undefined
    TypeError: Cannot read property 'present' of undefined
        at RegisterPage.<anonymous> (http://localhost:9876/_karma_webpack_/src/app/login/register/register.page.ts:41:17)
        at step (http://localhost:9876/_karma_webpack_/node_modules/tslib/tslib.es6.js:100:1)
        at Object.next (http://localhost:9876/_karma_webpack_/node_modules/tslib/tslib.es6.js:81:45)
        at fulfilled (http://localhost:9876/_karma_webpack_/node_modules/tslib/tslib.es6.js:71:42)
        at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone.js:386:1)
        at ProxyZoneSpec.push../node_modules/zone.js/dist/zone-testing.js.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:292:1)
        at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone.js:385:1)
        at Object.onInvoke (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm5/core.js:26256:1)
        at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone.js:385:1)
        at Zone../node_modules/zone.js/dist/zone.js.Zone.run (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone.js:143:1) thrown
Drvanon commented 4 years ago

This should be a quick fix.

marickmanrho commented 4 years ago

Well, how to spy on the alert itself?

Now we have in register.page.ts

  private async showSafetyAlert() {
    const alert = await this.alertCtrl.create({
      header: "Warning",
      subHeader: "Password Safety",
      message: "This app is in Alpha and therefore we cannot guarantee the safety of your data. Please keep this in mind when picking your password. We recommend you pick a password you do not use anywhere else.",
      buttons: ["Accept"],
      backdropDismiss: false
    });

    await alert.present();
  }

and in register.page.spec.ts

let alertSpy: AlertController = jasmine.createSpyObj("alertSpy", ["create", "dismiss"]);

But how to spy on the present() method created by the create method of the alertSpy?

Drvanon commented 4 years ago

Ah I see your point. Well we control what create returns, we can make the create function return an object that has a present method.