Neues Initialrelease mit IonicMaterial

This commit is contained in:
Carsten Hilmer
2016-08-22 12:55:52 +02:00
parent 30a5df79aa
commit 45e482b14d
1249 changed files with 305225 additions and 68794 deletions

View File

@@ -0,0 +1,80 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaBarcodeScanner', function () {
var $rootScope = null;
var $cordovaBarcodeScanner = null;
beforeEach(inject(function (_$cordovaBarcodeScanner_, _$rootScope_) {
$cordovaBarcodeScanner = _$cordovaBarcodeScanner_;
$rootScope = _$rootScope_;
}));
it('should do a scan', function (done) {
var expectedText = 'Some UPC Code';
$cordovaBarcodeScanner.scannedText = expectedText;
var expectedFormat = 'TEXT_TYPE';
$cordovaBarcodeScanner.scannedFormat = expectedFormat;
$cordovaBarcodeScanner.scan()
.then(
function(result) {
expect(result.text).toBe(expectedText);
expect(result.format).toBe(expectedFormat);
},
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while scanning.', function(done) {
$cordovaBarcodeScanner.throwsError = true;
$cordovaBarcodeScanner.scan()
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should encode.', function(done) {
var expectedText = 'http://www.ecofic.com';
var expectedFormat = 'TEXT_TYPE';
$cordovaBarcodeScanner.encode(expectedFormat, expectedText)
.then(
function() {
expect($cordovaBarcodeScanner.scannedText).toBe(expectedText);
expect($cordovaBarcodeScanner.scannedFormat).toBe(expectedFormat);
},
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while encoding.', function(done) {
$cordovaBarcodeScanner.throwsError = true;
$cordovaBarcodeScanner.encode()
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
});
})

View File

@@ -0,0 +1,28 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaBrightness', function () {
var $cordovaBrightness = null;
beforeEach(inject(function (_$cordovaBrightness_) {
$cordovaBrightness = _$cordovaBrightness_;
}));
it('should get the current brightness', function () {
$cordovaBrightness.get().then(function (result) {
expect(result.value).toEqual(100);
});
});
it('should set the current brightness', function () {
$cordovaBrightness.set(50);
var currentBrightness = $cordovaBrightness.get();
$cordovaBrightness.get().then(function (result) {
expect(result.value).toEqual(50);
});
});
});
})

View File

@@ -0,0 +1,78 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaCamera', function () {
var $rootScope = null;
var $cordovaCamera = null;
var cameraOptions = {};
beforeEach(inject(function (_$cordovaCamera_, _$rootScope_) {
$cordovaCamera = _$cordovaCamera_;
$rootScope = _$rootScope_;
}));
it('should get picture', function (done) {
$cordovaCamera.getPicture(cameraOptions)
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while getting the picture.', function(done) {
$cordovaCamera.throwsError = true;
$cordovaCamera.imageData = '';
$cordovaCamera.getPicture(cameraOptions)
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should return the url of the picture.', function(done) {
var expected = 'file:///mnt/sdcard/dummy/myImage.jpeg';
$cordovaCamera.throwsError = false;
$cordovaCamera.imageData = expected;
$cordovaCamera.getPicture(cameraOptions)
.then(
function(imageData) {
expect(imageData).toEqual(expected);
},
function() {
expected(false).toBe(true);
} )
.finally(
function() {
done(); });
$rootScope.$digest();
});
it('should return an empty string as imageData.', function(done) {
var expected = '';
$cordovaCamera.throwsError = false;
$cordovaCamera.getPicture(cameraOptions)
.then(
function(imageData) {
expect(imageData).toMatch('');
},
function() {
expect(false).toBe(true);
})
.finally(function() { done(); });
$rootScope.$digest();
});
});
})

View File

@@ -0,0 +1,20 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaCapture', function () {
var $cordovaCapture = null;
var $timeout = null;
var $rootScope = null;
beforeEach(inject(function (_$timeout_, _$rootScope_, _$cordovaCapture_) {
$cordovaCapture = _$cordovaCapture_;
$timeout = _$timeout_;
$rootScope = _$rootScope_;
}));
it('should do something', function() {
});
});
})

View File

