Skip to content

Instantly share code, notes, and snippets.

@ikouchiha47
Last active August 29, 2015 14:18
Show Gist options
  • Save ikouchiha47/d693ccd0e94935cb0b24 to your computer and use it in GitHub Desktop.
Save ikouchiha47/d693ccd0e94935cb0b24 to your computer and use it in GitHub Desktop.
'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', [
'ngRoute',
'myAppServices',
'myAppControllers'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/:genre?', {
templateUrl: 'views/movies.html',
controller: 'MoviesCtrl'
})
.otherwise({
redirectTo: '/'
});
}]);
// Karma configuration
// Generated on Thu Apr 09 2015 13:11:18 GMT+0530 (IST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'app/bower_components/angular/**/*.js',
'app/bower_components/angular-mocks/**/*.js',
'app/bower_components/angular-resource/**/*.js',
'app/bower_components/angular-route/**/*.js',
'app/app.js',
'app/services/**/*.js',
'app/controllers/**/*.js',
'unit-tests/**/*.js'
],
// list of files to exclude
exclude: [
'app/**/*.min.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
'use strict';
(function() {
angular.module('myAppControllers', ['myAppServices']).
controller('MoviesCtrl', [ '$rootScope', '$scope', '$routeParams', 'Movie', 'Config', function($rootScope, $scope, $routeParams, Movie, Config) {
$scope.movies = {}
$scope.image = {}
$rootScope.api = {
key: "abcd",
url: "https://api.themoviedb.org/3/"
}
Config.get({ api_key: $rootScope.api.key }, function(data) {
$scope.image = {
base_url: data.images.base_url,
backdrop_size: data.images.backdrop_sizes[0]
}
});
Movie.trending($rootScope.api.url + 'movie/' + ($routeParams.genre || "top_rated"))
.query(function(data) {
$scope.movies = data.results;
});
}]);
}());
describe('MoviesCtrl', function() {
var $rootScope
, $controller
, services
;
beforeEach( function() {
module('myApp');
});
beforeEach(function() {
module('myAppServices');
inject(function($injector) {
services = $injector.get('myAppServices')
$rootScope = $injector.get('$rootScope');
$controller = $injector.get('$controller')
});
});
describe("Intialization", function() {
it("should initialize the api url", function() {
var $scope = $rootScope.new();
var controller = $controller('MoviesCtrl', { $rootScope: $rootScope, $scope: $scope, myAppServices: services });
expect($rootScope.api.url).toEqual("https://api.themoviedb.org/3/")
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment