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

Bug 1168118 - Migrate test_sms_contact_input_validation.py to Gij #30236

Merged
merged 1 commit into from Jun 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions apps/sms/test/marionette/composer_test.js
Expand Up @@ -4,6 +4,7 @@
var assert = require('chai').assert;

var Messages = require('./lib/messages.js');
var InboxView = require('./lib/views/inbox/view');
var MessagesActivityCaller = require('./lib/messages_activity_caller.js');

marionette('Messages Composer', function() {
Expand Down Expand Up @@ -258,4 +259,41 @@ marionette('Messages Composer', function() {
assertIsFocused(composer.messageInput, 'Message input should be focused');
});
});


suite('Invalid recipients', function() {
var newMessage;

setup(function() {
messagesApp.launch();

var inbox = new InboxView(client);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new line after messagesApp.launch();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

newMessage = inbox.createNewMessage();
});

suite('the recipients list', function() {
test('should display that a non existing contact is invalid', function() {
newMessage.addNewRecipient('non_exisiting_contact');
assert.isTrue(newMessage.containsInvalidRecipients());
});

test('should allow to correct an invalid contact', function() {
newMessage.addNewRecipient('non_exisiting_contact');
newMessage.clearRecipients();
newMessage.addNewRecipient(123);
assert.lengthOf(newMessage.recipients, 1);
assert.equal(newMessage.recipients[0], '123');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe also assert.isFalse(newMessage.containsInvalidRecipients()); here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Done.

assert.isFalse(newMessage.containsInvalidRecipients());
});
});

suite('Content composer', function() {
test('should not enable send button if the contact is invalid',
function() {
newMessage.addNewRecipient('invalidContact');
newMessage.typeMessage('Test message');
assert.isFalse(newMessage.isSendButtonEnabled());
});
});
});
});
121 changes: 5 additions & 116 deletions apps/sms/test/marionette/lib/messages.js
Expand Up @@ -2,6 +2,8 @@

/* global module */
var InboxAccessor = require('./views/inbox/accessors');
var ComposerAccessor = require('./views/new-message/accessors');
var NewMessageView = require('./views/new-message/view');
var ConversationAccessor = require('./views/conversation/accessors');

