File size: 5,183 Bytes
7e79d67 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | 'use strict';
describe('SectionsCtrl', function() {
var ctrl,
scope,
stateParams,
rootScope,
httpBackend,
styleguideData = {
sections: {
data: [
{
header: 'Section header text',
reference: '1'
},
{
header: 'Sub section header text',
parentReference: '1',
reference: '1.1'
}
]
},
config: {
data: {
title: 'Page Title'
}
}
};
// Load the controller's module
beforeEach(angular.mock.module('sgApp'));
beforeEach(function() {
module(function($provide) {
$provide.value('Styleguide', styleguideData);
$provide.value('Variables', {
init: function() {}
});
});
});
// Initialize the controller and a mock scope
beforeEach(inject(function($controller, $rootScope, $httpBackend) {
rootScope = $rootScope;
httpBackend = $httpBackend;
scope = $rootScope.$new();
stateParams = {
section: '1.1'
};
httpBackend.whenGET('overview.html').respond('');
httpBackend.whenGET('views/main.html').respond('');
httpBackend.whenGET('views/sections.html').respond('');
httpBackend.whenGET('views/404.html').respond('');
ctrl = $controller('SectionsCtrl', {
$scope: scope,
$stateParams: stateParams
});
}));
it('should be defined', function() {
expect(ctrl).not.to.equal(null);
});
it('should contain correct title', function() {
rootScope.$digest();
expect(rootScope.pageTitle).to.eql('1.1 Sub section header text - Page Title');
});
it('should refresh title when new data is available', function() {
rootScope.$digest();
styleguideData.sections.data = [{
header: 'Section header text',
reference: '1'
},
{
header: 'Changed section header',
parentReference: '1',
reference: '1.1'
}];
styleguideData.config.data = {
title: 'New Page Title'
};
rootScope.$digest();
expect(rootScope.pageTitle).to.eql('1.1 Changed section header - New Page Title');
});
describe('empty main section detection', function() {
it('should return true if main section', function() {
var section = {
header: 'Section header text',
reference: '1',
renderMarkup: '',
markup: ''
};
expect(scope.isMainSection(section)).to.eql(true);
});
it('should return true for empty main sections', function() {
var section = {
header: 'Section header text',
reference: '1',
renderMarkup: '',
markup: ''
};
expect(scope.isEmptyMainSection(section)).to.eql(true);
});
it('should return false for empty sub sections', function() {
var section = {
header: 'Section header text',
reference: '1.1',
renderMarkup: '',
markup: ''
};
expect(scope.isEmptyMainSection(section)).to.eql(false);
});
it('should return false for section that has markup', function() {
var section = {
header: 'Section header text',
reference: '1',
renderMarkup: '<p>Test</p>',
markup: '<p>Test</p>'
};
expect(scope.isEmptyMainSection(section)).to.eql(false);
});
});
describe('section filtering', function() {
it('should return true if showing all sections', function() {
scope.currentSection = 'all';
expect(scope.filterSections({reference: '1'})).to.eql(true);
expect(scope.filterSections({reference: '2'})).to.eql(true);
expect(scope.filterSections({reference: 'foo'})).to.eql(true);
});
it('should return true for current section', function() {
scope.currentSection = '1';
expect(scope.filterSections({reference: '1'})).to.eql(true);
});
it('should return false if section is a subsection of main section', function() {
scope.currentSection = '1';
styleguideData.config.data = {
hideSubsectionsOnMainSection: true
};
expect(scope.filterSections({reference: '1.2'})).to.eql(false);
expect(scope.filterSections({reference: '1.1.2'})).to.eql(false);
});
it('should return false if section is not sub section of current section', function() {
scope.currentSection = '2';
expect(scope.filterSections({reference: '1.2'})).to.eql(false);
expect(scope.filterSections({reference: '1.1.2'})).to.eql(false);
});
it('should return false if current section is 1 and section reference is 10', function() {
scope.currentSection = '1';
expect(scope.filterSections({reference: '1'})).to.eql(true);
expect(scope.filterSections({reference: '1.0'})).to.eql(false);
expect(scope.filterSections({reference: '1.1'})).to.eql(false);
expect(scope.filterSections({reference: '10'})).to.eql(false);
expect(scope.filterSections({reference: '10.0'})).to.eql(false);
expect(scope.filterSections({reference: '10.1'})).to.eql(false);
});
it('should return false for undefined reference', function() {
expect(scope.filterSections({})).to.eql(false);
});
});
});
|