tests.js 2 KB
Newer Older
李晓兵's avatar
李晓兵 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
/* global Fingerprint */
/* eslint-disable no-alert, no-console */

exports.defineAutoTests = function() {
  describe("Fingerprint Object", function () {
    it("should exist", function() {
      expect(window.Fingerprint).toBeDefined();
    });
  });

  describe("isAvailable", function () {
    it("isAvailable schould be defined", function () {
      expect(window.Fingerprint.isAvailable).toBeDefined();
    });

    it("isAvailable schould return an result or error in callback", function (done) {
      window.Fingerprint.isAvailable( function (result) {
        expect(result).toBeDefined();
        done();
      }, function(result) {
        expect(result).toBeDefined();
        done();
      });
    });
  });

  describe("show", function () {
    it("show schould be defined", function () {
      expect(window.Fingerprint.show).toBeDefined();
    });
  });
};

exports.defineManualTests = function (contentEl, createActionButton) {

  createActionButton("isAvailable", function () {
    window.Fingerprint.isAvailable(isAvailableSuccess, isAvailableError);

    function isAvailableSuccess(result) {
      console.log(result);
      alert("Fingerprint available (" + result + ")");
    }

    function isAvailableError(message) {
      alert(message);
    }
  });

  createActionButton("show", function () {
    Fingerprint.show({
      clientId: "Fingerprint-Tests",
      clientSecret: "password",
      disableBackup: false
    }, successCallback, errorCallback);

    function successCallback() {
      alert("Authentication successfull");
    }

    function errorCallback(err) {
      alert("Authentication invalid " + err);
    }
  });

  createActionButton("show-disablebackup", function () {
    Fingerprint.show({
      clientId: "Fingerprint-Tests",
      clientSecret: "password",
      disableBackup: true
    }, successCallback, errorCallback);

    function successCallback() {
      alert("Authentication successfull");
    }

    function errorCallback(err) {
      alert("Authentication invalid " + err);
    }
  });

};