Skip to content

Commit

Permalink
test: add few unit test for ng-pdf directive
Browse files Browse the repository at this point in the history
- add karma-ng-html2js-preprocessor dependance to use viewer template
- add karma.proxies to serve the pdf file

maybe help sayanee#79
  • Loading branch information
simobasso committed Dec 16, 2015
1 parent 2dabe75 commit 578c4d0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"jasmine-core": "^2.4.1",
"karma": "^0.13.15",
"karma-jasmine": "^0.3.6",
"karma-ng-html2js-preprocessor": "^0.2.0",
"karma-phantomjs-launcher": "^0.2.1",
"phantomjs": "^1.9.19"
},
Expand Down
16 changes: 13 additions & 3 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
{pattern: 'example/pdf/relativity.pdf', included: false, served: true},
'bower_components/pdfjs-dist/web/compatibility.js',
'example/js/lib/pdf.js',
'example/js/lib/pdf.worker.js',
'example/js/lib/angular.min.js',
'example/js/app.js',
'example/js/controllers/docCtrl.js',
'dist/angular-pdf.min.js',
'example/partials/*.html',
'bower_components/angular-mocks/angular-mocks.js',
'test/spec/*.js'
],
Expand All @@ -31,12 +33,15 @@ module.exports = function(config) {
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'example/partials/*.html': ['ng-html2js']
},

proxies: {
'/pdf': '/base/example/pdf'
},

// test results reporter to use
// possible values: 'dots', 'progress'
Expand All @@ -47,7 +52,6 @@ module.exports = function(config) {
// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,

Expand All @@ -72,6 +76,12 @@ module.exports = function(config) {

// Concurrency level
// how many browser should be started simultanous
concurrency: Infinity
concurrency: Infinity,

ngHtml2JsPreprocessor: {
// strip this from the file path
stripPrefix: 'example/',
moduleName: 'my.templates'
}
})
}
43 changes: 43 additions & 0 deletions test/spec/ngPdfSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
describe('ngPdf', function() {
console.log = function() {};
var element, $scope;

// Load the myApp module, which contains the directive
beforeEach(module('App'));

beforeEach(module('my.templates'));

beforeEach(inject(function(_$compile_, _$rootScope_, _$document_){
// The injector unwraps the underscores (_) from around the parameter names when matching
var $compile = _$compile_;
var $rootScope = _$rootScope_;
var $document = _$document_;
$scope = $rootScope.$new();
// Compile a piece of HTML containing the directive
var html = '<ng-pdf template-url="partials/viewer.html" canvasid="pdf" scale="page-fit" page=13></ng-pdf>';
var elmnt = angular.element(html);
$document.find('body').append(elmnt);
element = $compile(elmnt)($scope);
$scope.pdfUrl = '/pdf/relativity.pdf';
$scope.$digest();
}));

beforeEach(function(done){
setTimeout(function() {
done();
}, 9000);
}, 10000);

it('ng-pdf maust have 1 canvas', function() {
var canvas = element.find('canvas');
expect(canvas.length).toBe(1);
});

it('goNext and goPrevious change page', function(){
expect($scope.pageNum).toBe(13);
$scope.goPrevious();
expect($scope.pageNum).toBe(12);
$scope.goNext();
expect($scope.pageNum).toBe(13);
});
});

0 comments on commit 578c4d0

Please sign in to comment.