@@ -0,0 +1,180 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaContacts', function () {
var $rootScope = null;
var $cordovaContacts = null;
var findOptions = {fields:'*'};
var createContact = function(id, firstName, lastName, nickname,
phoneNumbers, emailAddresses, mailingAddresses, ims, organizations,
birthday, note, photos, categories, urls) {
var contact = {
id: id,
displayName: firstName + ' ' + lastName,
name: { givenName: firstName, familyName: lastName },
nickname: firstName,
phoneNumbers: phoneNumbers,
emails: emailAddresses,
addresses: mailingAddresses,
ims: ims,
organizations: organizations,
birthday: birthday,
note: note,
photos: photos,
categories: categories,
urls: urls
};
return contact;
};
beforeEach(inject(function (_$rootScope_, _$cordovaContacts_) {
$cordovaContacts = _$cordovaContacts_;
$rootScope = _$rootScope_;
// Add some contacts for testing purposes
var earl = createContact('1', 'Earl', 'Baleep', 'Earl',
[], [], [], [], [], '06/21/1952',
'', [], [], []);
$cordovaContacts.contacts.push(earl);
}));
it('should save a contact', function (done) {
var originalLength = $cordovaContacts.contacts.length;
var contact = createContact('1000000', 'Norman', 'Yup', 'Norman');
$cordovaContacts.save(contact)
.then(
function() {
var newLength = $cordovaContacts.contacts.length;
expect(newLength).toBe(originalLength+1);
},
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should not allow the same contact to be saved twice', function(done) {
var originalLength = $cordovaContacts.contacts.length;
// Save the contact once
var contact = createContact('1000001', 'John', 'Doe', 'John');
$cordovaContacts.save(contact)
.then(
function() {
// Ensure the contact was added
var newLength = $cordovaContacts.contacts.length;
expect(newLength).toBe(originalLength+1);
// If the contact is saved again, it should fail.
$cordovaContacts.save(contact)
.then(
function() { expect(false).toBe(true); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
},
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should remove an existng contact', function(done) {
// The unique identifier of the contact we'll remove
var contactId = '1000002';
var originalLength = $cordovaContacts.contacts.length;
// Save the contact once
var contact = createContact(contactId, 'John', 'Doe', 'John');
$cordovaContacts.save(contact)
.then(
function() {
// Ensure the contact was added
var newLength = $cordovaContacts.contacts.length;
expect(newLength).toBe(originalLength+1);
// Attempt to remove the contact
$cordovaContacts.remove(contact)
.then(
function() {
newLength = $cordovaContacts.contacts.length;
expect(newLength).toBe(originalLength);
},
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
},
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should fail to remove a contact if it does not exist', function(done) {
// The unique identifier of the contact we'll try to remove
var contactId = '10000003';
var contact = createContact(contactId, 'John', 'Doe', 'John');
// Attempt to remove the contact
$cordovaContacts.remove(contact)
.then(
function() { expect(false).toBe(true); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should find an existing contact', function(done) {
$cordovaContacts.find(findOptions)
.then(
function() { expect(true).toBe(true); },
function(error) { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it ('should not find a specific contact', function(done) {
$cordovaContacts.find(findOptions)
.then(
function() { expect(true).toBe(true); },
function(error) { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while finding a contact.', function(done) {
$cordovaContacts.throwsError = true;
$cordovaContacts.find(findOptions)
.then(
function() { expect(false).toBe(true); },
function(error) { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
});
})

View File

@@ -0,0 +1,49 @@
describe('ngCordovaMocks', function () {
beforeEach(function () {
module('ngCordovaMocks');
});
describe('cordovaDatePicker', function () {
var $cordovaDatePicker = null,
$rootScope = null;
beforeEach(inject(function (_$cordovaDatePicker_, _$rootScope_) {
$cordovaDatePicker = _$cordovaDatePicker_;
$rootScope = _$rootScope_;
}));
it('should show a date picker', function () {
var result,
dummyDate = new Date(),
options = {
date: dummyDate,
mode: 'date'
};
$cordovaDatePicker
.show(options)
.then(function (response) {
result = response;
});
$rootScope.$digest();
expect(result).toBe(dummyDate);
});
it('should have default options if none are passed', function() {
var result;
$cordovaDatePicker
.show()
.then(function (response) {
result = response;
});
$rootScope.$digest();
expect(result instanceof Date).toBeTruthy();
});
});
})

View File

@@ -0,0 +1,69 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaDevice', function () {
var $cordovaDevice = null;
beforeEach(inject(function (_$cordovaDevice_) {
$cordovaDevice = _$cordovaDevice_;
}));
it('should get the device name', function () {
// NOTE: device.name was deprecated in Cordova 2.3.
// This test can be removed once device.name is removed.
$cordovaDevice.device = 'Power Device';
var deviceName = $cordovaDevice.getDevice();
expect(deviceName).toEqual('Power Device');
});
it('should get the version of cordova in use', function () {
var cordovaVersion = '3.5';
$cordovaDevice.cordova = cordovaVersion;
var version = $cordovaDevice.getCordova();
expect(version).toEqual(cordovaVersion);
});
it('should get the model name', function () {
var modelName = 'Buster';
$cordovaDevice.model = modelName;
var model = $cordovaDevice.getModel();
expect(model).toEqual(modelName);
});
it('should get the platform', function () {
var operatingSystem = 'MyFavoriteOS';
$cordovaDevice.platform = operatingSystem;
var platform = $cordovaDevice.getPlatform();
expect(platform).toEqual(operatingSystem);
});
it('should get the unique ID', function () {
var guid = 'eb77ae18-f6c1-4a36-8705-1975a9225fb9';
$cordovaDevice.uuid = guid;
var uuid = $cordovaDevice.getUUID();
expect(uuid).toEqual(guid);
});
it('should get the version', function () {
var version = '1.0';
$cordovaDevice.version = version;
var v = $cordovaDevice.getVersion();
expect(v).toEqual(version);
});
it('should get the manufacturer', function () {
var manufacturer = 'apple';
$cordovaDevice.manufacturer = manufacturer;
var v = $cordovaDevice.getManufacturer();
expect(v).toEqual(manufacturer);
});
});
})

View File

@@ -0,0 +1,81 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaDeviceMotion', function () {
var count = 0;
var $interval = null;
var $rootScope = null;
var $cordovaDeviceMotion = null;
var motionServiceOptions = { frequency: 1000 };
beforeEach(inject(function (_$interval_, _$rootScope_, _$cordovaDeviceMotion_) {
$cordovaDeviceMotion = _$cordovaDeviceMotion_;
$rootScope = _$rootScope_;
$interval = _$interval_;
count = 0;
}));
it('should get the current acceleration', function (done) {
var expected = { x:1, y:1, z:1, timestamp:Date() };
$cordovaDeviceMotion.currentAcceleration = expected;
$cordovaDeviceMotion.getCurrentAcceleration()
.then(
function(actual) { expect(actual).toBe(expected); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while getting the current acceleration.', function(done) {
$cordovaDeviceMotion.throwsError = true;
$cordovaDeviceMotion.getCurrentAcceleration()
.then(
function(actual) { expect(false).toBe(true); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should track five points over an interval', function() {
var watch = $cordovaDeviceMotion.watchAcceleration(motionServiceOptions);
watch.promise.then(
function() { },
function(err) { expect(false).toBe(true); },
function(result) {
count = count + 1;
}
);
$interval.flush(5000);
$rootScope.$digest();
expect(count).toBe(5);
});
it('should clear a created watch', function() {
var watch = $cordovaDeviceMotion.watchAcceleration(motionServiceOptions);
watch.promise.then(
function() { },
function(err) { expect(false).toBe(true); },
function(result) {
count = count + 1;
}
);
$interval.flush(6000);
$cordovaDeviceMotion.clearWatch(watch.watchId);
$rootScope.$digest();
expect(count).toBe(6);
});
});
})

View File

@@ -0,0 +1,99 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaDeviceOrientation', function () {
var count = 0;
var $interval = null;
var $rootScope = null;
var $cordovaDeviceOrientation = null;
var orientationServiceOptions = { frequency: 1000 };
beforeEach(inject(function (_$interval_, _$rootScope_, _$cordovaDeviceOrientation_) {
$cordovaDeviceOrientation = _$cordovaDeviceOrientation_;
$rootScope = _$rootScope_;
$interval = _$interval_;
count = 0;
}));
it('should get the current heading', function (done) {
var expected = { x:1, y:1, z:1, timestamp:Date() };
$cordovaDeviceOrientation.currentHeading = expected;
$cordovaDeviceOrientation.getCurrentHeading()
.then(
function(actual) { expect(actual).toBe(expected); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while getting the current heading.', function(done) {
$cordovaDeviceOrientation.throwsError = true;
$cordovaDeviceOrientation.getCurrentHeading()
.then(
function(actual) { expect(false).toBe(true); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should track five readings over an interval', function() {
var watch = $cordovaDeviceOrientation.watchHeading(orientationServiceOptions);
watch.then(
function() { },
function(err) { expect(false).toBe(true); },
function(result) {
count = count + 1;
}
);
$interval.flush(5000);
$rootScope.$digest();
expect(count).toBe(5);
});
it('should clear a created watch', function() {
var watch = $cordovaDeviceOrientation.watchHeading(orientationServiceOptions);
watch.then(
function() { },
function(err) { expect(false).toBe(true); },
function(result) {
count = count + 1;
}
);
$interval.flush(5000);
$cordovaDeviceOrientation.clearWatch(watch.watchID);
$rootScope.$digest();
expect(count).toBe(5);
});
it('should cancel a created watch', function() {
var watch = $cordovaDeviceOrientation.watchHeading(orientationServiceOptions);
watch.then(
function() { },
function(err) { expect(false).toBe(true); },
function(result) {
count = count + 1;
}
);
$interval.flush(5000);
watch.cancel();
$rootScope.$digest();
expect(count).toBe(5);
});
});
})

View File

@@ -0,0 +1,53 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaDialogs', function () {
var $cordovaDialogs = null;
beforeEach(inject(function (_$cordovaDialogs_) {
$cordovaDialogs = _$cordovaDialogs_;
}));
it('should alert the user', function() {
var message = 'Hello. World.';
$cordovaDialogs.useHostAbilities = false;
$cordovaDialogs.alert(message);
expect($cordovaDialogs.dialogText).toBe(message);
});
it('should ask for confirmation', function() {
var confirmation = 'Are you sure?';
$cordovaDialogs.useHostAbilities = false;
$cordovaDialogs.confirm(confirmation);
expect($cordovaDialogs.dialogText).toBe(confirmation);
});
it('should prompt the user', function() {
// Pretend that user enters '21'
var promptResponse = '21';
$cordovaDialogs.useHostAbilities = false;
$cordovaDialogs.promptResponse = promptResponse;
// Simulate the prompt
var prompt = 'Please enter your age:';
$cordovaDialogs.prompt(prompt,
function(response) {
expect(response).toBe(promptResponse);
},
'Age',
['ok', 'cancel'],
'13'
);
});
it('should beep five times', function() {
var times = 5;
$cordovaDialogs.beep(times);
expect($cordovaDialogs.beepCount).toBe(times);
})
});
})

View File

@@ -0,0 +1,170 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaFile', function () {
var $cordovaFile = null;
var $rootScope = null;
var testFileName = "test.txt";
var testData = "My data object";
var testFolder ="testfolder";
beforeEach(inject(function (_$cordovaFile_, _$rootScope_) {
$cordovaFile = _$cordovaFile_;
$rootScope = _$rootScope_;
}));
it('should successfully check directory', function(done) {
$cordovaFile.checkDir('/some/directory')
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(done);
$rootScope.$digest();
});
it('should fail checking directory', function(done) {
$cordovaFile.throwsError = true;
$cordovaFile.checkDir('/some/directory')
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(done);
;
$rootScope.$digest();
});
it('should successfully create a directory', function(done) {
$cordovaFile.createDir('/some/directory', true)
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(done);
$rootScope.$digest();
});
it('should fail creating a directory', function(done) {
$cordovaFile.throwsError = true;
$cordovaFile.createDir('/some/directory', true)
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(done);
$rootScope.$digest();
});
it('should successfully check for a file', function(done) {
$cordovaFile.checkFile('/some/directory', 'test.txt')
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(done);
$rootScope.$digest();
});
it('should fail checking directory', function(done) {
$cordovaFile.throwsError = true;
$cordovaFile.checkDir('/some/directory')
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(done);
$rootScope.$digest();
});
describe('tests with mockfFiles flag enabled',function(){
beforeEach(function(){
$cordovaFile.shouldMockFiles = true;
});
describe('file tests',function(){
beforeEach(function(){
$cordovaFile.writeFile(testFileName, testData);
$rootScope.$digest();
});
it('should resolve if file exists',function(done){
$cordovaFile.checkFile(testFileName).then(function(){
expect(true).toEqual(true);
},function(){
expect(false).toEqual(true);
}).finally(done);
$rootScope.$digest();
});
it('should reject if file do not exists',function(done){
$cordovaFile.checkFile('nonExistingFile.txt').then(function(){
expect(false).toEqual(true);
},function(){
expect(true).toEqual(true);
}).finally(done);
$rootScope.$digest();
});
it('should return file content if file exists',function(done){
$cordovaFile.readFile(testFileName).then(function(data){
expect(testData).toEqual(data);
},function(){
expect(false).toEqual(true);
}).finally(done);
$rootScope.$digest();
});
it('shold be rejected if file does not exists',function(done){
$cordovaFile.readFile('NotValidFile').then(function(data){
expect(false).toEqual(true);
},function(){
expect(true).toEqual(true);
}).finally(done);
$rootScope.$digest();
});
});
describe('directory tests',function(){
beforeEach(function(){
$cordovaFile.createDir(testFolder, true);
$rootScope.$digest();
});
it('should resolve test directory which was created in setup',function(done){
$cordovaFile.checkDir(testFolder).then(function(){
expect(true).toEqual(true);
},function(){
expect(false).toEqual(true);
}).finally(done);
$rootScope.$digest();
});
it('should not return test directory as file',function(done){
$cordovaFile.readFile(testFolder).then(function(){
expect(false).toEqual(true);
},function(){
expect(true).toEqual(true);
}).finally(done);
$rootScope.$digest();
});
});
});
});
// TODO: ping the fileSystem property to detect if
// - check whether directory exists or not.
// - overwrite works on the createDir function
});

View File

@@ -0,0 +1,48 @@
describe('Service: $cordovaFileOpener2', function(){
var $cordovaFileOpener2, $rootScope, $window;
beforeEach(function() {
module('ngCordovaMocks');
});
beforeEach(inject(function (_$cordovaFileOpener2_, _$q_, _$rootScope_, _$window_) {
$cordovaFileOpener2 = _$cordovaFileOpener2_;
$rootScope = _$rootScope_;
$window = _$window_;
}));
it('should call window\'s plugins.fileOpener2.open method of success', function(done) {
$cordovaFileOpener2.open(
'/sdcard/Download/gmail.apk',
'application/vnd.android.package-archive'
).then(
function () {
expect(true).toBe(true);
},
function() {
expect(false).toBe(true);
}
).finally(done);
$rootScope.$digest();
});
it('should call window\'s plugins.fileOpener2.open method of failure', function(done) {
$cordovaFileOpener2.throwsError = true;
$cordovaFileOpener2.open(
'/sdcard/Download/gmail.apk',
'application/vnd.android.package-archive'
).then(
function () {
expect(true).toBe(true);
},
function() {
expect(false).toBe(true);
}
).finally(done);
$rootScope.$digest();
});
});

View File

@@ -0,0 +1,107 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaGeolocation', function () {
var count = 0;
var $interval = null;
var $rootScope = null;
var $cordovaGeolocation = null;
var gpsOptions = {};
beforeEach(inject(function (_$cordovaGeolocation_, _$rootScope_, _$interval_) {
$cordovaGeolocation = _$cordovaGeolocation_;
$rootScope = _$rootScope_;
$interval = _$interval_;
count = 0;
}));
it('should get the current position', function (done) {
var expected = {coords: { longitude:1, latitude:1 }, timestamp:Date()};
$cordovaGeolocation.currentPosition = expected;
$cordovaGeolocation.useHostAbilities = false;
$cordovaGeolocation.getCurrentPosition()
.then(
function(actual) { expect(actual).toBe(expected); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while getting the current position.', function(done) {
$cordovaGeolocation.throwsError = true;
$cordovaGeolocation.getCurrentPosition()
.then(
function(actual) { expect(false).toBe(true); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should track five locations over an interval', function() {
$cordovaGeolocation.useHostAbilities = false;
var watch = $cordovaGeolocation.watchPosition(gpsOptions);
watch.then(
function() { },
function(err) { expect(false).toBe(true); },
function(result) {
count = count + 1;
}
);
$interval.flush(5000);
$rootScope.$digest();
expect(count).toBe(5);
});
it('should clear a created watch', function() {
$cordovaGeolocation.useHostAbilities = false;
var watch = $cordovaGeolocation.watchPosition(gpsOptions);
watch.then(
function() { },
function(err) { expect(false).toBe(true); },
function(result) {
count = count + 1;
}
);
$interval.flush(5000);
$cordovaGeolocation.clearWatch(watch.watchID);
$rootScope.$digest();
expect(count).toBe(5);
});
it('should cancel a created watch', function() {
$cordovaGeolocation.useHostAbilities = false;
var watch = $cordovaGeolocation.watchPosition(gpsOptions);
watch.then(
function() { },
function(err) { expect(false).toBe(true); },
function(result) {
count = count + 1;
}
);
$interval.flush(5000);
watch.cancel();
$rootScope.$digest();
expect(count).toBe(5);
});
});
});

View File

@@ -0,0 +1,77 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaGlobalization', function () {
var $rootScope = null;
var $cordovaGlobalization = null;
beforeEach(inject(function (_$cordovaGlobalization_, _$rootScope_) {
$cordovaGlobalization = _$cordovaGlobalization_;
$rootScope = _$rootScope_;
}));
it('should get the preferred language', function (done) {
$cordovaGlobalization.getPreferredLanguage()
.then(
function(actual) {
expect(typeof actual).toBe('object');
expect(actual.value).toBeDefined();
expect(typeof actual.value).toBe('string');
expect(actual.value.length > 0).toBe(true);
},
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while getting the preferred language.', function(done) {
$cordovaGlobalization.throwsError = true;
$cordovaGlobalization.getPreferredLanguage()
.then(
function(actual) { expect(false).toBe(true); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should get the locale', function (done) {
$cordovaGlobalization.getLocaleName()
.then(
function(actual) {
expect(actual).toBeDefined();
expect(typeof actual).toBe('object');
expect(actual.value).toBeDefined();
expect(typeof actual.value).toBe('string');
expect(actual.value.length > 0).toBe(true);
},
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while getting the locale.', function(done) {
$cordovaGlobalization.throwsError = true;
$cordovaGlobalization.getLocaleName()
.then(
function(actual) { expect(false).toBe(true); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
});
})

View File

@@ -0,0 +1,74 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaGoogleAnalytics', function () {
var $timeout = null;
var $cordovaGoogleAnalytics = null;
beforeEach(inject(function (_$cordovaGoogleAnalytics_, _$timeout_) {
$cordovaGoogleAnalytics = _$cordovaGoogleAnalytics_;
$timeout = _$timeout_;
}));
var testPromises = function testPromises(funcName) {
$cordovaGoogleAnalytics[funcName](1)
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
);
$timeout.flush();
$cordovaGoogleAnalytics.throwsError = true;
$cordovaGoogleAnalytics[funcName](1)
.then(
function() { expect(false).toBe(true); },
function() { expect(true).toBe(true); }
);
$timeout.flush();
};
it('should start tracker', function () {
testPromises('startTrackerWithId');
});
it('should set User Id.', function() {
testPromises('setUserId');
});
it('should set debug mode.', function() {
testPromises('debugMode');
});
it('should track view.', function() {
testPromises('trackView');
});
it('should add customer dimensions.', function() {
testPromises('addCustomDimension');
});
it('should track event.', function() {
testPromises('trackEvent');
});
it('should track exception.', function() {
testPromises('trackException');
});
it('should track timing.', function() {
testPromises('trackTiming');
});
it('should add transaction.', function() {
testPromises('addTransaction');
});
it('should add add a transaction item.', function() {
testPromises('addTransactionItem');
});
});
})

View File

@@ -0,0 +1,67 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('keychain', function() {
var $rootScope = null;
var $cordovaKeychain = null;
beforeEach(inject(function(_$rootScope_, _$cordovaKeychain_) {
$rootScope = _$rootScope_;
$cordovaKeychain = _$cordovaKeychain_;
}));
it('should get values that are stored', function() {
$cordovaKeychain.keychains = { 'testService' : { 'testKey' : 'testValue' } };
$cordovaKeychain.getForKey('testKey', 'testService')
.then(
function(value) { expect(value).toEqual('testValue'); },
function() { expect(false).toBe(true); }
);
$rootScope.$apply();
});
it('should not get values that are not stored', function() {
$cordovaKeychain.getForKey('testKey', 'testService')
.then(
function() { expect(false).toBe(true); },
function() { expect(true).toBe(true); }
);
$rootScope.$apply();
});
it('should store values', function() {
$cordovaKeychain.setForKey('testKey', 'testService', 'testValue')
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(
function() {
expect($cordovaKeychain.keychains['testService']).toEqual({ 'testKey' : 'testValue'});
}
);
$rootScope.$apply();
});
it('should remove values', function() {
$cordovaKeychain.keychains = { 'testService' : { 'testKey' : 'testValue' }};
$cordovaKeychain.removeForKey('testKey', 'testService')
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(
function() {
expect($cordovaKeychain.keychains['testService']['testKey']).toBeUndefined();
}
);
$rootScope.$apply();
});
});
});

