index.spec.js 2.61 KB
Newer Older
Chok's avatar
Chok 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
/* globals require */

/*!
 * Module dependencies.
 */

var cordova = require('./helper/cordova'),
    BarcodeScanner = require('../www/barcodescanner'),
    execSpy,
    execWin,
    options;

/*!
 * Specification.
 */

describe('phonegap-plugin-barcodescanner', function () {
    beforeEach(function () {
        execWin = jasmine.createSpy();
        execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);
    });

    describe('BarcodeScanner', function () {
      it("BarcodeScanner plugin should exist", function() {
          expect(BarcodeScanner).toBeDefined();
          expect(typeof BarcodeScanner == 'object').toBe(true);
      });

      it("should contain a scan function", function() {
          expect(BarcodeScanner.scan).toBeDefined();
          expect(typeof BarcodeScanner.scan == 'function').toBe(true);
      });

      it("should contain an encode function", function() {
          expect(BarcodeScanner.encode).toBeDefined();
          expect(typeof BarcodeScanner.encode == 'function').toBe(true);
      });

      it("should contain three DestinationType constants", function() {
          expect(BarcodeScanner.Encode.TEXT_TYPE).toBe("TEXT_TYPE");
          expect(BarcodeScanner.Encode.EMAIL_TYPE).toBe("EMAIL_TYPE");
          expect(BarcodeScanner.Encode.PHONE_TYPE).toBe("PHONE_TYPE");
          expect(BarcodeScanner.Encode.SMS_TYPE).toBe("SMS_TYPE");
      });
    });

    describe('BarcodeScanner instance', function () {
        describe('cordova.exec', function () {
            it('should call cordova.exec on next process tick', function (done) {
                BarcodeScanner.scan(function() {}, function() {}, {});
                setTimeout(function () {
                    expect(execSpy).toHaveBeenCalledWith(
                        jasmine.any(Function),
                        jasmine.any(Function),
                        'BarcodeScanner',
                        'scan',
                        jasmine.any(Object)
                    );
                    done();
                }, 100);
            });

            it('should call cordova.exec on next process tick', function (done) {
                BarcodeScanner.encode("", "",function() {}, function() {}, {});
                setTimeout(function () {
                    expect(execSpy).toHaveBeenCalledWith(
                        jasmine.any(Function),
                        jasmine.any(Function),
                        'BarcodeScanner',
                        'encode',
                        jasmine.any(Object)
                    );
                    done();
                }, 100);
            });
        });
    });
});