Add translations to Karma specs

* Added a task to Gruntfile to use website/src/i18n.js to generate a small JS file to be loaded in Karma env which sets window.env.translations to the i18n.translations['en'].

* Added new Grunt task to build:dev

* Updated Karma specs to reenable testing where possible, updating comments where not.
This commit is contained in:
Kevin Gisi
2015-03-22 09:06:37 -04:00
parent f41933b7a1
commit 09b6401794
8 changed files with 29 additions and 18 deletions

View File

@@ -154,8 +154,8 @@ module.exports = function(grunt) {
fileNameFormat: '${name}-${hash}.${ext}' fileNameFormat: '${name}-${hash}.${ext}'
}, },
src: [ src: [
'website/build/*.js', 'website/build/*.js',
'website/build/*.css', 'website/build/*.css',
'website/build/favicon.ico', 'website/build/favicon.ico',
'website/build/common/dist/sprites/*.png', 'website/build/common/dist/sprites/*.png',
'website/build/common/img/sprites/backer-only/*.gif', 'website/build/common/img/sprites/backer-only/*.gif',
@@ -166,7 +166,7 @@ module.exports = function(grunt) {
} }
}, },
nodemon: { nodemon: {
dev: { dev: {
script: '<%= pkg.main %>' script: '<%= pkg.main %>'
} }
@@ -202,7 +202,7 @@ module.exports = function(grunt) {
_.each(files[key].js, function(val){ _.each(files[key].js, function(val){
var path = "./"; var path = "./";
if( val.indexOf('common/') == -1) if( val.indexOf('common/') == -1)
path = './website/public/'; path = './website/public/';
js.push(path + val); js.push(path + val);
}); });
@@ -213,7 +213,7 @@ module.exports = function(grunt) {
var path = "./"; var path = "./";
if( val.indexOf('common/') == -1) { if( val.indexOf('common/') == -1) {
path = (val == 'app.css' || val == 'static.css') ? './website/build/' : './website/public/'; path = (val == 'app.css' || val == 'static.css') ? './website/build/' : './website/public/';
} }
css.push(path + val) css.push(path + val)
}); });
@@ -230,10 +230,19 @@ module.exports = function(grunt) {
// Register tasks. // Register tasks.
grunt.registerTask('compile:sprites', ['clean:sprite', 'sprite', 'cssmin']); grunt.registerTask('compile:sprites', ['clean:sprite', 'sprite', 'cssmin']);
grunt.registerTask('build:prod', ['loadManifestFiles', 'clean:build', 'browserify', 'uglify', 'stylus', 'cssmin', 'copy:build', 'hashres']); grunt.registerTask('build:prod', ['loadManifestFiles', 'clean:build', 'browserify', 'uglify', 'stylus', 'cssmin', 'copy:build', 'hashres']);
grunt.registerTask('build:dev', ['browserify', 'stylus']); grunt.registerTask('build:dev', ['browserify', 'stylus', 'test:prepare:translations']);
grunt.registerTask('run:dev', [ 'build:dev', 'concurrent' ]); grunt.registerTask('run:dev', [ 'build:dev', 'concurrent' ]);
grunt.registerTask('test:prepare:translations', function() {
require('coffee-script');
var i18n = require('./website/src/i18n'),
fs = require('fs');
fs.writeFileSync('test/spec/translations.js',
"if(!window.env) window.env = {};\n" +
"window.env.translations = " + JSON.stringify(i18n.translations['en']) + ';');
});
if(process.env.NODE_ENV == 'production') if(process.env.NODE_ENV == 'production')
grunt.registerTask('default', ['build:prod']); grunt.registerTask('default', ['build:prod']);
else else

View File

@@ -34,6 +34,8 @@ module.exports = function(config) {
'website/public/bower_components/js-emoji/emoji.js', 'website/public/bower_components/js-emoji/emoji.js',
'common/dist/scripts/habitrpg-shared.js', 'common/dist/scripts/habitrpg-shared.js',
"test/spec/translations.js",
"website/public/js/env.js", "website/public/js/env.js",
"website/public/js/app.js", "website/public/js/app.js",

View File

@@ -1,8 +1,6 @@
'use strict'; 'use strict';
// @TODO translations aren't loading describe('Auth Controller', function() {
xdescribe('Auth Controller', function() {
describe('AuthCtrl', function(){ describe('AuthCtrl', function(){
var scope, ctrl, user, $httpBackend, $window; var scope, ctrl, user, $httpBackend, $window;

View File

@@ -3,7 +3,6 @@
describe('Filters Controller', function() { describe('Filters Controller', function() {
var scope, user; var scope, user;
beforeEach(module('habitrpg'));
beforeEach(inject(function($rootScope, $controller, Shared) { beforeEach(inject(function($rootScope, $controller, Shared) {
user = specHelper.newUser(); user = specHelper.newUser();
Shared.wrap(user); Shared.wrap(user);

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
// @TODO the requests via $resource seem to be // @TODO the requests via $resource seem to be
// doing a full page reload which breaks the specs // doing a full page reload which breaks the specs
xdescribe('groupServices', function() { xdescribe('groupServices', function() {
var $httpBackend, groups; var $httpBackend, groups;

View File

@@ -66,13 +66,13 @@ describe('Inventory Controller', function() {
expect(user.stats.gp).to.eql(1); expect(user.stats.gp).to.eql(1);
}); });
xit('chooses a pet', function(){ it('chooses a pet', function(){
user.items.pets['Cactus-Base'] = 5; user.items.pets['Cactus-Base'] = 5;
scope.choosePet('Cactus', 'Base'); scope.choosePet('Cactus', 'Base');
expect(user.items.currentPet).to.eql('Cactus-Base'); expect(user.items.currentPet).to.eql('Cactus-Base');
}); });
xit('purchases an egg', inject(function(Content){ it('purchases an egg', inject(function(Content){
scope.purchase('eggs', Content.eggs['Wolf']); scope.purchase('eggs', Content.eggs['Wolf']);
expect(user.balance).to.eql(3.25); expect(user.balance).to.eql(3.25);
expect(user.items.eggs).to.eql({Cactus: 1, Wolf: 1}) expect(user.items.eggs).to.eql({Cactus: 1, Wolf: 1})

View File

@@ -1,5 +1,6 @@
'use strict'; 'use strict';
// @TODO: Something here is calling a full page reload
xdescribe('Root Controller', function() { xdescribe('Root Controller', function() {
var scope, user, ctrl; var scope, user, ctrl;
@@ -11,8 +12,7 @@ xdescribe('Root Controller', function() {
ctrl = $controller('RootCtrl', {$scope: scope, User: {user: user}}); ctrl = $controller('RootCtrl', {$scope: scope, User: {user: user}});
})); }));
// @TODO: Fix translations not loading here
it('shows contributor level text', function(){ it('shows contributor level text', function(){
expect(scope.contribText()).to.eql(undefined); expect(scope.contribText()).to.eql(undefined);
expect(scope.contribText(null, {npc: 'NPC'})).to.eql('NPC'); expect(scope.contribText(null, {npc: 'NPC'})).to.eql('NPC');
@@ -24,8 +24,9 @@ xdescribe('Root Controller', function() {
expect(scope.contribText({level: 5, text: 'Blacksmith'})).to.eql('Champion Blacksmith'); expect(scope.contribText({level: 5, text: 'Blacksmith'})).to.eql('Champion Blacksmith');
expect(scope.contribText({level: 6, text: 'Blacksmith'})).to.eql('Champion Blacksmith'); expect(scope.contribText({level: 6, text: 'Blacksmith'})).to.eql('Champion Blacksmith');
expect(scope.contribText({level: 7, text: 'Blacksmith'})).to.eql('Legendary Blacksmith'); expect(scope.contribText({level: 7, text: 'Blacksmith'})).to.eql('Legendary Blacksmith');
expect(scope.contribText({level: 8, text: 'Blacksmith'})).to.eql('Heroic Blacksmith'); expect(scope.contribText({level: 8, text: 'Blacksmith'})).to.eql('Guardian Blacksmith');
expect(scope.contribText({level: 8, text: 'Blacksmith'}, {npc: 'NPC'})).to.eql('NPC'); expect(scope.contribText({level: 9, text: 'Blacksmith'})).to.eql('Heroic Blacksmith');
expect(scope.contribText({level: 9, text: 'Blacksmith'}, {npc: 'NPC'})).to.eql('NPC');
}); });
}); });

File diff suppressed because one or more lines are too long