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 #30381 from azasypkin/bug-xxx-modular-startup
Browse files Browse the repository at this point in the history
Bug 1162028 - [Messages][NG] Extract views/conversation/conversation.html
  • Loading branch information
azasypkin committed Jun 16, 2015
2 parents ae44238 + 83370df commit 70c9bee
Show file tree
Hide file tree
Showing 33 changed files with 1,331 additions and 190 deletions.
85 changes: 85 additions & 0 deletions apps/sharedtest/test/unit/event_dispatcher_test.js
Expand Up @@ -142,6 +142,91 @@ suite('EventDispatcher >', function() {
});
});

suite('once >', function() {
test('throws if event name is not valid string', function() {
assert.throws(() => eventTarget.once());
assert.throws(() => eventTarget.once('', () => {}));
assert.throws(() => eventTarget.once(null, () => {}));
});

test('throws if handler is not function', function() {
assert.throws(() => eventTarget.once('event'));
assert.throws(() => eventTarget.once('event', null));
assert.throws(() => eventTarget.once('event', {}));
});

test('successfully registers handler', function() {
var expectedHandler = sinon.stub(),
unexpectedHandler = sinon.stub();

eventTarget.once('not-expected-event', unexpectedHandler);
eventTarget.once('event', expectedHandler);

eventTarget.emit('event');
sinon.assert.calledOnce(expectedHandler);

// Should not call handler more than once.
eventTarget.emit('event');
sinon.assert.calledOnce(expectedHandler);
sinon.assert.notCalled(unexpectedHandler);
});

test('successfully registers multiple handlers', function() {
var expectedHandler1 = sinon.stub(),
expectedHandler2 = sinon.stub(),
unexpectedHandler = sinon.stub();

eventTarget.once('not-expected-event', unexpectedHandler);
eventTarget.once('event', expectedHandler1);
eventTarget.once('event', expectedHandler2);

eventTarget.emit('event');

sinon.assert.notCalled(unexpectedHandler);
sinon.assert.calledOnce(expectedHandler1);
sinon.assert.calledOnce(expectedHandler2);
sinon.assert.callOrder(expectedHandler1, expectedHandler2);
});

test('correctly passes parameters', function() {
var handler = sinon.stub();

eventTarget.once('event', handler);
eventTarget.emit('event');

sinon.assert.calledOnce(handler);
sinon.assert.calledWithExactly(handler, undefined);

eventTarget.once('event', handler);
eventTarget.emit('event', { a: 'b' });

sinon.assert.calledTwice(handler);
sinon.assert.calledWithExactly(handler, { a: 'b' });
});

suite('with allowed events >', function() {
test('throws if event name is not allowed', function() {
assert.throws(() => restrictedEventTarget.once('event'));
});

test('successfully registers handler for allowed event', function() {
var expectedHandler = sinon.stub(),
unexpectedHandler = sinon.stub();

restrictedEventTarget.once('allowed-event-2', unexpectedHandler);
restrictedEventTarget.once('allowed-event-1', expectedHandler);

restrictedEventTarget.emit('allowed-event-1');
sinon.assert.calledOnce(expectedHandler);

// Should not call handler more than once.
restrictedEventTarget.emit('allowed-event-1');
sinon.assert.calledOnce(expectedHandler);
sinon.assert.notCalled(unexpectedHandler);
});
});
});