View File

@@ -0,0 +1,93 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaLocalNotification', function () {
var $cordovaLocalNotification = null;
var $timeout = null;
var $rootScope = null;
beforeEach(inject(function (_$timeout_, _$rootScope_, _$cordovaLocalNotification_) {
$cordovaLocalNotification = _$cordovaLocalNotification_;
$timeout = _$timeout_;
$rootScope = _$rootScope_;
localStorage.removeItem("ngCordLocNotif-1");
localStorage.removeItem("ngCordLocNotif-2");
}));
it('should set a scheduled notification', function(done) {
$cordovaLocalNotification.schedule({id : 1, mydata : "my data string"}).then(
function(){
var myNotif = JSON.parse(localStorage.getItem("ngCordLocNotif-1"));
expect(myNotif.id).toBe(1);
},
function() { expect(false).toBe(true); }
).finally(function() { done(); })
$rootScope.$digest();
});
it('should cancel a scheduled notification', function(done) {
localStorage.setItem("ngCordLocNotif-1", "{mydata: 'mydata'}");
$cordovaLocalNotification.cancel(1).then(
function(){
var myNotif = localStorage.getItem("ngCordLocNotif-1");
expect(myNotif).toBe(null);
},
function() { expect(false).toBe(true); }
).finally(function() { done(); })
$rootScope.$digest();
});
it('should find a scheduled notification', function(done) {
localStorage.setItem("ngCordLocNotif-1", "{mydata: 'mydata'}");
$cordovaLocalNotification.isScheduled(1).then(
function(res){
expect(res).toBe(true);
},
function() { expect(false).toBe(true); }
).finally(function() { done(); })
$rootScope.$digest();
});
it('should not find a scheduled notification', function(done) {
$cordovaLocalNotification.isScheduled(1).then(
function(res){
expect(res).toBe(false);
},
function() { expect(false).toBe(true); }
).finally(function() { done(); })
$rootScope.$digest();
});
it('should return 2 keys', function(done) {
localStorage.setItem("ngCordLocNotif-1", "{mydata: 'mydata'}");
localStorage.setItem("ngCordLocNotif-2", "{mydata: 'mydata2'}");
$cordovaLocalNotification.getAllIds(1).then(
function(res){
expect(res).toContain(1);
expect(res).toContain(2);
expect(res.length).toBe(2);
},
function() { expect(false).toBe(true); }
).finally(function() { done(); })
$rootScope.$digest();
});
it('should return 2 keys', function(done) {
localStorage.setItem("ngCordLocNotif-1", "{mydata: 'mydata'}");
localStorage.setItem("ngCordLocNotif-2", "{mydata: 'mydata2'}");
$cordovaLocalNotification.getIds(1).then(
function(res){
expect(res).toContain(1);
expect(res).toContain(2);
expect(res.length).toBe(2);
},
function() { expect(false).toBe(true); }
).finally(function() { done(); })
$rootScope.$digest();
});
});
})

