mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
test(platform): init platform/config tests
This commit is contained in:
@ -16,7 +16,7 @@ export class TapClick {
|
|||||||
self.lastTouch = 0;
|
self.lastTouch = 0;
|
||||||
self.lastActivated = 0;
|
self.lastActivated = 0;
|
||||||
self.disableClick = 0;
|
self.disableClick = 0;
|
||||||
self.disableClickLimit = 1500;
|
self.disableClickLimit = 1000;
|
||||||
|
|
||||||
self.tapPolyfill = (config.setting('tapPolyfill') !== false);
|
self.tapPolyfill = (config.setting('tapPolyfill') !== false);
|
||||||
|
|
||||||
|
59
ionic/config/test/config.spec.ts
Normal file
59
ionic/config/test/config.spec.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import {IonicConfig, IonicPlatform} from 'ionic/ionic';
|
||||||
|
|
||||||
|
export function run() {
|
||||||
|
|
||||||
|
it('should set setting object', () => {
|
||||||
|
let config = new IonicConfig();
|
||||||
|
config.setting({
|
||||||
|
name: 'Doc Brown',
|
||||||
|
occupation: 'Weather Man'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(config.setting('name')).toEqual('Doc Brown');
|
||||||
|
expect(config.setting('name')).toEqual('Doc Brown');
|
||||||
|
expect(config.setting('occupation')).toEqual('Weather Man');
|
||||||
|
expect(config.setting('occupation')).toEqual('Weather Man');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get null setting', () => {
|
||||||
|
let config = new IonicConfig();
|
||||||
|
|
||||||
|
expect(config.setting('name')).toEqual(null);
|
||||||
|
expect(config.setting('name')).toEqual(null);
|
||||||
|
expect(config.setting('occupation')).toEqual(null);
|
||||||
|
expect(config.setting('occupation')).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set/get single setting', () => {
|
||||||
|
let config = new IonicConfig();
|
||||||
|
config.setting('name', 'Doc Brown');
|
||||||
|
config.setting('occupation', 'Weather Man');
|
||||||
|
|
||||||
|
expect(config.setting('name')).toEqual('Doc Brown');
|
||||||
|
expect(config.setting('name')).toEqual('Doc Brown');
|
||||||
|
expect(config.setting('occupation')).toEqual('Weather Man');
|
||||||
|
expect(config.setting('occupation')).toEqual('Weather Man');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init w/ given config settings', () => {
|
||||||
|
let config = new IonicConfig({
|
||||||
|
name: 'Doc Brown',
|
||||||
|
occupation: 'Weather Man'
|
||||||
|
});
|
||||||
|
expect(config.setting('name')).toEqual('Doc Brown');
|
||||||
|
expect(config.setting('occupation')).toEqual('Weather Man');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get settings object', () => {
|
||||||
|
let config = new IonicConfig({
|
||||||
|
name: 'Doc Brown',
|
||||||
|
occupation: 'Weather Man'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(config.setting()).toEqual({
|
||||||
|
name: 'Doc Brown',
|
||||||
|
occupation: 'Weather Man'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
12
ionic/platform/.eslintrc
Normal file
12
ionic/platform/.eslintrc
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"blockBindings": true,
|
||||||
|
"arrowFunctions": true,
|
||||||
|
"classes": true,
|
||||||
|
"forOf": true,
|
||||||
|
"modules": true,
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"semi": 2
|
||||||
|
}
|
||||||
|
}
|
@ -119,7 +119,7 @@ export class IonicPlatform {
|
|||||||
if (arguments.length) {
|
if (arguments.length) {
|
||||||
this._ua = val;
|
this._ua = val;
|
||||||
}
|
}
|
||||||
return this._ua;
|
return this._ua || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
navigatorPlatform(val) {
|
navigatorPlatform(val) {
|
||||||
@ -191,7 +191,6 @@ export class IonicPlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onResize(cb) {
|
onResize(cb) {
|
||||||
// TODO: Make more good
|
|
||||||
this._onResizes.push(cb);
|
this._onResizes.push(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,17 +228,9 @@ export class IonicPlatform {
|
|||||||
* @param {TODO} queryValue TODO
|
* @param {TODO} queryValue TODO
|
||||||
* @returns {boolean} TODO
|
* @returns {boolean} TODO
|
||||||
*/
|
*/
|
||||||
testQuery(queryValue) {
|
testQuery(queryValue, queryTestValue) {
|
||||||
let val = this.query('ionicplatform');
|
let valueSplit = queryValue.toLowerCase().split(';');
|
||||||
if (val) {
|
return valueSplit.indexOf(queryTestValue) > -1;
|
||||||
let valueSplit = val.toLowerCase().split(';');
|
|
||||||
for (let i = 0; i < valueSplit.length; i++) {
|
|
||||||
if (valueSplit[i] == queryValue) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -249,7 +240,7 @@ export class IonicPlatform {
|
|||||||
*/
|
*/
|
||||||
testUserAgent(userAgentExpression) {
|
testUserAgent(userAgentExpression) {
|
||||||
let rgx = new RegExp(userAgentExpression, 'i');
|
let rgx = new RegExp(userAgentExpression, 'i');
|
||||||
return rgx.test(this._ua);
|
return rgx.test(this._ua || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -258,11 +249,13 @@ export class IonicPlatform {
|
|||||||
* @returns {Object} TODO
|
* @returns {Object} TODO
|
||||||
*/
|
*/
|
||||||
matchUserAgentVersion(userAgentExpression) {
|
matchUserAgentVersion(userAgentExpression) {
|
||||||
|
if (this._ua && userAgentExpression) {
|
||||||
let val = this._ua.match(userAgentExpression);
|
let val = this._ua.match(userAgentExpression);
|
||||||
if (val) {
|
if (val) {
|
||||||
return {
|
return {
|
||||||
major: val[1],
|
major: val[1],
|
||||||
minor: val[2]
|
minor: val[2]
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,12 +266,17 @@ export class IonicPlatform {
|
|||||||
* @param {TODO} userAgentExpression TODO
|
* @param {TODO} userAgentExpression TODO
|
||||||
* @returns {boolean} TODO
|
* @returns {boolean} TODO
|
||||||
*/
|
*/
|
||||||
isPlatform(queryValue, userAgentExpression) {
|
isPlatform(queryTestValue, userAgentExpression) {
|
||||||
if (!userAgentExpression) {
|
if (!userAgentExpression) {
|
||||||
userAgentExpression = queryValue;
|
userAgentExpression = queryTestValue;
|
||||||
}
|
}
|
||||||
return this.testQuery(queryValue) ||
|
|
||||||
this.testUserAgent(userAgentExpression);
|
let queryValue = this.query('ionicplatform');
|
||||||
|
if (queryValue) {
|
||||||
|
return this.testQuery(queryValue, queryTestValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.testUserAgent(userAgentExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -389,7 +387,7 @@ export class IonicPlatform {
|
|||||||
rootNode.depth = 0;
|
rootNode.depth = 0;
|
||||||
let childPlatform = rootNode.child();
|
let childPlatform = rootNode.child();
|
||||||
while (childPlatform) {
|
while (childPlatform) {
|
||||||
rootNode.depth++
|
rootNode.depth++;
|
||||||
childPlatform = childPlatform.child();
|
childPlatform = childPlatform.child();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,16 +457,14 @@ class PlatformNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isMatch(p) {
|
isMatch(p) {
|
||||||
if (typeof this.c.isMatched !== 'boolean') {
|
|
||||||
if (p.platformOverride && !this.isEngine) {
|
if (p.platformOverride && !this.isEngine) {
|
||||||
this.c.isMatched = (p.platformOverride === this.c.name);
|
return (p.platformOverride === this.c.name);
|
||||||
|
|
||||||
} else if (!this.c.isMatch) {
|
} else if (!this.c.isMatch) {
|
||||||
this.c.isMatched = false;
|
return false;
|
||||||
} else {
|
|
||||||
this.c.isMatched = this.c.isMatch(p);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return this.c.isMatched;
|
return this.c.isMatch(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
version(p) {
|
version(p) {
|
||||||
|
132
ionic/platform/test/platform.spec.ts
Normal file
132
ionic/platform/test/platform.spec.ts
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
import {IonicConfig, IonicPlatform} from 'ionic/ionic';
|
||||||
|
|
||||||
|
export function run() {
|
||||||
|
|
||||||
|
it('should set android via platformOverride, despite ios user agent', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
config.setting('platform', 'android');
|
||||||
|
platform.userAgent(IPAD_UA);
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('android')).toEqual(true);
|
||||||
|
expect(platform.is('ios')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set ios via platformOverride, despite android querystring', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
config.setting('platform', 'ios');
|
||||||
|
platform.url('/?ionicplatform=android');
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('android')).toEqual(false);
|
||||||
|
expect(platform.is('ios')).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set ios via platformOverride', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
config.setting('platform', 'ios');
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('android')).toEqual(false);
|
||||||
|
expect(platform.is('ios')).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set android via platformOverride', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
config.setting('platform', 'android');
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('android')).toEqual(true);
|
||||||
|
expect(platform.is('ios')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set ios via querystring', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
platform.url('/?ionicplatform=ios');
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('mobile')).toEqual(true);
|
||||||
|
expect(platform.is('android')).toEqual(false);
|
||||||
|
expect(platform.is('ios')).toEqual(true);
|
||||||
|
expect(platform.is('tablet')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set ios via querystring, even with android user agent', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
platform.url('/?ionicplatform=ios');
|
||||||
|
platform.userAgent(ANDROID_UA);
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('android')).toEqual(false);
|
||||||
|
expect(platform.is('ios')).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set android via querystring', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
platform.url('/?ionicplatform=android');
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('android')).toEqual(true);
|
||||||
|
expect(platform.is('ios')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set android via querystring, even with ios user agent', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
platform.url('/?ionicplatform=android');
|
||||||
|
platform.userAgent(IPHONE_UA);
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('android')).toEqual(true);
|
||||||
|
expect(platform.is('ios')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set android via user agent', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
platform.userAgent(ANDROID_UA);
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('mobile')).toEqual(true);
|
||||||
|
expect(platform.is('android')).toEqual(true);
|
||||||
|
expect(platform.is('ios')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set iphone via user agent', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
platform.userAgent(IPHONE_UA);
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('mobile')).toEqual(true);
|
||||||
|
expect(platform.is('android')).toEqual(false);
|
||||||
|
expect(platform.is('ios')).toEqual(true);
|
||||||
|
expect(platform.is('iphone')).toEqual(true);
|
||||||
|
expect(platform.is('tablet')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set ipad via user agent', () => {
|
||||||
|
let platform = new IonicPlatform();
|
||||||
|
let config = new IonicConfig();
|
||||||
|
platform.userAgent(IPAD_UA);
|
||||||
|
platform.load(config);
|
||||||
|
|
||||||
|
expect(platform.is('mobile')).toEqual(true);
|
||||||
|
expect(platform.is('android')).toEqual(false);
|
||||||
|
expect(platform.is('ios')).toEqual(true);
|
||||||
|
expect(platform.is('ipad')).toEqual(true);
|
||||||
|
expect(platform.is('tablet')).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const ANDROID_UA = 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.20 Mobile Safari/537.36';
|
||||||
|
const IPHONE_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4';
|
||||||
|
const IPAD_UA = 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53';
|
Reference in New Issue
Block a user