mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Move chat controller to own spec file
This commit is contained in:
72
test/spec/controllers/chatCtrlSpec.js
Normal file
72
test/spec/controllers/chatCtrlSpec.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe("Chat 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('ChatCtrl', {$scope: scope});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('copyToDo', function() {
|
||||||
|
it('when copying a user message it opens modal with information from message', function() {
|
||||||
|
scope.group = {
|
||||||
|
name: "Princess Bride"
|
||||||
|
};
|
||||||
|
|
||||||
|
var modalSpy = sandbox.spy($rootScope, "openModal");
|
||||||
|
var message = {
|
||||||
|
uuid: 'the-dread-pirate-roberts',
|
||||||
|
user: 'Wesley',
|
||||||
|
text: 'As you wish'
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.copyToDo(message);
|
||||||
|
|
||||||
|
modalSpy.should.have.been.calledOnce;
|
||||||
|
|
||||||
|
modalSpy.should.have.been.calledWith('copyChatToDo', sinon.match(function(callArgToMatch){
|
||||||
|
return callArgToMatch.controller == 'CopyMessageModalCtrl'
|
||||||
|
&& callArgToMatch.scope.text == message.text
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('when copying a system message it opens modal with information from message', function() {
|
||||||
|
scope.group = {
|
||||||
|
name: "Princess Bride"
|
||||||
|
};
|
||||||
|
|
||||||
|
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){
|
||||||
|
return callArgToMatch.controller == 'CopyMessageModalCtrl'
|
||||||
|
&& callArgToMatch.scope.text == message.text
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
@@ -72,76 +72,6 @@ describe('Groups Controller', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Chat 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('ChatCtrl', {$scope: scope});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('copyToDo', function() {
|
|
||||||
it('when copying a user message it opens modal with information from message', function() {
|
|
||||||
scope.group = {
|
|
||||||
name: "Princess Bride"
|
|
||||||
};
|
|
||||||
|
|
||||||
var modalSpy = sandbox.spy($rootScope, "openModal");
|
|
||||||
var message = {
|
|
||||||
uuid: 'the-dread-pirate-roberts',
|
|
||||||
user: 'Wesley',
|
|
||||||
text: 'As you wish'
|
|
||||||
};
|
|
||||||
|
|
||||||
scope.copyToDo(message);
|
|
||||||
|
|
||||||
modalSpy.should.have.been.calledOnce;
|
|
||||||
|
|
||||||
modalSpy.should.have.been.calledWith('copyChatToDo', sinon.match(function(callArgToMatch){
|
|
||||||
return callArgToMatch.controller == 'CopyMessageModalCtrl'
|
|
||||||
&& callArgToMatch.scope.text == message.text
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('when copying a system message it opens modal with information from message', function() {
|
|
||||||
scope.group = {
|
|
||||||
name: "Princess Bride"
|
|
||||||
};
|
|
||||||
|
|
||||||
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){
|
|
||||||
return callArgToMatch.controller == 'CopyMessageModalCtrl'
|
|
||||||
&& callArgToMatch.scope.text == message.text
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Autocomplete controller", function() {
|
describe("Autocomplete controller", function() {
|
||||||
var scope, ctrl, user, $rootScope, $controller;
|
var scope, ctrl, user, $rootScope, $controller;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user