forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibm-mobilefirst-tests.ts
169 lines (158 loc) · 5.58 KB
/
ibm-mobilefirst-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="ibm-mobilefirst.d.ts" />
// Tests
// Test WL.Client
WL.Client.connect({
onSuccess: function (response: WL.ResponseBase) {
var title: string = response.responseJSON["title"];
console.log(response.status + ' ' + title);
},
onFailure: function (response: WL.FailureResponse) {
},
timeout: 30
});
WL.Client.invokeProcedure({ adapter: "", procedure: ""}).then(function(response) {
response.responseJSON;
}, function(response) {
response.status;
});
// Test WL.Device
WL.Device.getNetworkInfo(function(networkInfo) {
var addrs = networkInfo.Ipv4Addresses;
addrs[0].wifiAddress;
})
// Test user delete certificate
WL.UserAuth.deleteCertificate("entity").then(function() {
console.log('WL.UserAuth.deleteCertificate success');
}, function(error: string) {
console.log('WL.UserAuth.deleteCertificate failure ' + error);
});
// Test Auhorization Manager
var xhr = new XMLHttpRequest();
WLAuthorizationManager.addCachedAuthorizationHeader(xhr).always(
function(response: WLAuthorizationManager.RequestObject) {
// success or failure flow
}
);
WLAuthorizationManager.getAppIdentity().then(function(data) {
// success flow with application identity
}, function(error: string) {
// failure flow with error
});
WLAuthorizationManager.getCachedAuthorizationHeader().then(function(response) {
// success flow
}, function(error) {
// error flow
});
WLAuthorizationManager.getDeviceIdentity().then(function(data) {
// success flow with device identity
}, function(error) {
// failure flow with error
});
// Test WL.JSONStore
var arr: any[];
arr = WL.JSONStore.QueryPart().between('gpa', [3.0, 4.0]);
//arr = [{$between: [{ gpa : [3.0, 4.0] }]}]
arr = WL.JSONStore.QueryPart().equal('age', 35);
//arr = [{$equal: [{ age : 35 }]}]
arr = WL.JSONStore.QueryPart().greaterOrEqualThan('age', 40);
//arr = [{$greaterOrEqualThan: [{ age : 40 }]}]
arr = WL.JSONStore.QueryPart().greaterThan('age', 40);
//arr = [{$greaterThan: [{ age : 40 }]}]
arr = WL.JSONStore.QueryPart().inside('gpa', [3.0, 4.0]);
//arr = [{$inside: [{ gpa : [3.0, 4.0] }]}]
arr = WL.JSONStore.QueryPart().leftLike('name', 'ca');
//arr = [{$leftLike: [{ name : 'ca' }]}]
arr = WL.JSONStore.QueryPart().lessOrEqualThan('age', 40);
//arr = [{$lessOrEqualThan: [{ age : 40 }]}]
arr = WL.JSONStore.QueryPart().lessThan('age', 40);
//arr = [{$lessThan: [{ age : 40 }]}]
arr = WL.JSONStore.QueryPart().like('name', 'ca');
//arr = [{$like: [{ name : 'ca' }]}]
arr = WL.JSONStore.QueryPart().notBetween('gpa', [3.0, 4.0]);
//arr = [{$notBetween: [{ gpa : [3.0, 4.0] }]}]
arr = WL.JSONStore.QueryPart().notEqual('name', 'ca');
//arr = [{$notEqual: [{ name : 'ca' }]}]
// Test WL.Logger
WL.Logger.config();
var logger = WL.Logger.create({pkg: 'myapp'});
logger.debug('Hello world');
logger.error('Hello world');
logger.fatal('Hello world');
logger.info('Hello world');
logger.trace('Hello world');
logger.warn('Hello world');
WL.Logger.ctx({pkg: 'hello'}).debug('Hello world'); //Package name context passed
WL.Logger.debug('Hello world');
WL.Logger.error('Hello world');
WL.Logger.fatal('Hello world');
WL.Logger.info('Hello world');
WL.Logger.log('Hello world');
WL.Logger.trace('Hello world');
WL.Logger.warn('Hello world');
WL.Logger.metadata( { hi : 'world' } ).info('hello');
WL.Logger.setNativeOptions({
maxFileSize : 100000,
level : 'debug',
capture : true,
filters : { jsonstore : 'debug' }
});
WL.Logger.status().then(function (state) {
//{ enabled : true, stringify: true, filters : {},
// level : 'info', pkg : '', tag: {level: false, pkg: true} }
}).fail(function (errMsg) {
//errMsg = error message
});
// Test WL.SecurityUtils
WL.SecurityUtils.base64Encode('input string').then(function(result: string) {
console.log('Base64 Encoded: ' + result);
}, function() {
console.log('An error occurred');
});
// Test WL.SimpleDialog
WL.SimpleDialog.show(
'My Title', 'My Text', [{
text: 'First Button',
handler: function() {
WL.Logger.debug("First button pressed");
}
}]);
// Test WL.TabBar
// iOS
var creditTab = WL.TabBar.addItem("CREDIT", function() {
alert("the CREDIT tab was selected!");
}, "Visa", {
image:"images/credit.png",
badge: "2"
});
creditTab.setEnabled(false);
creditTab.updateBadge("3");
creditTab.updateBadge(null);
// Android
var tabFeeds = WL.TabBar.addItem ('tab2', function() {
console.log('handler');
}, 'Engadget Feeds', {
image: 'images/feed.png',
imageSelected: 'images/feed.png'
});
tabFeeds.setEnabled(true);
// Test WLResourceRequest
var request1 = new WLResourceRequest('/adapters/sampleAdapter/multiplyNumbers', WLResourceRequest.GET);
request1.setQueryParameter('params', [5, 6]);
request1.send().then(function(response: WL.Response) {
console.log('Success ' + response.responseJSON);
}, function(error: WL.ResponseBase) {
console.log('Error ' + error.errorCode + ' ' + error.errorMsg);
});
var request2 = new WLResourceRequest('url', WLResourceRequest.POST, 30000);
request2.send('content').then(function(response: WL.Response) {
console.log('Success ' + response.responseJSON);
}, function(error: WL.ResponseBase) {
console.log('Error ' + error.errorCode + ' ' + error.errorMsg);
});
var request3 = new WLResourceRequest('url', 'METHOD', 50000);
request3.send({ data: 'content', more_data: 'more_content' }).then(function(response: WL.Response) {
console.log('Success ' + response.responseJSON);
}, function(error: WL.ResponseBase) {
console.log('Error ' + error.errorCode + ' ' + error.errorMsg);
});