openEventsPlatformApp/plugins/cordova-plugin-device/tests/tests.js
plugins/cordova-plugin-device/tests/tests.jsRaw
1/*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20*/
21
22/* jshint jasmine: true */
23
24exports.defineAutoTests = function() {
25 describe('Device Information (window.device)', function () {
26 it("should exist", function() {
27 expect(window.device).toBeDefined();
28 });
29
30 it("should contain a platform specification that is a string", function() {
31 expect(window.device.platform).toBeDefined();
32 expect((String(window.device.platform)).length > 0).toBe(true);
33 });
34
35 it("should contain a version specification that is a string", function() {
36 expect(window.device.version).toBeDefined();
37 expect((String(window.device.version)).length > 0).toBe(true);
38 });
39
40 it("should contain a UUID specification that is a string or a number", function() {
41 expect(window.device.uuid).toBeDefined();
42 if (typeof window.device.uuid == 'string' || typeof window.device.uuid == 'object') {
43 expect((String(window.device.uuid)).length > 0).toBe(true);
44 } else {
45 expect(window.device.uuid > 0).toBe(true);
46 }
47 });
48
49 it("should contain a cordova specification that is a string", function() {
50 expect(window.device.cordova).toBeDefined();
51 expect((String(window.device.cordova)).length > 0).toBe(true);
52 });
53
54 it("should depend on the presence of cordova.version string", function() {
55 expect(window.cordova.version).toBeDefined();
56 expect((String(window.cordova.version)).length > 0).toBe(true);
57 });
58
59 it("should contain device.cordova equal to cordova.version", function() {
60 expect(window.device.cordova).toBe(window.cordova.version);
61 });
62
63 it("should contain a model specification that is a string", function() {
64 expect(window.device.model).toBeDefined();
65 expect((String(window.device.model)).length > 0).toBe(true);
66 });
67
68 it("should contain a manufacturer property that is a string", function() {
69 expect(window.device.manufacturer).toBeDefined();
70 expect((String(window.device.manufacturer)).length > 0).toBe(true);
71 });
72
73 it("should contain an isVirtual property that is a boolean", function() {
74 expect(window.device.isVirtual).toBeDefined();
75 expect(typeof window.device.isVirtual).toBe("boolean");
76 });
77
78 it("should contain a serial number specification that is a string", function() {
79 expect(window.device.serial).toBeDefined();
80 expect((String(window.device.serial)).length > 0).toBe(true);
81
82 });
83
84 });
85};
86
87exports.defineManualTests = function(contentEl, createActionButton) {
88 var logMessage = function (message, color) {
89 var log = document.getElementById('info');
90 var logLine = document.createElement('div');
91 if (color) {
92 logLine.style.color = color;
93 }
94 logLine.innerHTML = message;
95 log.appendChild(logLine);
96 };
97
98 var clearLog = function () {
99 var log = document.getElementById('info');
100 log.innerHTML = '';
101 };
102
103 var device_tests = '<h3>Press Dump Device button to get device information</h3>' +
104 '<div id="dump_device"></div>' +
105 'Expected result: Status box will get updated with device info. (i.e. platform, version, uuid, model, etc)';
106
107 contentEl.innerHTML = '<div id="info"></div>' + device_tests;
108
109 createActionButton('Dump device', function() {
110 clearLog();
111 logMessage(JSON.stringify(window.device, null, '\t'));
112 }, "dump_device");
113};