mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1132301: Part 5 - add unit tests for the Social Sharing feature of Loop. r=Standard8
This commit is contained in:
parent
d1013e867f
commit
e6dca9bd6b
@ -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);
|
||||
|
||||
|
@ -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: []
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -34,7 +34,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 = {
|
||||
@ -277,7 +279,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)));
|
||||
});
|
||||
|
||||
@ -413,7 +417,9 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
roomName: "Its a room",
|
||||
roomOwner: "Me",
|
||||
roomToken: "fakeToken",
|
||||
roomUrl: "http://invalid"
|
||||
roomUrl: "http://invalid",
|
||||
socialShareButtonAvailable: false,
|
||||
socialShareProviders: []
|
||||
};
|
||||
});
|
||||
|
||||
@ -431,6 +437,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([]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -455,6 +463,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"});
|
||||
@ -1094,6 +1127,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() {
|
||||
@ -1101,7 +1154,9 @@ describe("loop.store.ActiveRoomStore", function () {
|
||||
roomName: "Its a room",
|
||||
roomOwner: "Me",
|
||||
roomToken: "fakeToken",
|
||||
roomUrl: "http://invalid"
|
||||
roomUrl: "http://invalid",
|
||||
socialShareButtonAvailable: false,
|
||||
socialShareProviders: []
|
||||
}));
|
||||
});
|
||||
|
||||
@ -1131,7 +1186,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() {
|
||||
|
@ -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, "", "");
|
||||
});
|
||||
|
||||
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, "", 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});
|
||||
|
Loading…
Reference in New Issue
Block a user