View File

@@ -0,0 +1,30 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaNetwork', function () {
var $cordovaNetwork = null;
beforeEach(inject(function (_$cordovaNetwork_) {
$cordovaNetwork = _$cordovaNetwork_;
}));
it('should get network name', function () {
// TODO: This should integrate with the navigator connection property values.
$cordovaNetwork.connectionType = 'WiFi connection';
var networkName = $cordovaNetwork.getNetwork();
expect(networkName).toEqual('WiFi connection');
});
it('should check if online', function() {
var isOnline = $cordovaNetwork.isOnline();
expect(isOnline).toBe(true);
});
it('should check if offline', function() {
var isOffline = $cordovaNetwork.isOffline();
expect(isOffline).toBe(false);
})
});
})

View File

@@ -0,0 +1,81 @@
'use strict';
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaPush', function () {
var $rootScope = null;
var $timeout = null;
var $cordovaPush = null;
beforeEach(inject(function (_$cordovaPush_, _$rootScope_, _$timeout_) {
$cordovaPush = _$cordovaPush_;
$timeout = _$timeout_;
$rootScope = _$rootScope_;
}));
it('should register', function (done) {
var expectedToken = 'ABC';
$cordovaPush.deviceToken = expectedToken;
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
expect(notification.event).toBe('registered');
expect(notification.regid).toBe(expectedToken);
});
$cordovaPush.register({})
.then(
function(result) {
expect(result).toBe(expectedToken);
},
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
$timeout.flush();
});
it('should throw an error while register.', function(done) {
$cordovaPush.throwsError = true;
$cordovaPush.register()
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should unregister', function (done) {
$cordovaPush.unregister()
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while unregister.', function(done) {
$cordovaPush.throwsError = true;
$cordovaPush.unregister()
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
});
});

