Skip to content

Commit

Permalink
refactor(eslint): use cordova-eslint /w fix (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 authored Jul 2, 2020
1 parent 4b71984 commit 57df018
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 108 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'
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"repository": "github:apache/cordova-plugin-screen-orientation",
"bugs": "https://github.com/apache/cordova-plugin-screen-orientation/issues",
"scripts": {
"test": "npm run jshint",
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src"
"test": "npm run lint",
"lint": "eslint ."
},
"cordova": {
"id": "cordova-plugin-screen-orientation",
Expand All @@ -31,7 +31,7 @@
"author": "Apache Software Foundation",
"license": "Apache-2.0",
"devDependencies": {
"jshint": "^2.9.4"
"@cordova/eslint-config": "^3.0.0"
},
"engines": {
"cordovaDependencies": {
Expand Down
28 changes: 16 additions & 12 deletions src/windows/CDVOrientationProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* specific language governing permissions and limitations
* under the License.
*
*/
*/

/* global Windows, WinJS */

var DisplayInfo = Windows.Graphics.Display.DisplayInformation;
var Orientations = Windows.Graphics.Display.DisplayOrientations;
Expand All @@ -28,35 +30,37 @@ if (!window.Promise) {

module.exports = {
screenOrientation: function (win, fail, args) {
//console.log("screenOrientation proxy called with " + args);
// console.log("screenOrientation proxy called with " + args);

try {
var prefOrients = args[0];
var winPrefs = 0;

if (prefOrients & 1) { // UIInterfaceOrientationPortrait
winPrefs = winPrefs | Orientations.portrait;
if (prefOrients & 1) {
// UIInterfaceOrientationPortrait
winPrefs = winPrefs | Orientations.portrait;
}
if (prefOrients & 2) { // UIInterfaceOrientationPortraitUpsideDown
if (prefOrients & 2) {
// UIInterfaceOrientationPortraitUpsideDown
winPrefs = winPrefs | Orientations.portraitFlipped;
}
if(prefOrients & 4) { // UIInterfaceOrientationLandscapeLeft
if (prefOrients & 4) {
// UIInterfaceOrientationLandscapeLeft
winPrefs = winPrefs | Orientations.landscape;
}
if (prefOrients & 8) { // UIInterfaceOrientationLandscapeRight
if (prefOrients & 8) {
// UIInterfaceOrientationLandscapeRight
winPrefs = winPrefs | Orientations.landscapeFlipped;
}
setTimeout(function () {
DisplayInfo.autoRotationPreferences = winPrefs;
win();
}, 0);
}
catch (err) {
console.log("error :: " + err);
} catch (err) {
console.log('error :: ' + err);
fail();
}

}
};

require("cordova/exec/proxy").add("CDVOrientation", module.exports);
require('cordova/exec/proxy').add('CDVOrientation', module.exports);
70 changes: 30 additions & 40 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,44 @@
* under the License.
*
*/
/* jshint jasmine: true */
exports.defineAutoTests = function() {

describe('window.screen', function() {

it('should be defined', function() {
exports.defineAutoTests = function () {
describe('window.screen', function () {
it('should be defined', function () {
expect(window.screen).toBeDefined();
});
});

describe('window.screen.orientation', function() {

it('should be defined', function() {
describe('window.screen.orientation', function () {
it('should be defined', function () {
expect(window.screen.orientation).toBeDefined();
});

it('should have a `lock` function', function() {
it('should have a `lock` function', function () {
expect(window.screen.orientation.lock).toBeDefined();
expect(typeof window.screen.orientation.lock).toBe('function');
});

it('should have an `unlock` function', function() {
it('should have an `unlock` function', function () {
expect(window.screen.orientation.unlock).toBeDefined();
expect(typeof window.screen.orientation.unlock).toBe('function');
});

it('should have a `type` property (string)', function() {
it('should have a `type` property (string)', function () {
expect(window.screen.orientation.type).toBeDefined();
expect(typeof window.screen.orientation.type).toBe('string');
});

it('should have an `angle` property (number)', function() {
it('should have an `angle` property (number)', function () {
expect(window.screen.orientation.angle).toBeDefined();
expect(typeof window.screen.orientation.angle).toBe('number');
});

it('should have an `onchange` settable function', function() {
it('should have an `onchange` settable function', function () {
// it should be null to start
expect(window.screen.orientation.onchange).toBe(null);
// then we set it
var funk = function(){};
var funk = function () {};
window.screen.orientation.onchange = funk;
// now it should exist
expect(window.screen.orientation.onchange).toBeDefined();
Expand All @@ -69,78 +66,71 @@ exports.defineAutoTests = function() {
expect(window.screen.orientation.onchange).toBe(null);
});

it('should have an eventListener interface',function() {
it('should have an eventListener interface', function () {
expect(window.screen.orientation.addEventListener).toBeDefined();
expect(typeof window.screen.orientation.addEventListener).toBe('function');

expect(window.screen.orientation.removeEventListener).toBeDefined();
expect(typeof window.screen.orientation.removeEventListener).toBe('function');


});
});

describe('OrientationType', function() {

it("should be defined", function() {
describe('OrientationType', function () {
it('should be defined', function () {
expect(window.OrientationType).toBeDefined();
});

it("should have defined types", function() {
it('should have defined types', function () {
expect(window.OrientationType['portrait-primary']).toBeDefined();
expect(window.OrientationType['portrait-secondary']).toBeDefined();
expect(window.OrientationType['landscape-primary']).toBeDefined();
expect(window.OrientationType['landscape-secondary']).toBeDefined();
});
});

describe('OrientationLockType', function() {

it("should be defined", function() {
describe('OrientationLockType', function () {
it('should be defined', function () {
expect(window.OrientationLockType).toBeDefined();
});

it("should have defined types", function() {
it('should have defined types', function () {
expect(window.OrientationLockType['portrait-primary']).toBeDefined();
expect(window.OrientationLockType['portrait-secondary']).toBeDefined();
expect(window.OrientationLockType['landscape-primary']).toBeDefined();
expect(window.OrientationLockType['landscape-secondary']).toBeDefined();
expect(window.OrientationLockType['portrait']).toBeDefined();
expect(window.OrientationLockType['landscape']).toBeDefined();
expect(window.OrientationLockType['any']).toBeDefined();
expect(window.OrientationLockType.portrait).toBeDefined();
expect(window.OrientationLockType.landscape).toBeDefined();
expect(window.OrientationLockType.any).toBeDefined();
});
});


// TODO:
// test addEventListener('change') works
// test onchange works
describe('window.screen.orientation', function() {

it('should successfully lock and unlock screen orientation', function() {
return window.screen.orientation.lock('portrait').then(function() {
describe('window.screen.orientation', function () {
it('should successfully lock and unlock screen orientation', function () {
return window.screen.orientation.lock('portrait').then(function () {
expect(window.screen.orientation.type).toMatch(/^portrait-/);
expect(window.screen.orientation.unlock).not.toThrow();
});
});
});
};
exports.defineManualTests = function(contentEl, createActionButton) {

createActionButton('Listen to orientationchange events', function() {
window.addEventListener("orientationchange", function(){
exports.defineManualTests = function (contentEl, createActionButton) {
createActionButton('Listen to orientationchange events', function () {
window.addEventListener('orientationchange', function () {
contentEl.innerHTML += '<p>Orientation changed! ' + screen.orientation.type + '</p>';
});
});
createActionButton('Unlock orientation', function() {
createActionButton('Unlock orientation', function () {
screen.orientation.unlock();
contentEl.innerHTML += '<p>Orientation unlocked.</p>';
});
createActionButton('Lock to portrait', function() {
createActionButton('Lock to portrait', function () {
screen.orientation.lock('portrait');
contentEl.innerHTML += '<p>Orientation locked to portrait.</p>';
});
createActionButton('Lock to landscape', function() {
createActionButton('Lock to landscape', function () {
screen.orientation.lock('landscape');
contentEl.innerHTML += '<p>Orientation locked to landscape.</p>';
});
Expand Down
Loading

0 comments on commit 57df018

Please sign in to comment.