Bug 1168118 - Migrate test_sms_contact_input_validation.py to Gij #30236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
|
@@ -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); | ||
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe also There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
}); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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"]', | ||
|
@@ -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), | ||
|
||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good! Can we use the same approach for There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.