View File

@@ -0,0 +1,140 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaSocialSharing', function () {
var $rootScope = null;
var $cordovaSocialSharing = null;
beforeEach(inject(function (_$cordovaSocialSharing_, _$rootScope_) {
$cordovaSocialSharing = _$cordovaSocialSharing_;
$rootScope = _$rootScope_;
}));
it('should share with twitter', function (done) {
$cordovaSocialSharing.shareViaTwitter('Check out Ecofic!', null, 'http://www.ecofic.com')
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while sharing with twitter.', function(done) {
$cordovaSocialSharing.throwsError = true;
$cordovaSocialSharing.shareViaTwitter('Check out Ecofic!', null, 'http://www.ecofic.com')
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should share with whatsApp', function (done) {
$cordovaSocialSharing.shareViaWhatsApp('Check out Ecofic!', null, 'http://www.ecofic.com')
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while sharing with whatsApp.', function(done) {
$cordovaSocialSharing.throwsError = true;
$cordovaSocialSharing.shareViaWhatsApp('Check out Ecofic!', null, 'http://www.ecofic.com')
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should share with facebook', function (done) {
$cordovaSocialSharing.shareViaFacebook('Check out Ecofic!', null, 'http://www.ecofic.com')
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while sharing with facebook.', function(done) {
$cordovaSocialSharing.throwsError = true;
$cordovaSocialSharing.shareViaFacebook('Check out Ecofic!', null, 'http://www.ecofic.com')
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should share via sms', function (done) {
$cordovaSocialSharing.shareViaSMS('Check out Ecofic!', '1-555-555-5555')
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while sharing via sms.', function(done) {
$cordovaSocialSharing.throwsError = true;
$cordovaSocialSharing.shareViaSMS('Check out Ecofic!', '1-555-555-5555')
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should share via email', function (done) {
$cordovaSocialSharing.shareViaEmail('This is an email message', 'Email Subject', [], [], [])
.then(
function() { expect(true).toBe(true); },
function() { expect(false).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
it('should throw an error while sharing via email.', function(done) {
$cordovaSocialSharing.throwsError = true;
$cordovaSocialSharing.shareViaEmail('This is an email message', 'Email Subject', [], [], [])
.then(
function() { expect(true).toBe(false); },
function() { expect(true).toBe(true); }
)
.finally(function() { done(); })
;
$rootScope.$digest();
});
});
})

