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 #13335 from KevinGrandon/bug_924274_contact_tests
Browse files Browse the repository at this point in the history
Bug 924274 - [Contacts] Add initial marionette tests
  • Loading branch information
KevinGrandon committed Nov 6, 2013
2 parents 85c929f + 503e36d commit 5814d4b
Show file tree
Hide file tree
Showing 9 changed files with 543 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/communications/contacts/js/contacts.js
Expand Up @@ -338,6 +338,7 @@ var Contacts = (function() {

if (!customTag) {
customTag = document.querySelector('#custom-tag');
customTag.addEventListener('keydown', handleCustomTag);
customTag.addEventListener('touchend', handleCustomTag);
}
if (!customTagReset) {
Expand Down
137 changes: 137 additions & 0 deletions apps/communications/contacts/test/marionette/activities_test.js
@@ -0,0 +1,137 @@
var Contacts = require('./lib/contacts');
var Dialer = require('./lib/dialer');
var Sms = require('./lib/sms');
var assert = require('assert');

marionette('Contacts > Activities', function() {
var client = marionette.client(Contacts.config);

var dialerSubject;

var smsSubject;
var smsSelectors;

var subject;
var selectors;

setup(function() {
subject = new Contacts(client);
selectors = Contacts.Selectors;

dialerSubject = new Dialer(client);

smsSubject = new Sms(client);
smsSelectors = Sms.Selectors;
});

suite('webcontacts/contact activity', function() {
test('a contact with duplicate number shows merge page', function() {

subject.launch();

subject.addContact({
givenName: 'From Contacts App',
tel: 1111
});

client.apps.close(Contacts.URL, 'contacts');

dialerSubject.launch();

// Dialer keys don't work in b2g desktop for some reason yet,
// So just manually fire off the activity
client.executeScript(function() {
var activity = new MozActivity({
name: 'new',
data: {
type: 'webcontacts/contact',
params: {
'tel': 1111
}
}
});
});

client.switchToFrame();
client.apps.switchToApp(Contacts.URL, 'contacts');

subject.enterContactDetails({
givenName: 'From Dialer Activity'
}, true);

client.switchToFrame(client.findElement(selectors.duplicateFrame));

var duplicateHeader = client.helper.
waitForElement(selectors.duplicateHeader);
var expectedResult = subject.l10n(
'/contacts/locales/matcher/matcher.en-US.properties',
'duplicatesFoundTitle');

assert.equal(duplicateHeader.text(), expectedResult);
});
});

suite('webcontacts/tel activity', function() {
test('Error message when no contacts', function() {

smsSubject.launch();

// Launch the activity directly as mozSms has problems
// in b2g desktop.
client.executeScript(function() {
var activity = new MozActivity({
name: 'pick',
data: {
type: 'webcontacts/tel'
}
});
});

client.switchToFrame();
client.apps.switchToApp(Contacts.URL, 'contacts');

var confirmMsg = client.findElement(selectors.confirmBody);
var expectedResult = subject.l10n(
'/contacts/locales/contacts.en-US.properties',
'noContactsActivity');
assert.equal(confirmMsg.text(), expectedResult);
});

test('Error message selected contact has no number', function() {

subject.launch();

subject.addContact({
givenName: 'No Phone Number'
});

client.apps.close(Contacts.URL, 'contacts');

smsSubject.launch();

client.executeScript(function() {
var activity = new MozActivity({
name: 'pick',
data: {
type: 'webcontacts/tel'
}
});
});

client.switchToFrame();
client.apps.switchToApp(Contacts.URL, 'contacts');
client.helper.waitForElement(selectors.bodyReady);

client.helper.waitForElement(selectors.listContactFirst)
.click();

var confirmText = client.helper.waitForElement(selectors.confirmBody)
.text();

var expectedResult = subject.l10n(
'/contacts/locales/contacts.en-US.properties',
'no_contact_phones');
assert.equal(confirmText, expectedResult);
});
});
});
43 changes: 43 additions & 0 deletions apps/communications/contacts/test/marionette/details_test.js
@@ -0,0 +1,43 @@
var Contacts = require('./lib/contacts');
var assert = require('assert');

marionette('Contacts > Details', function() {
var client = marionette.client(Contacts.config);
var subject;
var selectors;

setup(function() {
subject = new Contacts(client);
subject.launch();

selectors = Contacts.Selectors;
});

suite('Click phone number', function() {
test('Shows error /w no sim', function() {
var tel = 1231231234;

subject.addContact({
givenName: 'Hello',
tel: 1231231234
});

client.helper.waitForElement(selectors.listContactFirstText)
.click();

client.helper.waitForElement(selectors.details);

client.helper.waitForElement(selectors.detailsTelButtonFirst)
.click();

var header = client.helper.waitForElement(selectors.confirmHeader);

var expectedHeaderText = subject.l10n(
'/dialer/locales/shared.en-US.properties',
'emergencyDialogTitle');

assert.equal(header.text(), expectedHeaderText);
});
});

});
81 changes: 81 additions & 0 deletions apps/communications/contacts/test/marionette/form_test.js
@@ -0,0 +1,81 @@
var Contacts = require('./lib/contacts');
var assert = require('assert');

marionette('Contacts > Form', function() {
var client = marionette.client(Contacts.config);
var subject;
var selectors;

setup(function() {
subject = new Contacts(client);
subject.launch();

selectors = Contacts.Selectors;
});

suite('Click phone number', function() {
test('Add a simple contact', function() {

var givenName = 'Hello';
var familyName = 'World';

subject.addContact({
givenName: givenName,
familyName: familyName
});

var listView = client.helper.waitForElement(selectors.list);
assert.ok(listView.displayed(), 'List view is shown.');

var listElementText = client.helper
.waitForElement(selectors.listContactFirst)
.text();

assert.notEqual(listElementText.indexOf(givenName), -1);
assert.notEqual(listElementText.indexOf(familyName), -1);
});

test('Can create custom label', function() {
subject.addContact({
givenName: 'Custom Label Test',
tel: 1231231234
});

client.helper.waitForElement(selectors.listContactFirstText)
.click();

client.helper.waitForElement(selectors.details);
client.helper.waitForElement(selectors.detailsEditContact)
.click();

subject.waitForFormShown();

client.helper.waitForElement(selectors.formTelLabelFirst)
.click();

client.helper.waitForElement(selectors.formCustomTag)
.sendKeys('BFF');

client.helper.waitForElement(selectors.formCustomTagDone)
.click();

// Wait for the custom tag page to disappear
client.waitFor(function waiting() {
var tagPage = client.findElement(selectors.formCustomTagPage);
var className = tagPage.getAttribute('className');
return className.indexOf('app-go-left-in') === -1;
});

client.findElement(selectors.formSave)
.click();

client.helper.waitForElement(selectors.detailsTelLabelFirst);
client.waitFor(function waiting() {
var label = client.findElement(selectors.detailsTelLabelFirst).text();
return label === 'BFF';
});
assert.ok(true, 'custom label is updated.');
});
});

});

0 comments on commit 5814d4b

Please sign in to comment.