+'use strict';
+
+describe('crmCaseType', function() {
+
+ beforeEach(function() {
+ CRM.resourceUrls = {
+ 'civicrm': ''
+ };
+ CRM.crmCaseType = {
+ 'REL_TYPE_CNAME': 'label_b_a'
+ };
+ module('crmCaseType');
+ module('crmJsonComparitor');
+ inject(function(crmJsonComparitor) {
+ crmJsonComparitor.register(jasmine);
+ });
+ });
+
+ describe('CaseTypeCtrl', function() {
+ var apiCalls;
+ var ctrl;
+ var compile;
+ var $httpBackend;
+ var scope;
+ var timeout;
+
+ beforeEach(inject(function(_$httpBackend_, $rootScope, $controller, $compile, $timeout) {
+ $httpBackend = _$httpBackend_;
+ scope = $rootScope.$new();
+ compile = $compile;
+ timeout = $timeout;
+ apiCalls = {
+ 'actStatuses': {
+ 'values': {
+ "272": {
+ "id": "272",
+ "option_group_id": "25",
+ "label": "Scheduled",
+ "value": "1",
+ "name": "Scheduled",
+ "filter": "0",
+ "is_default": "1",
+ "weight": "1",
+ "is_optgroup": "0",
+ "is_reserved": "1",
+ "is_active": "1"
+ },
+ "273": {
+ "id": "273",
+ "option_group_id": "25",
+ "label": "Completed",
+ "value": "2",
+ "name": "Completed",
+ "filter": "0",
+ "weight": "2",
+ "is_optgroup": "0",
+ "is_reserved": "1",
+ "is_active": "1"
+ }
+ }
+ },
+ 'actTypes': {
+ 'values': {
+ "784": {
+ "id": "784",
+ "option_group_id": "2",
+ "label": "ADC referral",
+ "value": "62",
+ "name": "ADC referral",
+ "filter": "0",
+ "is_default": "0",
+ "weight": "64",
+ "is_optgroup": "0",
+ "is_reserved": "0",
+ "is_active": "1",
+ "component_id": "7"
+ },
+ "32": {
+ "id": "32",
+ "option_group_id": "2",
+ "label": "Add Client To Case",
+ "value": "27",
+ "name": "Add Client To Case",
+ "filter": "0",
+ "is_default": "0",
+ "weight": "26",
+ "description": "",
+ "is_optgroup": "0",
+ "is_reserved": "1",
+ "is_active": "1",
+ "component_id": "7"
+ }
+ }
+ },
+ 'relTypes': {
+ 'values' : {
+ "14": {
+ "id": "14",
+ "name_a_b": "Benefits Specialist is",
+ "label_a_b": "Benefits Specialist is",
+ "name_b_a": "Benefits Specialist",
+ "label_b_a": "Benefits Specialist",
+ "description": "Benefits Specialist",
+ "contact_type_a": "Individual",
+ "contact_type_b": "Individual",
+ "is_reserved": "0",
+ "is_active": "1"
+ },
+ "9": {
+ "id": "9",
+ "name_a_b": "Case Coordinator is",
+ "label_a_b": "Case Coordinator is",
+ "name_b_a": "Case Coordinator",
+ "label_b_a": "Case Coordinator",
+ "description": "Case Coordinator",
+ "contact_type_a": "Individual",
+ "contact_type_b": "Individual",
+ "is_reserved": "0",
+ "is_active": "1"
+ }
+ }
+ },
+ "caseType": {
+ "id": "1",
+ "name": "housing_support",
+ "title": "Housing Support",
+ "description": "Help homeless individuals obtain temporary and long-term housing",
+ "is_active": "1",
+ "is_reserved": "0",
+ "weight": "1",
+ "is_forkable": "1",
+ "is_forked": "",
+ "definition": {
+ "activityTypes": [
+ {"name": "Open Case", "max_instances": "1"}
+ ],
+ "activitySets": [
+ {
+ "name": "standard_timeline",
+ "label": "Standard Timeline",
+ "timeline": "1",
+ "activityTypes": [
+ {
+ "name": "Open Case",
+ "status": "Completed"
+ },
+ {
+ "name": "Medical evaluation",
+ "reference_activity": "Open Case",
+ "reference_offset": "1",
+ "reference_select": "newest"
+ }
+ ]
+ }
+ ],
+ "caseRoles": [
+ {
+ "name": "Homeless Services Coordinator",
+ "creator": "1",
+ "manager": "1"
+ }
+ ]
+ }
+ }
+ };
+ ctrl = $controller('CaseTypeCtrl', {$scope: scope, apiCalls: apiCalls});
+ }));
+
+ it('should load activity statuses', function() {
+ expect(scope.activityStatuses).toEqualData([apiCalls['actStatuses']['values']['272'], apiCalls['actStatuses']['values']['273']]);
+ });
+
+ it('should load activity types', function() {
+ expect(scope.activityTypes).toEqualData(apiCalls['actTypes']['values']);
+ });
+
+ it('addActivitySet should add an activitySet to the case type', function() {
+ scope.addActivitySet('timeline');
+ var activitySets = scope.caseType.definition.activitySets;
+ var newSet = activitySets[activitySets.length - 1];
+ expect(newSet.name).toBe('timeline_1');
+ expect(newSet.timeline).toBe('1');
+ expect(newSet.label).toBe('Timeline');
+ });
+
+ it('addActivitySet handles second timeline correctly', function() {
+ scope.addActivitySet('timeline');
+ scope.addActivitySet('timeline');
+ var activitySets = scope.caseType.definition.activitySets;
+ var newSet = activitySets[activitySets.length - 1];
+ expect(newSet.name).toBe('timeline_2');
+ expect(newSet.timeline).toBe('1');
+ expect(newSet.label).toBe('Timeline #2');
+ });
+
+ });
+});