Skip to content

Commit

Permalink
refactor(eslint): use cordova-eslint /w fix
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 committed Jul 2, 2020
1 parent 35279c3 commit 265c74b
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 134 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

root: true
extends: '@cordova/eslint-config/browser'

overrides:
- files: [tests/**/*.js]
extends: '@cordova/eslint-config/node-tests'
16 changes: 0 additions & 16 deletions .jshintrc

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"cordova-windows"
],
"scripts": {
"test": "npm run jshint",
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
"test": "npm run lint",
"lint": "eslint ."
},
"engines": {
"cordovaDependencies": {
Expand All @@ -43,6 +43,6 @@
"author": "Apache Software Foundation",
"license": "Apache-2.0",
"devDependencies": {
"jshint": "^2.6.0"
"@cordova/eslint-config": "^3.0.0"
}
}
21 changes: 10 additions & 11 deletions src/browser/StatusBarProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,32 @@
*
*/

function notSupported(win,fail) {
function notSupported (win, fail) {
//
console.log('StatusBar is not supported');
setTimeout(function(){
setTimeout(function () {
if (win) {
win();
}
// note that while it is not explicitly supported, it does not fail
// this is really just here to allow developers to test their code in the browser
// and if we fail, then their app might as well. -jm
},0);
}, 0);
}

module.exports = {
isVisible: false,
styleBlackTranslucent:notSupported,
styleDefault:notSupported,
styleLightContent:notSupported,
styleBlackOpaque:notSupported,
overlaysWebView:notSupported,
styleBlackTranslucent: notSupported,
styleDefault: notSupported,
styleLightContent: notSupported,
styleBlackOpaque: notSupported,
overlaysWebView: notSupported,
styleLightContect: notSupported,
backgroundColorByName: notSupported,
backgroundColorByHexString: notSupported,
hide: notSupported,
show: notSupported,
_ready:notSupported
_ready: notSupported
};

require("cordova/exec/proxy").add("StatusBar", module.exports);

require('cordova/exec/proxy').add('StatusBar', module.exports);
32 changes: 17 additions & 15 deletions src/windows/StatusBarProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,42 @@

var _supported = null; // set to null so we can check first time

function isSupported() {
function isSupported () {
// if not checked before, run check
if (_supported === null) {
var viewMan = Windows.UI.ViewManagement;
_supported = (viewMan.StatusBar && viewMan.StatusBar.getForCurrentView);
var viewMan = Windows.UI.ViewManagement;
_supported = viewMan.StatusBar && viewMan.StatusBar.getForCurrentView;
}
return _supported;
}

function getViewStatusBar() {
function getViewStatusBar () {
if (!isSupported()) {
throw new Error("Status bar is not supported");
throw new Error('Status bar is not supported');
}
return Windows.UI.ViewManagement.StatusBar.getForCurrentView();
}

function hexToRgb(hex) {
function hexToRgb (hex) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function (m, r, g, b) {
return r + r + g + g + b + b;
});

var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
return result
? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
}
: null;
}

module.exports = {
_ready: function(win, fail) {
if(isSupported()) {
_ready: function (win, fail) {
if (isSupported()) {
var statusBar = getViewStatusBar();
win(statusBar.occludedRect.height !== 0);
}
Expand Down Expand Up @@ -90,7 +92,7 @@ module.exports = {

backgroundColorByHexString: function (win, fail, args) {
var rgb = hexToRgb(args[0]);
if(isSupported()) {
if (isSupported()) {
var statusBar = getViewStatusBar();
statusBar.backgroundColor = { a: 0, r: rgb.r, g: rgb.g, b: rgb.b };
statusBar.backgroundOpacity = 1;
Expand All @@ -111,4 +113,4 @@ module.exports = {
}
}
};
require("cordova/exec/proxy").add("StatusBar", module.exports);
require('cordova/exec/proxy').add('StatusBar', module.exports);
132 changes: 80 additions & 52 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,95 +17,95 @@
* specific language governing permissions and limitations
* under the License.
*
*/
*/

/* jshint jasmine: true */
/* global StatusBar */

exports.defineAutoTests = function () {
describe("StatusBar", function () {
it("statusbar.spec.1 should exist", function() {
describe('StatusBar', function () {
it('statusbar.spec.1 should exist', function () {
expect(window.StatusBar).toBeDefined();
});

it("statusbar.spec.2 should have show|hide methods", function() {
it('statusbar.spec.2 should have show|hide methods', function () {
expect(window.StatusBar.show).toBeDefined();
expect(typeof window.StatusBar.show).toBe("function");
expect(typeof window.StatusBar.show).toBe('function');

expect(window.StatusBar.hide).toBeDefined();
expect(typeof window.StatusBar.hide).toBe("function");
expect(typeof window.StatusBar.hide).toBe('function');
});

it("statusbar.spec.3 should have set backgroundColor methods", function() {
it('statusbar.spec.3 should have set backgroundColor methods', function () {
expect(window.StatusBar.backgroundColorByName).toBeDefined();
expect(typeof window.StatusBar.backgroundColorByName).toBe("function");
expect(typeof window.StatusBar.backgroundColorByName).toBe('function');

expect(window.StatusBar.backgroundColorByHexString).toBeDefined();
expect(typeof window.StatusBar.backgroundColorByHexString).toBe("function");
expect(typeof window.StatusBar.backgroundColorByHexString).toBe('function');
});

it("statusbar.spec.4 should have set style methods", function() {
it('statusbar.spec.4 should have set style methods', function () {
expect(window.StatusBar.styleBlackTranslucent).toBeDefined();
expect(typeof window.StatusBar.styleBlackTranslucent).toBe("function");
expect(typeof window.StatusBar.styleBlackTranslucent).toBe('function');

expect(window.StatusBar.styleDefault).toBeDefined();
expect(typeof window.StatusBar.styleDefault).toBe("function");
expect(typeof window.StatusBar.styleDefault).toBe('function');

expect(window.StatusBar.styleLightContent).toBeDefined();
expect(typeof window.StatusBar.styleLightContent).toBe("function");
expect(typeof window.StatusBar.styleLightContent).toBe('function');

expect(window.StatusBar.styleBlackOpaque).toBeDefined();
expect(typeof window.StatusBar.styleBlackOpaque).toBe("function");
expect(typeof window.StatusBar.styleBlackOpaque).toBe('function');

expect(window.StatusBar.overlaysWebView).toBeDefined();
expect(typeof window.StatusBar.overlaysWebView).toBe("function");
expect(typeof window.StatusBar.overlaysWebView).toBe('function');
});
});
};

exports.defineManualTests = function (contentEl, createActionButton) {
function log(msg) {
var el = document.getElementById("info");
function log (msg) {
var el = document.getElementById('info');
var logLine = document.createElement('div');
logLine.innerHTML = msg;
el.appendChild(logLine);
}

function doShow() {
function doShow () {
StatusBar.show();
log('StatusBar.isVisible=' + StatusBar.isVisible);
}

function doHide() {
function doHide () {
StatusBar.hide();
log('StatusBar.isVisible=' + StatusBar.isVisible);
}

function doColor1() {
function doColor1 () {
log('set color=red');
StatusBar.backgroundColorByName('red');
}

function doColor2() {
function doColor2 () {
log('set style=translucent black');
StatusBar.styleBlackTranslucent();
}

function doColor3() {
function doColor3 () {
log('set style=default');
StatusBar.styleDefault();
}

var showOverlay = true;
function doOverlay() {
function doOverlay () {
showOverlay = !showOverlay;
StatusBar.overlaysWebView(showOverlay);
log('Set overlay=' + showOverlay);
}

/******************************************************************************/

contentEl.innerHTML = '<div id="info"></div>' +
contentEl.innerHTML =
'<div id="info"></div>' +
'Also: tapping bar on iOS should emit a log.' +
'<div id="action-show"></div>' +
'Expected result: Status bar will be visible' +
Expand All @@ -121,31 +121,59 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'Expected result: If overlay false, background color for status bar will be red';

log('StatusBar.isVisible=' + StatusBar.isVisible);
window.addEventListener('statusTap', function () {
log('tap!');
}, false);

createActionButton("Show", function () {
doShow();
}, 'action-show');

createActionButton("Hide", function () {
doHide();
}, 'action-hide');

createActionButton("Style=red (background)", function () {
doColor1();
}, 'action-color1');

createActionButton("Style=translucent black", function () {
doColor2();
}, 'action-color2');

createActionButton("Style=default", function () {
doColor3();
}, 'action-color3');

createActionButton("Toggle Overlays", function () {
doOverlay();
}, 'action-overlays');
window.addEventListener(
'statusTap',
function () {
log('tap!');
},
false
);

createActionButton(
'Show',
function () {
doShow();
},
'action-show'
);

createActionButton(
'Hide',
function () {
doHide();
},
'action-hide'
);

createActionButton(
'Style=red (background)',
function () {
doColor1();
},
'action-color1'
);

createActionButton(
'Style=translucent black',
function () {
doColor2();
},
'action-color2'
);

createActionButton(
'Style=default',
function () {
doColor3();
},
'action-color3'
);

createActionButton(
'Toggle Overlays',
function () {
doOverlay();
},
'action-overlays'
);
};
Loading

0 comments on commit 265c74b

Please sign in to comment.