(function(module) {
Expand All @@ -14,49 +16,13 @@ var ConversationAccessor = require('./views/conversation/accessors');
BACKSPACE: '\ue003'
};

function observeElementStability(el) {
delete el.dataset.__stable;

function markElementAsStable() {
return setTimeout(function() {
el.dataset.__stable = 'true';
observer.disconnect();
}, 1000);
}

var timeout = markElementAsStable();
var observer = new MutationObserver(function() {
if (timeout) {
clearTimeout(timeout);
timeout = markElementAsStable();
}
});
observer.observe(el, { childList: true, subtree: true });
}

var SELECTORS = Object.freeze({
main: '#main-wrapper',

optionMenu: 'body > form[data-type=action] menu',
systemMenu: 'form[data-z-index-level="action-menu"]',
contactPromptMenu: '.contact-prompt menu',

Composer: {
toField: '#messages-to-field',
recipientsInput: '#messages-to-field [contenteditable=true]',
recipient: '#messages-recipients-list .recipient[contenteditable=false]',
messageInput: '#messages-input',
subjectInput: '.subject-composer-input',
sendButton: '#messages-send-button',
attachButton: '#messages-attach-button',
header: '#messages-header',
charCounter: '.message-counter',
moreHeaderButton: '#messages-options-button',
mmsLabel: '.mms-label',
attachment: '#messages-input .attachment-container',
messageConvertNotice: '#messages-convert-notice'
},

Message: {
content: '.message-content > p:first-child',
vcardAttachment: '[data-attachment-type="vcard"]',
Expand All @@ -83,69 +49,7 @@ var ConversationAccessor = require('./views/conversation/accessors');

manifestURL: MANIFEST_URL,

Composer: {
get toField() {
return client.helper.waitForElement(SELECTORS.Composer.toField);
},

get recipientsInput() {
return client.helper.waitForElement(
SELECTORS.Composer.recipientsInput
);
},

get recipients() {
return client.findElements(SELECTORS.Composer.recipient);
},

get messageInput() {
return client.helper.waitForElement(
SELECTORS.Composer.messageInput
);
},

get subjectInput() {
return client.helper.waitForElement(
SELECTORS.Composer.subjectInput
);
},

get sendButton() {
return client.helper.waitForElement(SELECTORS.Composer.sendButton);
},

get attachButton() {
return client.helper.waitForElement(
SELECTORS.Composer.attachButton
);
},

get header() {
return client.helper.waitForElement(SELECTORS.Composer.header);
},

get charCounter() {
return client.findElement(SELECTORS.Composer.charCounter);
},

get mmsLabel() {
return client.findElement(SELECTORS.Composer.mmsLabel);
},

get attachment() {
return client.findElement(SELECTORS.Composer.attachment);
},

get conversionBanner() {
return client.findElement(SELECTORS.Composer.messageConvertNotice);
},

showOptions: function() {
client.helper.waitForElement(
SELECTORS.Composer.moreHeaderButton
).tap();
}
},
Composer: new ComposerAccessor(client),

Conversation: new ConversationAccessor(client),

Expand Down Expand Up @@ -264,23 +168,8 @@ var ConversationAccessor = require('./views/conversation/accessors');
}
},

addRecipient: function(number) {
this.Composer.recipientsInput.sendKeys(number + Chars.ENTER);

// Since recipient.js re-renders recipients all the time (when new
// recipient is added or old is removed) and it can happen several
// times during single "add" or "remove" operation we should
// wait until Recipients View is in a final state. The problem here is
// that between "findElement" and "displayed" calls element can
// actually be removed from DOM and re-created again that will lead to
// "stale element" exception.
var toField = this.Composer.toField;
toField.scriptWith(observeElementStability);
client.helper.waitFor(function() {
return toField.scriptWith(function(el) {
return !!el.dataset.__stable;
});
});
addRecipient: function(recipient) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! Can we use the same approach for messages.clearRecipient then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're dealing with another DOM element. I'm not sure this is necessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well essentially they do exactly the same thing, no matter how they are done internally, but we can revise it later anyway.

new NewMessageView(client).addNewRecipient(recipient);
},

getRecipient: function(number) {
Expand Down
9 changes: 7 additions & 2 deletions apps/sms/test/marionette/lib/views/inbox/accessors.js
Expand Up @@ -27,15 +27,20 @@ InboxAccessor.prototype = {
return this.client.helper.waitForElement(SELECTORS.mmsConversation);
},

get createNewMessageButton() {
return this.client.helper.waitForElement(
SELECTORS.navigateToComposerHeaderButton
);
},

waitToAppear: function() {
return this.client.helper.waitForElement(SELECTORS.main);
},

// Temporary solution to keep the current tests running.
// TODO: bug 1167103
navigateToComposer: function() {
this.client.helper.waitForElement(SELECTORS.navigateToComposerHeaderButton)
.tap();
this.createNewMessageButton.tap();
}
};

Expand Down
8 changes: 8 additions & 0 deletions apps/sms/test/marionette/lib/views/inbox/view.js
Expand Up @@ -17,4 +17,12 @@ InboxView.prototype.goToFirstThread = function() {
return conversation;
};

InboxView.prototype.createNewMessage = function() {
this.accessors.createNewMessageButton.tap();
var NewMessageView = require('../new-message/view');
var newMessage = new NewMessageView(this.client);
newMessage.accessors.waitToAppear();
return newMessage;
};

module.exports = InboxView;
91 changes: 91 additions & 0 deletions apps/sms/test/marionette/lib/views/new-message/accessors.js
@@ -0,0 +1,91 @@
'use strict';

/* global module */

var SELECTORS = Object.freeze({
main: '#thread-messages',
toField: '#messages-to-field',
// last-child is a temporary workaound for bug 1097575
recipientsInput: '#messages-to-field [contenteditable=true]:last-child',
recipientsList: '#messages-recipients-list',
recipients: '#messages-recipients-list .recipient[contenteditable=false]',
messageInput: '#messages-input',
subjectInput: '.subject-composer-input',
sendButton: '#messages-send-button',
attachButton: '#messages-attach-button',
header: '#messages-header',
charCounter: '.message-counter',
moreHeaderButton: '#messages-options-button',
mmsLabel: '.mms-label',
attachment: '#messages-input .attachment-container',
messageConvertNotice: '#messages-convert-notice'
});

function NewMessageAccessor(client) {
this.client = client;
}

NewMessageAccessor.prototype = {
get toField() {
return this.client.helper.waitForElement(SELECTORS.toField);
},

get recipientsInput() {
return this.client.helper.waitForElement(SELECTORS.recipientsInput);
},

get recipientsList() {
return this.client.helper.waitForElement(SELECTORS.recipientsList);
},

get recipients() {
return this.client.findElements(SELECTORS.recipients);
},

get messageInput() {
return this.client.helper.waitForElement(SELECTORS.messageInput);
},

get subjectInput() {
return this.client.helper.waitForElement(SELECTORS.subjectInput);
},

get sendButton() {
return this.client.helper.waitForElement(SELECTORS.sendButton);
},

get attachButton() {
return this.client.helper.waitForElement(SELECTORS.attachButton);
},

get header() {
return this.client.helper.waitForElement(SELECTORS.header);
},

get charCounter() {
return this.client.findElement(SELECTORS.charCounter);
},

get mmsLabel() {
return this.client.findElement(SELECTORS.mmsLabel);
},

get attachment() {
return this.client.findElement(SELECTORS.attachment);
},

get conversionBanner() {
return this.client.findElement(SELECTORS.messageConvertNotice);
},

waitToAppear: function() {
return this.client.helper.waitForElement(SELECTORS.main);
},

// TODO: bug 1171989
showOptions: function() {
this.client.helper.waitForElement(SELECTORS.moreHeaderButton).tap();
}
};

module.exports = NewMessageAccessor;