Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25457 from ADLR-es/confirm-if-no-contacts
Browse files Browse the repository at this point in the history
Bug 1072180 - [GAIA][Contacts]if No Contacts on Gmail, while import sele...
  • Loading branch information
jmcanterafonseca committed Oct 29, 2014
2 parents 37089e0 + d29cf5f commit fbb6108
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 15 deletions.
58 changes: 43 additions & 15 deletions apps/communications/contacts/test/unit/import/import_test.js
Expand Up @@ -2,7 +2,8 @@

/* global utils, importer, MockAlphaScroll, MockImageLoader */
/* global MockSearch, MockasyncStorage, MockOauthflow, MockImportHtml */
/* global MockConnector, MockImportedContacts, MockCurtain */
/* global MockConnector, MockImportedContacts, MockCurtain, MockLazyLoader */
/* global MockConfirmDialog */

require('/shared/js/text_normalizer.js');
require('/shared/js/contacts/search.js');
Expand All @@ -11,6 +12,8 @@ require('/shared/js/contacts/import/importer_ui.js');
require('/shared/js/contacts/import/utilities/misc.js');
require('/shared/js/contacts/utilities/dom.js');
require('/shared/js/contacts/utilities/templates.js');
require('/shared/test/unit/mocks/mock_lazy_loader.js');
require('/shared/test/unit/mocks/mock_confirm_dialog.js');

requireApp('communications/contacts/test/unit/import/mock_import.html.js');
requireApp('communications/contacts/test/unit/mock_asyncstorage.js');
Expand All @@ -30,6 +33,9 @@ var realSearch,
realAsyncStorage,
realOauthflow,
realCurtain,
realLazyLoader,
realConfirmDialog,
realParentLazyLoader,
groupsListChild, groupsList;

if (!window.asyncStorage) {
Expand All @@ -52,6 +58,14 @@ if (!window.oauthflow) {
window.oauthflow = null;
}

if (!window.LazyLoader) {
window.LazyLoader = null;
}

if (!window.ConfirmDialog) {
window.ConfirmDialog = null;
}

setup(function() {
importer.reset();
});
Expand All @@ -78,6 +92,15 @@ suite('Import Friends Test Suite', function() {
realOauthflow = window.oauthflow;
window.oauthflow = MockOauthflow;

realLazyLoader = window.LazyLoader;
window.LazyLoader = MockLazyLoader;

realConfirmDialog = window.ConfirmDialog;
window.ConfirmDialog = MockConfirmDialog;

realParentLazyLoader = window.parent.LazyLoader;
window.parent.LazyLoader = MockLazyLoader;

document.body.innerHTML = MockImportHtml;

groupsList = document.body.querySelector('#groups-list');
Expand All @@ -104,7 +127,7 @@ suite('Import Friends Test Suite', function() {
querySelector('section#group-P li[data-uuid="1xz"]'));
assert.isNotNull(document.
querySelector('section#group-A li[data-uuid="2abc"]'));
assert.isNotNull(document.
assert.isNotNull(document.
querySelector('section#group-Ψ li[data-uuid="3cde"]'));

assert.equal(document.querySelectorAll('section#group-G *').length, 0);
Expand Down Expand Up @@ -231,12 +254,16 @@ suite('Import Friends Test Suite', function() {
}
);

var spy = sinon.spy(window.ConfirmDialog, 'show');

importer.start('mock_token', MockConnector, '*', function() {
var friendsMsgElement = document.querySelector('#friends-msg');
assert.equal(friendsMsgElement.getAttribute('data-l10n-id'),
'fbNoFriends');
done();
done(function() {
assert.isTrue(spy.called);
assert.isTrue(spy.calledWith(null, 'emptyAccount'));
});
});

spy.restore();
MockConnector.listDeviceContacts = listDeviceContacts;
});

Expand All @@ -250,18 +277,16 @@ suite('Import Friends Test Suite', function() {
callbacks.success({ data: []});
};

importer.start('mock_token', MockConnector, '*', function() {

assert.isTrue(document.getElementById('deselect-all').disabled === true);
assert.isTrue(document.getElementById('select-all').disabled === false);
var spy = sinon.spy(window.ConfirmDialog, 'show');

var friendsElement = document.getElementById('friends-msg');
assert.equal(friendsElement.getAttribute('data-l10n-id'),
'fbNoFriends');

done();
importer.start('mock_token', MockConnector, '*', function() {
done(function() {
assert.isTrue(spy.called);
assert.isTrue(spy.calledWith(null, 'emptyAccount'));
});
});

spy.restore();
MockConnector.listAllContacts = listAllContacts;
});

Expand Down Expand Up @@ -438,6 +463,9 @@ suite('Import Friends Test Suite', function() {
window.asyncStorage = realAsyncStorage;
window.oauthflow = realOauthflow;
window.curtain = realCurtain;
window.LazyLoader = realLazyLoader;
window.ConfirmDialog = realConfirmDialog;
window.parent.LazyLoader = realParentLazyLoader;
});

});
Expand Down
35 changes: 35 additions & 0 deletions shared/js/contacts/import/importer_ui.js
Expand Up @@ -540,6 +540,13 @@ if (typeof window.importer === 'undefined') {
Importer.friendsReady = function(response) {
if (typeof response.error === 'undefined') {
var lmyFriends = response.data;

if (lmyFriends.length === 0) {
showNoFriends(function() {
Curtain.hide(UI.end);
});
return;
}
// Notifying the connector
if (typeof serviceConnector.oncontactsloaded === 'function') {
serviceConnector.oncontactsloaded(lmyFriends);
Expand Down Expand Up @@ -590,6 +597,34 @@ if (typeof window.importer === 'undefined') {
} // else
};

function showNoFriends(callback) {
var dialog = parent.document.getElementById('confirmation-message');
parent.LazyLoader.load(dialog, function() {
LazyLoader.load('/shared/js/confirm.js', function() {
ConfirmDialog.show(null, 'emptyAccount',
{
title: 'ok',
isRecommend: true,
callback: function() {
ConfirmDialog.hide();
if(typeof callback === 'function') {
callback();
}
}
},
null,
{
zIndex: '10000'
});

// Only for unit testing purposes
if (typeof startCallback === 'function') {
window.setTimeout(startCallback, 0);
}
});
});
}

function cancelImport() {
cancelled = true;

Expand Down
Expand Up @@ -3,6 +3,7 @@ noSimMsg = To import contacts insert or unlock your SIM card
noMemoryCardMsg = To import contacts insert a memory card
importMemoryCard = Memory card
noConnection11 = To import Facebook friends or contacts connect to Wi-Fi or data network
emptyAccount = No friends or contacts found in this account.

# SIM import
simContacts-import = Import SIM contacts
Expand Down

0 comments on commit fbb6108

Please sign in to comment.