mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-29 21:25:35 +00:00
Bug 1132301: Part 5 - add unit tests for the Social Sharing feature of Loop. r=Standard8
This commit is contained in:
parent
4af1cb9e83
commit
a0b093aab1
@ -29,7 +29,8 @@ describe("loop.panel", function() {
|
||||
fakeWindow = {
|
||||
close: sandbox.stub(),
|
||||
addEventListener: function() {},
|
||||
document: { addEventListener: function(){} }
|
||||
document: { addEventListener: function(){} },
|
||||
setTimeout: function(callback) { callback(); }
|
||||
};
|
||||
loop.shared.mixins.setRootObject(fakeWindow);
|
||||
|
||||
|
@ -77,6 +77,9 @@ describe("loop.store.RoomStore", function () {
|
||||
beforeEach(function() {
|
||||
fakeMozLoop = {
|
||||
copyString: function() {},
|
||||
getLoopPref: function(pref) {
|
||||
return pref;
|
||||
},
|
||||
notifyUITour: function() {},
|
||||
rooms: {
|
||||
create: function() {},
|
||||
@ -368,6 +371,62 @@ describe("loop.store.RoomStore", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#shareRoomUrl", function() {
|
||||
beforeEach(function() {
|
||||
fakeMozLoop.socialShareRoom = sinon.stub();
|
||||
});
|
||||
|
||||
it("should pass the correct data for GMail sharing", function() {
|
||||
var roomUrl = "http://invalid";
|
||||
var origin = "https://mail.google.com/v1";
|
||||
store.shareRoomUrl(new sharedActions.ShareRoomUrl({
|
||||
roomUrl: roomUrl,
|
||||
provider: {
|
||||
origin: origin
|
||||
}
|
||||
}));
|
||||
|
||||
sinon.assert.calledOnce(fakeMozLoop.socialShareRoom);
|
||||
sinon.assert.calledWithExactly(fakeMozLoop.socialShareRoom, origin,
|
||||
roomUrl, "share_tweet", "share_email_body5");
|
||||
});
|
||||
|
||||
it("should pass the correct data for all other Social Providers", function() {
|
||||
var roomUrl = "http://invalid2";
|
||||
var origin = "https://twitter.com/share";
|
||||
store.shareRoomUrl(new sharedActions.ShareRoomUrl({
|
||||
roomUrl: roomUrl,
|
||||
provider: {
|
||||
origin: origin
|
||||
}
|
||||
}));
|
||||
|
||||
sinon.assert.calledOnce(fakeMozLoop.socialShareRoom);
|
||||
sinon.assert.calledWithExactly(fakeMozLoop.socialShareRoom, origin,
|
||||
roomUrl, "share_tweet", null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addSocialShareButton", function() {
|
||||
it("should invoke to the correct mozLoop function", function() {
|
||||
fakeMozLoop.addSocialShareButton = sinon.stub();
|
||||
|
||||
store.addSocialShareButton(new sharedActions.AddSocialShareButton());
|
||||
|
||||
sinon.assert.calledOnce(fakeMozLoop.addSocialShareButton);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addSocialShareProvider", function() {
|
||||
it("should invoke to the correct mozLoop function", function() {
|
||||
fakeMozLoop.addSocialShareProvider = sinon.stub();
|
||||
|
||||
store.addSocialShareProvider(new sharedActions.AddSocialShareProvider());
|
||||
|
||||
sinon.assert.calledOnce(fakeMozLoop.addSocialShareProvider);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setStoreState", function() {
|
||||
it("should update store state data", function() {
|
||||
store.setStoreState({pendingCreation: true});
|
||||
|
@ -18,7 +18,8 @@ describe("loop.roomViews", function () {
|
||||
|
||||
fakeMozLoop = {
|
||||
getAudioBlob: sinon.stub(),
|
||||
getLoopPref: sinon.stub()
|
||||
getLoopPref: sinon.stub(),
|
||||
isSocialShareButtonAvailable: sinon.stub()
|
||||
};
|
||||
|
||||
fakeWindow = {
|
||||
@ -28,7 +29,8 @@ describe("loop.roomViews", function () {
|
||||
mozLoop: fakeMozLoop
|
||||
},
|
||||
addEventListener: function() {},
|
||||
removeEventListener: function() {}
|
||||
removeEventListener: function() {},
|
||||
setTimeout: function(callback) { callback(); }
|
||||
};
|
||||
loop.shared.mixins.setRootObject(fakeWindow);
|
||||
|
||||
@ -198,6 +200,21 @@ describe("loop.roomViews", function () {
|
||||
expect(copyBtn.textContent).eql("copied_url_button");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Share button", function() {
|
||||
beforeEach(function() {
|
||||
view = mountTestComponent();
|
||||
});
|
||||
|
||||
it("should toggle the share dropdown when the share button is clicked", function() {
|
||||
var shareBtn = view.getDOMNode().querySelector(".btn-share");
|
||||
|
||||
React.addons.TestUtils.Simulate.click(shareBtn);
|
||||
|
||||
expect(view.state.showMenu).to.eql(true);
|
||||
expect(view.refs.menu.props.show).to.eql(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DesktopRoomConversationView", function() {
|
||||
@ -433,4 +450,140 @@ describe("loop.roomViews", function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("SocialShareDropdown", function() {
|
||||
var view, fakeProvider;
|
||||
|
||||
beforeEach(function() {
|
||||
sandbox.stub(dispatcher, "dispatch");
|
||||
|
||||
fakeProvider = {
|
||||
name: "foo",
|
||||
origin: "https://foo",
|
||||
iconURL: "http://example.com/foo.png"
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
view = fakeProvider = null;
|
||||
});
|
||||
|
||||
function mountTestComponent() {
|
||||
return TestUtils.renderIntoDocument(
|
||||
React.createElement(loop.roomViews.SocialShareDropdown, {
|
||||
dispatcher: dispatcher,
|
||||
roomStore: roomStore,
|
||||
show: true
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
describe("#render", function() {
|
||||
it("should show no contents when the Social Providers have not been fetched yet", function() {
|
||||
view = mountTestComponent();
|
||||
|
||||
expect(view.getDOMNode()).to.eql(null);
|
||||
});
|
||||
|
||||
it("should show different contents when the Share XUL button is not available", function() {
|
||||
activeRoomStore.setStoreState({
|
||||
socialShareProviders: []
|
||||
});
|
||||
view = mountTestComponent();
|
||||
|
||||
var node = view.getDOMNode();
|
||||
expect(node.querySelector(".share-panel-header")).to.not.eql(null);
|
||||
});
|
||||
|
||||
it("should show an empty list when no Social Providers are available", function() {
|
||||
activeRoomStore.setStoreState({
|
||||
socialShareButtonAvailable: true,
|
||||
socialShareProviders: []
|
||||
});
|
||||
|
||||
view = mountTestComponent();
|
||||
|
||||
var node = view.getDOMNode();
|
||||
expect(node.querySelector(".icon-add-share-service")).to.not.eql(null);
|
||||
expect(node.querySelectorAll(".dropdown-menu-item").length).to.eql(1);
|
||||
});
|
||||
|
||||
it("should show a list of available Social Providers", function() {
|
||||
activeRoomStore.setStoreState({
|
||||
socialShareButtonAvailable: true,
|
||||
socialShareProviders: [fakeProvider]
|
||||
});
|
||||
|
||||
view = mountTestComponent();
|
||||
|
||||
var node = view.getDOMNode();
|
||||
expect(node.querySelector(".icon-add-share-service")).to.not.eql(null);
|
||||
expect(node.querySelector(".dropdown-menu-separator")).to.not.eql(null);
|
||||
|
||||
var dropdownNodes = node.querySelectorAll(".dropdown-menu-item");
|
||||
expect(dropdownNodes.length).to.eql(2);
|
||||
expect(dropdownNodes[1].querySelector("img").src).to.eql(fakeProvider.iconURL);
|
||||
expect(dropdownNodes[1].querySelector("span").textContent)
|
||||
.to.eql(fakeProvider.name);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#handleToolbarAddButtonClick", function() {
|
||||
it("should dispatch an action when the 'add to toolbar' button is clicked", function() {
|
||||
activeRoomStore.setStoreState({
|
||||
socialShareProviders: []
|
||||
});
|
||||
|
||||
view = mountTestComponent();
|
||||
|
||||
var addButton = view.getDOMNode().querySelector(".btn-toolbar-add");
|
||||
React.addons.TestUtils.Simulate.click(addButton);
|
||||
|
||||
sinon.assert.calledOnce(dispatcher.dispatch);
|
||||
sinon.assert.calledWithExactly(dispatcher.dispatch,
|
||||
new sharedActions.AddSocialShareButton());
|
||||
});
|
||||
});
|
||||
|
||||
describe("#handleAddServiceClick", function() {
|
||||
it("should dispatch an action when the 'add provider' item is clicked", function() {
|
||||
activeRoomStore.setStoreState({
|
||||
socialShareProviders: [],
|
||||
socialShareButtonAvailable: true
|
||||
});
|
||||
|
||||
view = mountTestComponent();
|
||||
|
||||
var addItem = view.getDOMNode().querySelector(".dropdown-menu-item:first-child");
|
||||
React.addons.TestUtils.Simulate.click(addItem);
|
||||
|
||||
sinon.assert.calledOnce(dispatcher.dispatch);
|
||||
sinon.assert.calledWithExactly(dispatcher.dispatch,
|
||||
new sharedActions.AddSocialShareProvider());
|
||||
});
|
||||
});
|
||||
|
||||
describe("#handleProviderClick", function() {
|
||||
it("should dispatch an action when a provider item is clicked", function() {
|
||||
activeRoomStore.setStoreState({
|
||||
roomUrl: "http://example.com",
|
||||
socialShareButtonAvailable: true,
|
||||
socialShareProviders: [fakeProvider]
|
||||
});
|
||||
|
||||
view = mountTestComponent();
|
||||
|
||||
var providerItem = view.getDOMNode().querySelector(".dropdown-menu-item:last-child");
|
||||
React.addons.TestUtils.Simulate.click(providerItem);
|
||||
|
||||
sinon.assert.calledOnce(dispatcher.dispatch);
|
||||
sinon.assert.calledWithExactly(dispatcher.dispatch,
|
||||
new sharedActions.ShareRoomUrl({
|
||||
provider: fakeProvider,
|
||||
roomUrl: activeRoomStore.getStoreState().roomUrl,
|
||||
previews: []
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -35,7 +35,9 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
off: sinon.stub()
|
||||
},
|
||||
setScreenShareState: sinon.stub(),
|
||||
getActiveTabWindowId: sandbox.stub().callsArgWith(0, null, 42)
|
||||
getActiveTabWindowId: sandbox.stub().callsArgWith(0, null, 42),
|
||||
isSocialShareButtonAvailable: sinon.stub().returns(false),
|
||||
getSocialShareProviders: sinon.stub().returns([])
|
||||
};
|
||||
|
||||
fakeSdkDriver = {
|
||||
@ -278,7 +280,9 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
sinon.assert.calledTwice(dispatcher.dispatch);
|
||||
sinon.assert.calledWithExactly(dispatcher.dispatch,
|
||||
new sharedActions.SetupRoomInfo(_.extend({
|
||||
roomToken: fakeToken
|
||||
roomToken: fakeToken,
|
||||
socialShareButtonAvailable: false,
|
||||
socialShareProviders: []
|
||||
}, fakeRoomData)));
|
||||
});
|
||||
|
||||
@ -521,7 +525,9 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
roomName: "Its a room",
|
||||
roomOwner: "Me",
|
||||
roomToken: "fakeToken",
|
||||
roomUrl: "http://invalid"
|
||||
roomUrl: "http://invalid",
|
||||
socialShareButtonAvailable: false,
|
||||
socialShareProviders: []
|
||||
};
|
||||
});
|
||||
|
||||
@ -539,6 +545,8 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
expect(state.roomOwner).eql(fakeRoomInfo.roomOwner);
|
||||
expect(state.roomToken).eql(fakeRoomInfo.roomToken);
|
||||
expect(state.roomUrl).eql(fakeRoomInfo.roomUrl);
|
||||
expect(state.socialShareButtonAvailable).eql(false);
|
||||
expect(state.socialShareProviders).eql([]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -563,6 +571,31 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#updateSocialShareInfo", function() {
|
||||
var fakeSocialShareInfo;
|
||||
|
||||
beforeEach(function() {
|
||||
fakeSocialShareInfo = {
|
||||
socialShareButtonAvailable: true,
|
||||
socialShareProviders: [{
|
||||
name: "foo",
|
||||
origin: "https://example.com",
|
||||
iconURL: "icon.png"
|
||||
}]
|
||||
};
|
||||
});
|
||||
|
||||
it("should save the Social API information", function() {
|
||||
store.updateSocialShareInfo(new sharedActions.UpdateSocialShareInfo(fakeSocialShareInfo));
|
||||
|
||||
var state = store.getStoreState();
|
||||
expect(state.socialShareButtonAvailable)
|
||||
.eql(fakeSocialShareInfo.socialShareButtonAvailable);
|
||||
expect(state.socialShareProviders)
|
||||
.eql(fakeSocialShareInfo.socialShareProviders);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#joinRoom", function() {
|
||||
it("should reset failureReason", function() {
|
||||
store.setStoreState({failureReason: "Test"});
|
||||
@ -1202,6 +1235,26 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#_handleSocialShareUpdate", function() {
|
||||
it("should dispatch an UpdateRoomInfo action", function() {
|
||||
store._handleSocialShareUpdate();
|
||||
|
||||
sinon.assert.calledOnce(dispatcher.dispatch);
|
||||
sinon.assert.calledWithExactly(dispatcher.dispatch,
|
||||
new sharedActions.UpdateSocialShareInfo({
|
||||
socialShareButtonAvailable: false,
|
||||
socialShareProviders: []
|
||||
}));
|
||||
});
|
||||
|
||||
it("should call respective mozLoop methods", function() {
|
||||
store._handleSocialShareUpdate();
|
||||
|
||||
sinon.assert.calledOnce(fakeMozLoop.isSocialShareButtonAvailable);
|
||||
sinon.assert.calledOnce(fakeMozLoop.getSocialShareProviders);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Events", function() {
|
||||
describe("update:{roomToken}", function() {
|
||||
beforeEach(function() {
|
||||
@ -1209,7 +1262,9 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
roomName: "Its a room",
|
||||
roomOwner: "Me",
|
||||
roomToken: "fakeToken",
|
||||
roomUrl: "http://invalid"
|
||||
roomUrl: "http://invalid",
|
||||
socialShareButtonAvailable: false,
|
||||
socialShareProviders: []
|
||||
}));
|
||||
});
|
||||
|
||||
@ -1239,7 +1294,12 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
store.setupRoomInfo(new sharedActions.SetupRoomInfo(fakeRoomData));
|
||||
store.setupRoomInfo(new sharedActions.SetupRoomInfo(
|
||||
_.extend(fakeRoomData, {
|
||||
socialShareButtonAvailable: false,
|
||||
socialShareProviders: []
|
||||
})
|
||||
));
|
||||
});
|
||||
|
||||
it("should disconnect all room connections", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user