diff --git a/apps/email/test/marionette/email.js b/apps/email/test/marionette/email.js index bf9b49ba5e89..003f2666f031 100644 --- a/apps/email/test/marionette/email.js +++ b/apps/email/test/marionette/email.js @@ -1,3 +1,4 @@ +/*jshint node: true, browser: true */ function Email(client) { this.client = client; } @@ -47,27 +48,12 @@ Email.prototype = { return this.client.findElement(Selector.notificationBar); }, - setupImapEmail: function() { - const USER_NAME = 'GAIA'; - const EMAIL_ADDRESS = 'marionette.js.client@gmail.com'; - const PASSWORD = 'tpemozilla'; - // wait for the setup page is loaded - this.client.helper. - waitForElement(Selector.manualConfigButton); - // setup a IMAP email account - this._setupTypeName(USER_NAME); - this._setupTypeEmail(EMAIL_ADDRESS); - this._setupTypePassword(PASSWORD); - this._setupTapNext(); - this._waitForSetupCompleted(); - this._tapContinue(); - }, - manualSetupImapEmail: function(server) { // wait for the setup page is loaded this.client.helper. waitForElement(Selector.manualConfigButton). tap(); + this._waitForTransitionEnd('setup_manual_config'); // setup a IMAP email account var email = server.imap.username + '@' + server.imap.hostname; this._manualSetupTypeName(server.imap.username); @@ -92,7 +78,7 @@ Email.prototype = { tapCompose: function() { this.client.findElement(Selector.composeButton).tap(); // wait for being in the compose page - this._waitForTransitionEnd(); + this._waitForTransitionEnd('compose'); }, typeTo: function(email) { @@ -118,10 +104,10 @@ Email.prototype = { waitForElement(Selector.composeBodyInput).getAttribute('value'); }, - abortCompose: function() { + abortCompose: function(cardId) { this.client.helper.waitForElement(Selector.composeBackButton).tap(); this.client.helper.waitForElement(Selector.composeDraftDiscard).tap(); - this._waitForTransitionEnd(); + this._waitForTransitionEnd(cardId); }, tapSend: function() { @@ -141,16 +127,17 @@ Email.prototype = { tap(); // wait for being in the email list page client.helper.waitForElement(Selector.refreshButton); - this._waitForTransitionEnd(); + this._waitForTransitionEnd('message_list'); }, - waitForNewEmail: function() { - var client = this.client; - client. + tapRefreshButton: function() { + this.client. findElement(Selector.refreshButton). tap(); - // show a new email notification - client.helper.waitForElement(Selector.notificationBar); + }, + + waitForNewEmail: function() { + this.client.helper.waitForElement(Selector.notificationBar); }, launch: function() { @@ -165,7 +152,7 @@ Email.prototype = { var client = this.client; var element = client.findElements(Selector.messageHeaderItem)[index]; element.tap(); - this._waitForTransitionEnd(); + this._waitForTransitionEnd('message_reader'); }, /** @@ -191,27 +178,19 @@ Email.prototype = { break; } client.findElement(whichButton).tap(); - this._waitForTransitionEnd(); + this._waitForTransitionEnd('compose'); }, - _waitForTransitionEnd: function() { + _waitForTransitionEnd: function(cardId) { var client = this.client; client.waitFor(function() { - var condition = false; - client.executeScript( - function() { - return window.wrappedJSObject. - require('mail_common'). - Cards. - _eatingEventsUntilNextCard; - }, - function(error, result) { - if (result === false) { - condition = true; - } - } - ); - return condition; + return client.executeScript(function(cardId) { + var Cards = window.wrappedJSObject.require('mail_common').Cards, + card = Cards._cardStack[Cards.activeCardIndex], + cardNode = card && card.domNode; + return cardNode && cardNode.dataset.type === cardId && + !Cards._eatingEventsUntilNextCard; + }, [cardId]); }); }, @@ -233,13 +212,6 @@ Email.prototype = { sendKeys(password); }, - _setupTapNext: function() { - this._waitForTransitionEnd(); - this.client. - findElement(Selector.nextButton). - tap(); - }, - _manualSetupTypeName: function(name) { this.client. findElement(Selector.manualSetupNameInput). @@ -317,7 +289,7 @@ Email.prototype = { }, _manualSetupTapNext: function() { - this._waitForTransitionEnd(); + this._waitForTransitionEnd('setup_manual_config'); this.client. findElement(Selector.manualNextButton). tap(); diff --git a/apps/email/test/marionette/reply_imap_email_test.js b/apps/email/test/marionette/reply_imap_email_test.js index 5aa0f25831fe..fae9abe63b2d 100644 --- a/apps/email/test/marionette/reply_imap_email_test.js +++ b/apps/email/test/marionette/reply_imap_email_test.js @@ -21,7 +21,7 @@ marionette('reply to an e-mail', function() { var BODY_TEXT = 'I still have a dream.'; var app; - var server = serverHelper.use({}, this); + var server = serverHelper.use(null, this); setup(function() { app = new Email(client); app.launch(); @@ -36,6 +36,7 @@ marionette('reply to an e-mail', function() { app.typeBody(BODY_TEXT); app.tapSend(); + app.tapRefreshButton(); app.waitForNewEmail(); app.tapEmailAtIndex(0); }); @@ -48,7 +49,7 @@ marionette('reply to an e-mail', function() { assert(body.indexOf('wrote') != -1, format('body should contain "wrote", was "%s"', body)); - app.abortCompose(); + app.abortCompose('message_reader'); }); test('should be able to "reply all" to an email', function() { @@ -59,7 +60,7 @@ marionette('reply to an e-mail', function() { assert(body.indexOf('wrote') != -1, format('body should contain "wrote", was "%s"', body)); - app.abortCompose(); + app.abortCompose('message_reader'); }); test('should be able to forward an email', function() { @@ -70,6 +71,7 @@ marionette('reply to an e-mail', function() { assert(body.indexOf('Original message') != -1, format('body should contain "Original message", was "%s"', body)); - app.abortCompose(); + app.abortCompose('message_reader'); }); }); + diff --git a/apps/email/test/marionette/send_imap_email_test.js b/apps/email/test/marionette/send_imap_email_test.js index 7fa54c7aa921..f038346f5e8d 100644 --- a/apps/email/test/marionette/send_imap_email_test.js +++ b/apps/email/test/marionette/send_imap_email_test.js @@ -3,20 +3,20 @@ var assert = require('assert'); var serverHelper = require('./lib/server_helper'); marionette('send email via IMAP', function() { - var client = marionette.client({ - settings: { - // disable keyboard ftu because it blocks our display - 'keyboard.ftu.enabled': false - } - }); + var app, + client = marionette.client({ + settings: { + // disable keyboard ftu because it blocks our display + 'keyboard.ftu.enabled': false + } + }); - var app; setup(function() { app = new Email(client); app.launch(); }); - var server = serverHelper.use({}, this); + var server = serverHelper.use(null, this); test('should send a email', function() { const ONE_NEW_EMAIL_NOTIFICATION = '1 New Email'; @@ -30,15 +30,15 @@ marionette('send email via IMAP', function() { app.typeBody('I still have a dream.'); app.tapSend(); + app.tapRefreshButton(); app.waitForNewEmail(); // get the text of the notification bar - app.notificationBar. - text(function(error, text) { - assert.equal( - text, - ONE_NEW_EMAIL_NOTIFICATION, - text + ' should equal ' + ONE_NEW_EMAIL_NOTIFICATION - ); - }); + var notificationText = app.notificationBar.text(); + assert.equal( + notificationText, + ONE_NEW_EMAIL_NOTIFICATION, + notificationText + ' should equal ' + ONE_NEW_EMAIL_NOTIFICATION + ); }); }); +