Skip to content

Commit

Permalink
Merge pull request #531 from DedrickEnc/inittest
Browse files Browse the repository at this point in the history
A trial for unit test Breadcrumb
  • Loading branch information
jniles committed Jun 27, 2016
2 parents 54ca439 + a89e884 commit cbc4359
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 12 deletions.
7 changes: 6 additions & 1 deletion client/src/js/components/bhBreadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ angular.module('bhima.components')
function BreadcrumbController() {
var vm = this;

//variable to prefix all our ids at the view
vm.prefix = 'breadcrumb-';

/**
* Paths definition
* @example
Expand Down Expand Up @@ -95,9 +98,11 @@ function BreadcrumbController() {
*/
vm.bcDropdowns = vm.dropdown || [];

/** call the appropriate function and update the dropdown label */

/** call the appropriate function and update the dropdown label **/
vm.helperDropdown = function helperDropdown(child, parent) {
parent.selected = child.label;

child.action(child);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<!-- Excel -->
</div>

<div class="modal-footer">
<div class="modal-footer" id="receipt_modal_footer">
<button class="btn btn-default btn-sm" ng-click="ReceiptCtrl.close()" data-action="close" id="receipt_modal_close">Close</button>
<button class="btn btn-primary btn-sm" ng-click="ReceiptCtrl.print()" data-action="print"><span class="glyphicon glyphicon-print"></span> Print</button>
</div>
12 changes: 6 additions & 6 deletions client/src/partials/templates/breadcrumb.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div class="bhima-title">

<ol class="headercrumb">
<li ng-repeat="p in vm.bcPaths" id="{{ p.id }}" data-method="{{ p.dataMethod }}" ng-class="{ 'static' : !$last, 'title' : $last }">
<li ng-repeat="p in vm.bcPaths" data-method="{{ p.dataMethod }}" ng-class="{ 'static' : !$last, 'title' : $last }">
<span ng-hide="p.link">{{ p.label | translate }}</span>
<span ng-show="p.link">
<a ng-href="{{ p.link }}" href>{{ p.label | translate }}</a>
<a ng-href="{{ p.link }}" id="{{ vm.prefix + p.id }}" href>{{ p.label | translate }}</a>
</span>
</li>
</ol>
Expand All @@ -14,12 +14,12 @@
<!-- dropdown buttons -->
<div class="toolbar-item" ng-if="vm.bcDropdowns.length">
<span ng-repeat="d in vm.bcDropdowns" uib-dropdown>
<button class="btn btn-sm" ng-class="d.color" id="{{ d.id }}" data-method="{{ d.dataMethod }}" uib-dropdown-toggle>
<button class="btn btn-sm" ng-class="d.color" id="{{ vm.prefix + d.id }}" data-method="{{ d.dataMethod }}" uib-dropdown-toggle>
{{ d.selected | translate }} <span class="caret"></span>
</button>
<ul class="pull-right" uib-dropdown-menu>
<li ng-repeat="opt in d.option">
<a href ng-click="vm.helperDropdown(opt, d)" id="{{ opt.id }}" data-method="{{ opt.dataMethod }}">
<a href ng-click="vm.helperDropdown(opt, d)" id="{{ vm.prefix + opt.id }}" data-method="{{ opt.dataMethod }}">
{{ opt.label | translate }}
</a>
</li>
Expand All @@ -30,7 +30,7 @@
<!-- buttons -->
<div class="toolbar-item btn-group btn-group-sm" ng-show="vm.bcButtons.length">
<button class="btn"
id="{{ a.id }}"
id="{{ vm.prefix + a.id }}"
ng-class="a.color"
ng-repeat="a in vm.bcButtons"
ng-click="a.action(a.label)"
Expand All @@ -42,7 +42,7 @@

<!-- labels -->
<div class="toolbar-item" ng-if="vm.bcLabels.length">
<label ng-repeat="l in vm.bcLabels" id="{{ l.id }}" data-method="{{ l.dataMethod }}">
<label ng-repeat="l in vm.bcLabels" id="{{ vm.prefix + l.id }}" data-method="{{ l.dataMethod }}">
<strong><span class="{{ l.icon }}"></span> {{ l.label | translate }}</strong>
</label>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/test/e2e/patient/registry.search.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function PatientRegistrySearch() {
});

// combines dates with manual date manipulation
it('setting dates manually should find three patients.', function () {
it('setting dates manually should find two patients.', function () {
FU.buttons.search();

FU.input('ModalCtrl.params.dateBirthFrom', parameters.dateBirthFrom2);
Expand Down
2 changes: 1 addition & 1 deletion client/test/e2e/patient_invoice/invoiceRegistry.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function InvoiceRegistryPage() {
var searchButton = element(by.id('filterButton'));
var grid = element(by.id('invoice-registry'));
var gridRows = grid.element( by.css('.ui-grid-render-container-body')).all( by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows track by $index'));
var invoiceProofReference = element(by.id('receipt_modal_close')); //getting one off modal component here we have got the close button
var invoiceProofReference = element(by.id('receipt_modal_footer')); //getting one off modal component here we have got the footer div

function getInvoiceNumber() {
return gridRows.count();
Expand Down
119 changes: 119 additions & 0 deletions client/test/unit/components/bhBreadCrumb.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Created by Dedrick Kitamuka on 23/06/2016.
*/
describe('component : bhBreadCrumb', function () {
//two different spy for clarity
var buttonSpy = chai.spy();
var dropDownSpy = chai.spy();

var breadCrumb = {
path : [
{ id : 'firstlink', label: 'path1', link: '#/path1_link_to_go' },
{ label: 'path2', link: '#/path2_link_to_go' },
{ label: 'path3', link: '#/path3_link_to_go', current: true }
],

button : [
{ id : 'printbtn', icon: 'glyphicon glyphicon-print', label: 'Print', action: buttonSpy },
{ id : 'repeatbtn', icon: 'glyphicon glyphicon-repeat', label: 'Repeat', action: buttonSpy, color: 'btn-danger' },
{ id : 'refreshbtn', icon: 'glyphicon glyphicon-refresh', label: 'Refresh', action: buttonSpy}
],

label : [
{ icon: 'glyphicon glyphicon-print', label: 'My Label 1' },
{ label: 'My label 2' },
{ label: 'My label 3' }
],

dropdown : [
{
id : 'dropdownone',
label : 'Dropdown 1',
color : 'btn-primary',
option : [
{ id : 'optionFranc', label : 'Fc', action : dropDownSpy },
{ id : 'optionDollar', label : '$', action : dropDownSpy }
]
},

{
id : 'dropdowntwo',
label : 'Dropdown 2',
color : 'btn-success',
option : [
{ id : 'long', label : 'item1 dd2 with a too long text that you can imagine', action : dropDownSpy },
{ id : 'short', label : 'item2 dd2', action : dropDownSpy}
]
}
]
}, component;

var element, scope, $compile;

var template = `
<bh-breadcrumb
path="config.path"
button="config.button",
label="config.label",
dropdown="config.dropdown">
</bh-breadcrumb>`;

beforeEach(module('pascalprecht.translate', 'ngStorage', 'angularMoment', 'bhima.services', 'bhima.components', 'templates'));

beforeEach(inject(function (_$rootScope_, _$compile_, _$componentController_) {
scope = _$rootScope_.$new();
$compile = _$compile_;
component = _$componentController_('bhBreadcrumb', null, {
label : breadCrumb.label,
button : breadCrumb.button,
dropdown : breadCrumb.dropdown,
path : breadCrumb.path
});
}));

it('receives path data correctly', function (){
expect(component.path.length).to.be.equal(3);
});

it('receives button data correctly', function (){
expect(component.button.length).to.be.equal(3);
});

it('receives label data correctly', function (){
expect(component.label.length).to.be.equal(3);
});

it('receives dropdown data correctly', function (){
expect(component.dropdown.length).to.be.equal(2);
});

it('fires methods passed in through the button parameters', function () {

// assign configuration object to scope and init it
scope.config = breadCrumb;
element = $compile(angular.element(template))(scope);
scope.$digest();

scope.config.button.forEach(function (btn) {
$(element).find('#' + component.prefix + btn.id).click();
expect(buttonSpy).to.have.been.called.with(btn.label);
});

expect(buttonSpy).to.have.been.called.exactly(scope.config.button.length);
});

it('fires the action on a dropdown using the dropdownHelper method', function () {

scope.config = breadCrumb;
element = $compile(angular.element(template))(scope);
scope.$digest();

scope.config.dropdown.forEach(function (dropDownElement) {

dropDownElement.option.forEach(function (opt) {
$(element).find('#' + component.prefix + opt.id)[0].click();
expect(dropDownSpy).to.have.been.called.with(opt);
});
});
});
});
12 changes: 10 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function(config) {

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'],
frameworks: ['mocha', 'chai-spies', 'chai'],


// list of files / patterns to load in the browser
Expand All @@ -19,7 +19,9 @@ module.exports = function(config) {
'client/vendor/angular-mocks/angular-mocks.js',
'bin/client/js/vendor.min.js',
'bin/client/js/bhima.min.js',
'client/test/unit/**/*.spec.js'
'client/test/unit/**/*.spec.js',

'bin/client/partials/**/*.html'
],


Expand All @@ -31,6 +33,12 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'**/*.html' : ['ng-html2js']
},

ngHtml2JsPreprocessor : {
stripPrefix : 'bin/client/',
moduleName : 'templates'
},

// test results reporter to use
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"chai-as-promised": "^5.1.0",
"chai-datetime": "^1.4.0",
"chai-http": "^1.0.0",
"chai-spies": "^0.7.1",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.0",
"gulp-cssnano": "^2.1.1",
Expand All @@ -73,8 +74,10 @@
"jshint": "^2.8.0",
"karma": "^1.0.0",
"karma-chai": "^0.1.0",
"karma-chai-spies": "^0.1.4",
"karma-chrome-launcher": "^1.0.1",
"karma-mocha": "^1.0.1",
"karma-ng-html2js-preprocessor": "^1.0.0",
"mocha": "^2.5.3",
"protractor": "^3.1.1",
"rimraf": "^2.4.3"
Expand Down

0 comments on commit cbc4359

Please sign in to comment.