fix(client): Copy inbox messages to tasks

fixes #7017
closes #6994
This commit is contained in:
Blade Barringer 2016-09-12 08:01:50 -05:00
parent ed702a437d
commit 9d537d93d8
5 changed files with 110 additions and 2 deletions

View file

@ -125,6 +125,8 @@
"copyMessageAsToDo": "Copy message as To-Do",
"messageAddedAsToDo": "Message copied as To-Do.",
"messageWroteIn": "<%= user %> wrote in <%= group %>",
"taskFromInbox": "<%= from %> wrote '<%= message %>'",
"taskTextFromInbox": "Message from <%= from %>",
"msgPreviewHeading": "Message Preview",
"leaderOnlyChallenges": "Only group leader can create challenges",
"sendGift": "Send Gift",

View file

@ -0,0 +1,73 @@
'use strict';
describe('inbox Controller', function() {
var scope, ctrl, user, $rootScope, $controller;
beforeEach(function() {
module(function($provide) {
$provide.value('User', {});
});
inject(function(_$rootScope_, _$controller_){
user = specHelper.newUser();
user._id = 'unique-user-id';
$rootScope = _$rootScope_;
scope = _$rootScope_.$new();
$controller = _$controller_;
// Load RootCtrl to ensure shared behaviors are loaded
$controller('RootCtrl', {$scope: scope, User: {user: user}});
ctrl = $controller('InboxCtrl', {$scope: scope});
});
});
describe('copyToDo', function() {
it('when copying a user message it opens modal with information from message', function() {
scope.group = {
name: 'Princess Bride'
};
sandbox.spy($rootScope, 'openModal');
var message = {
uuid: 'the-dread-pirate-roberts',
user: 'Wesley',
text: 'As you wish'
};
scope.copyToDo(message);
expect($rootScope.openModal).to.be.calledOnce;
expect($rootScope.openModal).to.be.calledWith('copyChatToDo', sinon.match(function(callArgToMatch){
var taskText = env.t('taskTextFromInbox', {
from: message.user
});
return callArgToMatch.controller == 'CopyMessageModalCtrl'
&& callArgToMatch.scope.text == taskText
}));
});
it('when copying a system message it opens modal with information from message', function() {
var modalSpy = sandbox.spy($rootScope, 'openModal');
var message = {
uuid: 'system',
text: 'Wesley attacked the ROUS in the Fire Swamp'
};
scope.copyToDo(message);
modalSpy.should.have.been.calledOnce;
modalSpy.should.have.been.calledWith('copyChatToDo', sinon.match(function(callArgToMatch){
var taskText = env.t('taskTextFromInbox', {
from: 'system'
});
return callArgToMatch.controller == 'CopyMessageModalCtrl'
&& callArgToMatch.scope.text == taskText
}));
});
});
});

View file

@ -97,8 +97,9 @@ window.habitrpg = angular.module('habitrpg',
})
.state('options.social.inbox', {
url: "/inbox",
templateUrl: "partials/options.social.inbox.html",
url: '/inbox',
templateUrl: 'partials/options.social.inbox.html',
controller: 'InboxCtrl',
title: env.t('titleInbox')
})

View file

@ -0,0 +1,31 @@
'use strict';
habitrpg.controller('InboxCtrl', ['$scope', '$rootScope',
function ($scope, $rootScope) {
$scope.copyToDo = function (message) {
var messageUser;
if (message.uuid == 'system') {
messageUser = 'system';
} else {
messageUser = message.user;
}
var newScope = $scope.$new();
newScope.notes = env.t('taskFromInbox', {
from: messageUser,
message: message.text
});
newScope.text = env.t('taskTextFromInbox', {
from: messageUser
});
$rootScope.openModal('copyChatToDo',{
controller: 'CopyMessageModalCtrl',
scope: newScope
});
};
}
]);

View file

@ -90,6 +90,7 @@
"js/controllers/guildsCtrl.js",
"js/controllers/hallCtrl.js",
"js/controllers/headerCtrl.js",
"js/controllers/inboxCtrl.js",
"js/controllers/inventoryCtrl.js",
"js/controllers/inviteToGroupCtrl.js",
"js/controllers/memberModalCtrl.js",