mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
added missing tests, fixed indentation of js file
This commit is contained in:
parent
972a082203
commit
f8207c4164
@ -2,13 +2,12 @@
|
|||||||
<widget id="com.cordova.screenorientationdemo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
|
<widget id="com.cordova.screenorientationdemo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
|
||||||
<name>ScreenOrientationDemo</name>
|
<name>ScreenOrientationDemo</name>
|
||||||
<description>
|
<description>
|
||||||
A sample Apache Cordova application that showcases the Screenorientation plugin.
|
A sample Apache Cordova application that showcases the ScreenOrientation plugin.
|
||||||
</description>
|
</description>
|
||||||
<author email="dev@cordova.apache.org" href="http://cordova.io">
|
<author email="dev@cordova.apache.org" href="http://cordova.io">
|
||||||
Apache Cordova Team
|
Apache Cordova Team
|
||||||
</author>
|
</author>
|
||||||
<content src="index.html" />
|
<content src="index.html" />
|
||||||
<plugin name="cordova-plugin-whitelist" spec="1" />
|
|
||||||
<access origin="*" />
|
<access origin="*" />
|
||||||
<allow-intent href="http://*/*" />
|
<allow-intent href="http://*/*" />
|
||||||
<allow-intent href="https://*/*" />
|
<allow-intent href="https://*/*" />
|
||||||
|
113
tests/tests.js
113
tests/tests.js
@ -22,52 +22,101 @@
|
|||||||
/* jshint jasmine: true */
|
/* jshint jasmine: true */
|
||||||
|
|
||||||
exports.defineAutoTests = function() {
|
exports.defineAutoTests = function() {
|
||||||
describe('Orientation Information (window.screen.orientation)', function () {
|
|
||||||
it('should exist', function() {
|
describe('window.screen', function() {
|
||||||
if (window.screen) {
|
|
||||||
|
it('should be defined', function() {
|
||||||
|
expect(window.screen).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('window.screen.orientation', function() {
|
||||||
|
|
||||||
|
it('should be defined', function() {
|
||||||
expect(window.screen.orientation).toBeDefined();
|
expect(window.screen.orientation).toBeDefined();
|
||||||
} else {
|
|
||||||
fail('No screen object is present');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should contain a platform specification that is a string', function() {
|
it('should have a `lock` function', function() {
|
||||||
if (window.screen && window.screen.orientation) {
|
expect(window.screen.orientation.lock).toBeDefined();
|
||||||
expect((String(window.screen.orientation.type)).length > 0).toBe(true);
|
expect(typeof window.screen.orientation.lock).toBe('function');
|
||||||
} else {
|
});
|
||||||
fail('No orientation object is present');
|
|
||||||
}
|
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() {
|
||||||
|
expect(window.screen.orientation.type).toBeDefined();
|
||||||
|
expect(typeof window.screen.orientation.type).toBe('string');
|
||||||
|
});
|
||||||
|
|
||||||
|
xit('should have an `angle` property (number)', function() {
|
||||||
|
expect(window.screen.orientation.angle).toBeDefined();
|
||||||
|
expect(typeof window.screen.orientation.angle).toBe('number');
|
||||||
|
});
|
||||||
|
|
||||||
|
xit('should have an `onchange` property (function)', function() {
|
||||||
|
expect(window.screen.orientation.onchange).toBeDefined();
|
||||||
|
expect(typeof window.screen.orientation.onchange).toBe('function');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Screen functions', function () {
|
describe('OrientationType', function() {
|
||||||
it('should successfully lock and unlock screen orientation', function (done) {
|
|
||||||
|
it("should be defined", function() {
|
||||||
|
expect(window.OrientationType).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
xit("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() {
|
||||||
|
expect(window.OrientationLockType).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// test addEventListener('change') works
|
||||||
|
// test onchange works
|
||||||
|
describe('window.screen.orientation', function() {
|
||||||
|
|
||||||
|
xit('should successfully lock and unlock screen orientation, lock should return a promise', function(done) {
|
||||||
try {
|
try {
|
||||||
window.screen.orientation.lock('landscape').then(function () {
|
var promise = window.screen.orientation.lock('landscape');
|
||||||
|
expect(promise).toBeDefined();
|
||||||
|
expect(typeof promise).toBe('promise');
|
||||||
|
|
||||||
|
promise.then(function() {
|
||||||
expect(window.screen.orientation.unlock).not.toThrow();
|
expect(window.screen.orientation.unlock).not.toThrow();
|
||||||
done();
|
done();
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
fail('Promise was rejected: ' + err);
|
expect(err).toBeDefined();
|
||||||
|
fail(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (err) {
|
||||||
fail(e);
|
fail(err);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('OrientationLockType should have one of seven values', function () {
|
|
||||||
|
|
||||||
it("should have one of seven orientation lock types", function(){
|
|
||||||
expect(window.OrientationLockType['portrait-primary']).toBe(1);
|
|
||||||
expect(window.OrientationLockType['portrait-secondary']).toBe(2);
|
|
||||||
expect(window.OrientationLockType['landscape-primary']).toBe(4);
|
|
||||||
expect(window.OrientationLockType['landscape-secondary']).toBe(8);
|
|
||||||
expect(window.OrientationLockType['portrait']).toBe(3);
|
|
||||||
expect(window.OrientationLockType['landscape']).toBe(12);
|
|
||||||
expect(window.OrientationLockType['any']).toBe(15);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -35,9 +35,9 @@
|
|||||||
'portrait-secondary': 2,
|
'portrait-secondary': 2,
|
||||||
'landscape-primary': 4,
|
'landscape-primary': 4,
|
||||||
'landscape-secondary': 8,
|
'landscape-secondary': 8,
|
||||||
'portrait': 3, // either portrait-primary or portrait-secondary.
|
'portrait': (1 & 2), // either portrait-primary or portrait-secondary.
|
||||||
'landscape': 12, // either landscape-primary or landscape-secondary.
|
'landscape': ( 4 & 8 ), // either landscape-primary or landscape-secondary.
|
||||||
'any': 15 // All orientations are supported (unlocked orientation)
|
'any': ( 1 & 2 & 4 & 8 ) // All orientations are supported (unlocked orientation)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var orientationMask = 1;
|
var orientationMask = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user