arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/plugins/cordova-plugin-statusbar/tests/tests.js
plugins/cordova-plugin-statusbar/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/* global StatusBar */
 24
 25exports.defineAutoTests = function () {
 26    describe("StatusBar", function () {
 27        it("statusbar.spec.1 should exist", function() {
 28            expect(window.StatusBar).toBeDefined();
 29        });
 30
 31        it("statusbar.spec.2 should have show|hide methods", function() {
 32            expect(window.StatusBar.show).toBeDefined();
 33            expect(typeof window.StatusBar.show).toBe("function");
 34
 35            expect(window.StatusBar.hide).toBeDefined();
 36            expect(typeof window.StatusBar.hide).toBe("function");
 37        });
 38
 39        it("statusbar.spec.3 should have set backgroundColor methods", function() {
 40            expect(window.StatusBar.backgroundColorByName).toBeDefined();
 41            expect(typeof window.StatusBar.backgroundColorByName).toBe("function");
 42
 43            expect(window.StatusBar.backgroundColorByHexString).toBeDefined();
 44            expect(typeof window.StatusBar.backgroundColorByHexString).toBe("function");
 45        });
 46
 47        it("statusbar.spec.4 should have set style methods", function() {
 48            expect(window.StatusBar.styleBlackTranslucent).toBeDefined();
 49            expect(typeof window.StatusBar.styleBlackTranslucent).toBe("function");
 50
 51            expect(window.StatusBar.styleDefault).toBeDefined();
 52            expect(typeof window.StatusBar.styleDefault).toBe("function");
 53
 54            expect(window.StatusBar.styleLightContent).toBeDefined();
 55            expect(typeof window.StatusBar.styleLightContent).toBe("function");
 56
 57            expect(window.StatusBar.styleBlackOpaque).toBeDefined();
 58            expect(typeof window.StatusBar.styleBlackOpaque).toBe("function");
 59
 60            expect(window.StatusBar.overlaysWebView).toBeDefined();
 61            expect(typeof window.StatusBar.overlaysWebView).toBe("function");
 62        });
 63    });
 64};
 65
 66exports.defineManualTests = function (contentEl, createActionButton) {
 67    function log(msg) {
 68        var el = document.getElementById("info");
 69        var logLine = document.createElement('div');
 70        logLine.innerHTML = msg;
 71        el.appendChild(logLine);
 72    }
 73
 74    function doShow() {
 75        StatusBar.show();
 76        log('StatusBar.isVisible=' + StatusBar.isVisible);
 77    }
 78
 79    function doHide() {
 80        StatusBar.hide();
 81        log('StatusBar.isVisible=' + StatusBar.isVisible);
 82    }
 83
 84    function doColor1() {
 85        log('set color=red');
 86        StatusBar.backgroundColorByName('red');
 87    }
 88
 89    function doColor2() {
 90        log('set style=translucent black');
 91        StatusBar.styleBlackTranslucent();
 92    }
 93
 94    function doColor3() {
 95        log('set style=default');
 96        StatusBar.styleDefault();
 97    }
 98
 99    var showOverlay = true;
100    function doOverlay() {
101        showOverlay = !showOverlay;
102        StatusBar.overlaysWebView(showOverlay);
103        log('Set overlay=' + showOverlay);
104    }
105
106    /******************************************************************************/
107
108    contentEl.innerHTML = '<div id="info"></div>' +
109        'Also: tapping bar on iOS should emit a log.' +
110        '<div id="action-show"></div>' +
111        'Expected result: Status bar will be visible' +
112        '</p> <div id="action-hide"></div>' +
113        'Expected result: Status bar will be hidden' +
114        '</p> <div id="action-color2"></div>' +
115        'Expected result: Status bar text will be a light (white) color' +
116        '</p> <div id="action-color3"></div>' +
117        'Expected result: Status bar text will be a dark (black) color' +
118        '</p> <div id="action-overlays"></div>' +
119        'Expected result:<br>Overlay true = status bar will lay on top of web view content<br>Overlay false = status bar will be separate from web view and will not cover content' +
120        '</p> <div id="action-color1"></div>' +
121        'Expected result: If overlay false, background color for status bar will be red';
122
123    log('StatusBar.isVisible=' + StatusBar.isVisible);
124    window.addEventListener('statusTap', function () {
125        log('tap!');
126    }, false);
127
128    createActionButton("Show", function () {
129        doShow();
130    }, 'action-show');
131
132    createActionButton("Hide", function () {
133        doHide();
134    }, 'action-hide');
135
136    createActionButton("Style=red (background)", function () {
137        doColor1();
138    }, 'action-color1');
139
140    createActionButton("Style=translucent black", function () {
141        doColor2();
142    }, 'action-color2');
143
144    createActionButton("Style=default", function () {
145        doColor3();
146    }, 'action-color3');
147
148    createActionButton("Toggle Overlays", function () {
149        doOverlay();
150    }, 'action-overlays');
151};