View File

@@ -0,0 +1,23 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaSplashscreen', function () {
var $cordovaSplashscreen = null;
beforeEach(inject(function (_$cordovaSplashscreen_) {
$cordovaSplashscreen = _$cordovaSplashscreen_;
}));
it('should hide the splash screen', function() {
$cordovaSplashscreen.hide();
expect(true).toBe(true);
});
it('should show the splash screen', function() {
$cordovaSplashscreen.show();
expect(true).toBe(true);
});
});
})

View File

@@ -0,0 +1,23 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaStatusbar', function () {
var $cordovaStatusbar = null;
beforeEach(inject(function (_$cordovaStatusbar_) {
$cordovaStatusbar = _$cordovaStatusbar_;
}));
it('should hide the status bar', function() {
$cordovaStatusbar.hide();
expect($cordovaStatusbar.isVisible()).toBe(false);
});
it('should show the status bar', function() {
$cordovaStatusbar.show();
expect($cordovaStatusbar.isVisible()).toBe(true);
});
});
})

View File

@@ -0,0 +1,52 @@
describe('ngCordovaMocks', function () {
beforeEach(function () {
module('ngCordovaMocks');
});
describe('cordovaToast', function () {
var $rootScope = null;
var $cordovaToast = null;
var message = 'A message.';
var functionNames = [
'showShortTop',
'showShortCenter',
'showShortBottom',
'showLongTop',
'showLongCenter',
'showLongBottom',
'show'
];
beforeEach(inject(function (_$cordovaToast_, _$rootScope_) {
$cordovaToast = _$cordovaToast_;
$rootScope = _$rootScope_;
}));
it('should show a toast', function () {
functionNames.forEach(function(functionName){
$cordovaToast[functionName](message)
.then(
function () {expect(true).toBe(true)},
function () {expect(false).toBe(true)}
)
.finally(function () {done();});
$rootScope.$digest();
});
});
it('should throw an error ', function (done) {
$cordovaToast.throwsError = true;
functionNames.forEach(function(functionName){
$cordovaToast[functionName](message)
.then(
function () {expect(true).toBe(false)},
function () {expect(true).toBe(true)}
)
.finally(function () {done();});
$rootScope.$digest();
})
});
});
});

