1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-21 23:08:50 -05:00
mail/test/unit/controller/app/contacts-ctrl-test.js
Tankred Hase c93eaf17f3 Implement HKP server support
* Add public key import lightbox for copy and paste
* Fix refresh of pgp key change in keychain
* Display additional contacts info
* Filter by name and email addres in autocomplete
* Accept all file endings for key import

Accept all types of files for key import
2015-02-02 20:15:10 +01:00

112 lines
3.6 KiB
JavaScript

'use strict';
var ContactsCtrl = require('../../../../src/js/controller/app/contacts'),
Keychain = require('../../../../src/js/service/keychain'),
PGP = require('../../../../src/js/crypto/pgp'),
Dialog = require('../../../../src/js/util/dialog');
describe('Contacts Controller unit test', function() {
var scope, contactsCtrl, keychainStub, pgpStub, dialogStub;
beforeEach(function() {
pgpStub = sinon.createStubInstance(PGP);
keychainStub = sinon.createStubInstance(Keychain);
dialogStub = sinon.createStubInstance(Dialog);
angular.module('contactstest', ['woServices']);
angular.mock.module('contactstest');
angular.mock.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
scope.state = {};
contactsCtrl = $controller(ContactsCtrl, {
$scope: scope,
$q: window.qMock,
keychain: keychainStub,
pgp: pgpStub,
dialog: dialogStub
});
});
});
afterEach(function() {});
describe('scope variables', function() {
it('should be set correctly', function() {
expect(scope.state.contacts.toggle).to.exist;
});
});
describe('listKeys', function() {
it('should fail due to error in keychain.listLocalPublicKeys', function(done) {
keychainStub.listLocalPublicKeys.returns(rejects(42));
scope.listKeys().then(function() {
expect(dialogStub.error.calledOnce).to.be.true;
done();
});
});
it('should work', function(done) {
keychainStub.listLocalPublicKeys.returns(resolves([{
_id: '12345'
}]));
pgpStub.getKeyParams.returns({
fingerprint: 'asdf',
userIds: [{
name: 'Firstname Lastname',
emailAddress: 'first.last@example.com'
}]
});
expect(scope.keys).to.not.exist;
scope.listKeys().then(function() {
expect(scope.keys.length).to.equal(1);
expect(scope.keys[0]._id).to.equal('12345');
expect(scope.keys[0].fingerprint).to.equal('asdf');
expect(scope.keys[0].fullUserId).to.equal('Firstname Lastname <first.last@example.com>');
done();
});
});
});
describe('getFingerprint', function() {
it('should work', function() {
var key = {
fingerprint: 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
};
scope.getFingerprint(key);
expect(scope.fingerprint).to.equal('YYYY YYYY YYYY YYYY YYYY ... YYYY YYYY YYYY YYYY YYYY');
});
});
describe('removeKey', function() {
it('should work', function(done) {
var key = {
_id: '12345'
};
keychainStub.removeLocalPublicKey.withArgs('12345').returns(resolves());
scope.listKeys = function() {};
scope.removeKey(key).then(function() {
done();
});
});
it('should fail due to error in keychain.removeLocalPublicKey', function(done) {
var key = {
_id: '12345'
};
keychainStub.removeLocalPublicKey.withArgs('12345').returns(rejects(42));
scope.removeKey(key).then(function() {
expect(dialogStub.error.calledOnce).to.be.true;
done();
});
});
});
});