suite('off >', function() {
test('throws if event name is not valid string', function() {
assert.throws(() => eventTarget.off());
Expand Down
27 changes: 20 additions & 7 deletions apps/sms/build/build.js
Expand Up @@ -13,13 +13,26 @@ function removeDesktopOnlyFolder(appStageDir) {
}

function removeDesktopOnlyScripts(appStageDir) {
var indexFile = utils.getFile(appStageDir, 'index.html');
var desktopOnlyScriptsRegex = /<script.+desktop\-mock.+<\/script>/g;

utils.writeContent(
indexFile,
utils.getFileContent(indexFile).replace(desktopOnlyScriptsRegex, '')
);
// Picking every file specifically since we may have "index.html" files from
// a bunch of places we don't want process to (shared, node modules, bower..).
[
'index.html',
'views/inbox/index.html',
'views/conversation/index.html'
].forEach((indexFilePath) => {
var indexFile = utils.getFile(appStageDir, indexFilePath);
var indexDocument = utils.getDocument(utils.getFileContent(indexFile));

var mockScripts = indexDocument.querySelectorAll(
'script[src*="desktop-mock"]'
);

for (var mockScript of mockScripts) {
mockScript.remove();
}

utils.writeContent(indexFile, utils.serializeDocument(indexDocument));
});
}

exports.execute = function(options) {
Expand Down
4 changes: 2 additions & 2 deletions apps/sms/desktop-mock/navigator_moz_contacts.js
Expand Up @@ -156,8 +156,8 @@
var cid = 0;
var methods = {
contains: 'startsWith',
match: 'contains',
equals: 'contains'
match: 'includes',
equals: 'includes'
};

function isMatch(contact, filter) {
Expand Down
13 changes: 11 additions & 2 deletions apps/sms/test/marionette/lib/views/inbox/accessors.js
Expand Up @@ -4,9 +4,10 @@

var SELECTORS = Object.freeze({
main: '#thread-list',
firstConversation: '.threadlist-item',
conversation: '.threadlist-item',
smsConversation: '.threadlist-item[data-last-message-type="sms"]',
mmsConversation: '.threadlist-item[data-last-message-type="mms"]',
conversationTitle: '.threadlist-item-title',
navigateToComposerHeaderButton: '#threads-composer-link'
});

Expand All @@ -16,7 +17,7 @@ function InboxAccessor(client) {

InboxAccessor.prototype = {
get firstConversation() {
return this.client.helper.waitForElement(SELECTORS.firstConversation);
return this.client.helper.waitForElement(SELECTORS.conversation);
},

get smsConversation() {
Expand All @@ -27,12 +28,20 @@ InboxAccessor.prototype = {
return this.client.helper.waitForElement(SELECTORS.mmsConversation);
},

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

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

getConversationTitle: function(conversation) {
return conversation.findElement(SELECTORS.conversationTitle);
},

waitToAppear: function() {
return this.client.helper.waitForElement(SELECTORS.main);
},
Expand Down
37 changes: 24 additions & 13 deletions apps/sms/test/marionette/lib/views/inbox/view.js
Expand Up @@ -9,20 +9,31 @@ function InboxView(client) {
this.accessors = new InboxAccessor(client);
}

InboxView.prototype.goToFirstThread = function() {
this.accessors.firstConversation.tap();
var ConversationView = require('../conversation/view');
var conversation = new ConversationView(this.client);
conversation.accessors.waitToAppear();
return conversation;
};
InboxView.prototype = {
get conversations() {
return this.accessors.conversations.map(function(conversation) {
return {
lastMessageType: conversation.getAttribute('data-last-message-type'),
title: this.accessors.getConversationTitle(conversation).text()
};
}, this);
},

goToFirstThread: function() {
this.accessors.firstConversation.tap();
var ConversationView = require('../conversation/view');
var conversation = new ConversationView(this.client);
conversation.accessors.waitToAppear();
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;
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;
70 changes: 70 additions & 0 deletions apps/sms/test/marionette/notification_test.js
Expand Up @@ -5,6 +5,7 @@ var assert = require('chai').assert;

var Messages = require('./lib/messages.js');
var Storage = require('./lib/storage.js');
var InboxView = require('./lib/views/inbox/view');
var UtilityTray = require('../../../system/test/marionette/lib/utility_tray');
var NotificationList = require(
'../../../system/test/marionette/lib/notification.js'
Expand Down Expand Up @@ -67,6 +68,41 @@ marionette('Message notification tests', function() {
messagesApp.switchTo();
}

function removeNotification() {
client.switchToFrame();
notificationList.waitForNotificationCount(1);

utilityTray.open();
utilityTray.waitForOpened();

// Make sure we have our notification to remove.
notificationList.refresh();

var notificationNode = client.helper.waitForElement(
notificationList.getForApp(messagesApp.manifestURL)[0].query
);

// flick() sends a sequence of touch events that allows us to simulate
// swipe from left (x1=5) to right (x2=125) within 100ms period of time.
client.loader.getActions().flick(
notificationNode, 5, 15, 125, 15, 100
).perform();

utilityTray.close();
utilityTray.waitForClosed();

// Switch to messages so that it's able to remove notification.
messagesApp.launch();
messagesApp.switchTo();
storage.setMessagesStorage(messagesStorage);

// Verify that notification has been removed.
client.switchToFrame();
notificationList.waitForNotificationCount(0);

messagesApp.switchTo();
}

function assertMessagesIsInCorrectState() {
// Verify that we entered the right thread
var message = messagesApp.Conversation.message;
Expand Down Expand Up @@ -155,5 +191,39 @@ marionette('Message notification tests', function() {

assertMessagesIsInCorrectState();
});

test('when user removes notification from Utility tray', function() {
// Receive 'sms-received' system message and generate notification.
messagesApp.sendSystemMessage('sms-received', smsMessage);

// We should make Messages app visible, otherwise switchToApp won't work.
messagesApp.launch();
storage.setMessagesStorage(messagesStorage);

// Switch to system app to be sure that notification is generated.
client.switchToFrame();
notificationList.waitForNotificationCount(1);

// Close Message app since we want to run fresh instance.
messagesApp.close();

removeNotification();

// When notication is removed Messages is run to handle corresponding
// system message, in this case app should be in valid state i.e. it
// should have correctly initialized inbox view.
var inboxView = new InboxView(client);
var conversations = inboxView.conversations;

assert.equal(conversations.length, 1);
assert.equal(conversations[0].title, smsMessage.sender);

// Let's make sure that we still can receive new messages.
messagesApp.sendSystemMessage('sms-received', smsMessage);

openNotification();

assertMessagesIsInCorrectState();
});
});
});

0 comments on commit 70c9bee

Please sign in to comment.