View File

@@ -0,0 +1,49 @@
describe('ngCordovaMocks', function() {
beforeEach(function() {
module('ngCordovaMocks');
});
describe('cordovaVibration', function () {
var $cordovaVibration = null;
var $timeout = null;
var $rootScope = null;
beforeEach(inject(function (_$timeout_, _$rootScope_, _$cordovaVibration_) {
$cordovaVibration = _$cordovaVibration_;
$timeout = _$timeout_;
$rootScope = _$rootScope_;
}));
it('should vibrate for 500 milliseconds', function() {
expect($cordovaVibration.isVibrating).toBe(false);
$cordovaVibration.vibrate(500);
$timeout.flush();
$rootScope.$digest();
expect($cordovaVibration.isVibrating).toBe(false);
});
it('should be vibrating at 250 milliseconds', function() {
expect($cordovaVibration.isVibrating).toBe(false);
$cordovaVibration.vibrate(500);
$timeout.flush(400);
$rootScope.$digest();
expect($cordovaVibration.isVibrating).toBe(true);
});
it('should cancel vibration half way through', function() {
expect($cordovaVibration.isVibrating).toBe(false);
$cordovaVibration.vibrate(1000); // Vibrate for 1 second
$timeout.flush(500); // Fast-forward in time 500 milliseconds
$rootScope.$digest();
expect($cordovaVibration.isVibrating).toBe(true);
$cordovaVibration.cancelVibration(); // Stop the vibration
expect($cordovaVibration.isVibrating).toBe(false);
});
});
})