mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Final adjustments to PR #5114
* Added test for header ctrl * Made openModal function more readable * Only show setting to disable invite friends if party is exactly 1 member big * Use party.memberCount instead of party.members.length because it's more expressive
This commit is contained in:
56
test/spec/headerCtrlSpec.js
Normal file
56
test/spec/headerCtrlSpec.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Header Controller', function() {
|
||||||
|
var scope, ctrl, user, $location, $rootScope;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
module(function($provide) {
|
||||||
|
$provide.value('User', {});
|
||||||
|
});
|
||||||
|
|
||||||
|
inject(function(_$rootScope_, _$controller_, _$location_){
|
||||||
|
user = specHelper.newUser();
|
||||||
|
user._id = "unique-user-id"
|
||||||
|
|
||||||
|
scope = _$rootScope_.$new();
|
||||||
|
$rootScope = _$rootScope_;
|
||||||
|
|
||||||
|
$location = _$location_;
|
||||||
|
|
||||||
|
// Load RootCtrl to ensure shared behaviors are loaded
|
||||||
|
_$controller_('RootCtrl', {$scope: scope, User: {user: user}});
|
||||||
|
|
||||||
|
ctrl = _$controller_('HeaderCtrl', {$scope: scope, User: {user: user}});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
context('inviteOrStartParty', function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
sinon.stub($location, 'path');
|
||||||
|
sinon.stub($rootScope, 'openModal');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function(){
|
||||||
|
$location.path.restore();
|
||||||
|
$rootScope.openModal.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('redirects to party page if user does not have a party', function(){
|
||||||
|
var group = {};
|
||||||
|
scope.inviteOrStartParty(group);
|
||||||
|
|
||||||
|
expect($location.path).to.be.calledWith("/options/groups/party");
|
||||||
|
expect($rootScope.openModal).to.not.be.called;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Opens invite-friends modal if user has a party', function(){
|
||||||
|
var group = {
|
||||||
|
type: 'party'
|
||||||
|
};
|
||||||
|
scope.inviteOrStartParty(group);
|
||||||
|
|
||||||
|
expect($rootScope.openModal).to.be.calledOnce;
|
||||||
|
expect($location.path).to.not.be.called;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -18,10 +18,12 @@ habitrpg.controller("HeaderCtrl", ['$scope', 'Groups', 'User', '$location', '$ro
|
|||||||
|
|
||||||
$scope.inviteOrStartParty = function(group) {
|
$scope.inviteOrStartParty = function(group) {
|
||||||
if (group.type === "party") {
|
if (group.type === "party") {
|
||||||
$rootScope.openModal('invite-friends', {controller:'InviteToGroupCtrl', resolve:
|
$rootScope.openModal('invite-friends', {
|
||||||
{injectedGroup: function(){
|
controller:'InviteToGroupCtrl',
|
||||||
return group;
|
resolve: {
|
||||||
}}});
|
injectedGroup: function(){ return group; }
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
$location.path("/options/groups/party");
|
$location.path("/options/groups/party");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ script(type='text/ng-template', id='partials/options.settings.settings.html')
|
|||||||
label
|
label
|
||||||
input(type='checkbox', ng-model='user.preferences.dailyDueDefaultView', ng-change='set({"preferences.dailyDueDefaultView": user.preferences.dailyDueDefaultView?true: false})')
|
input(type='checkbox', ng-model='user.preferences.dailyDueDefaultView', ng-change='set({"preferences.dailyDueDefaultView": user.preferences.dailyDueDefaultView?true: false})')
|
||||||
span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('dailyDueDefaultViewPop'))=env.t('dailyDueDefaultView')
|
span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('dailyDueDefaultViewPop'))=env.t('dailyDueDefaultView')
|
||||||
.checkbox
|
.checkbox(ng-if='party.memberCount === 1')
|
||||||
label
|
label
|
||||||
input(type='checkbox', ng-model='user.preferences.displayInviteToPartyWhenPartyIs1', ng-change='set({"preferences.displayInviteToPartyWhenPartyIs1": user.preferences.displayInviteToPartyWhenPartyIs1 ? true : false})')
|
input(type='checkbox', ng-model='user.preferences.displayInviteToPartyWhenPartyIs1', ng-change='set({"preferences.displayInviteToPartyWhenPartyIs1": user.preferences.displayInviteToPartyWhenPartyIs1 ? true : false})')
|
||||||
span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('displayInviteToPartyWhenPartyIs1'))=env.t('displayInviteToPartyWhenPartyIs1')
|
span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('displayInviteToPartyWhenPartyIs1'))=env.t('displayInviteToPartyWhenPartyIs1')
|
||||||
|
|||||||
@@ -32,7 +32,8 @@
|
|||||||
|
|
||||||
// party
|
// party
|
||||||
span(ng-controller='PartyCtrl')
|
span(ng-controller='PartyCtrl')
|
||||||
button.party-invite.pull-right.btn.btn-primary(ng-click="inviteOrStartParty(group)", ng-if="(!party.members) && user.preferences.displayInviteToPartyWhenPartyIs1", popover=env.t("startAParty"), popover-placement="top", popover-trigger="mouseenter")=env.t("inviteFriends")
|
button.party-invite.pull-right.btn.btn-primary(ng-click="inviteOrStartParty(group)",
|
||||||
button.party-invite.pull-right.btn.btn-primary(ng-click="inviteOrStartParty(group)", ng-if="(party.members.length === 1) && user.preferences.displayInviteToPartyWhenPartyIs1", popover=env.t("addToParty"), popover-placement="top", popover-trigger="mouseenter")=env.t("inviteFriends")
|
ng-if="(!party.members || party.memberCount === 1) && user.preferences.displayInviteToPartyWhenPartyIs1",
|
||||||
|
popover="{{!party.members ? env.t('startAParty') : env.t('addToParty')}}", popover-placement="left", popover-trigger="mouseenter")=env.t("inviteFriends")
|
||||||
.herobox-wrap(ng-repeat='profile in partyMinusSelf')
|
.herobox-wrap(ng-repeat='profile in partyMinusSelf')
|
||||||
+herobox()
|
+herobox()
|
||||||
|
|||||||
Reference in New Issue
Block a user