Skip to content

Commit

Permalink
Add translations to Karma specs
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
gisikw committed Mar 25, 2015
1 parent f41933b commit 09b6401
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 18 deletions.
21 changes: 15 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ module.exports = function(grunt) {
fileNameFormat: '${name}-${hash}.${ext}'
},
src: [
'website/build/*.js',
'website/build/*.css',
'website/build/*.js',
'website/build/*.css',
'website/build/favicon.ico',
'website/build/common/dist/sprites/*.png',
'website/build/common/img/sprites/backer-only/*.gif',
Expand All @@ -166,7 +166,7 @@ module.exports = function(grunt) {
}
},

nodemon: {
nodemon: {
dev: {
script: '<%= pkg.main %>'
}
Expand Down Expand Up @@ -202,7 +202,7 @@ module.exports = function(grunt) {

_.each(files[key].js, function(val){
var path = "./";
if( val.indexOf('common/') == -1)
if( val.indexOf('common/') == -1)
path = './website/public/';
js.push(path + val);
});
Expand All @@ -213,7 +213,7 @@ module.exports = function(grunt) {
var path = "./";
if( val.indexOf('common/') == -1) {
path = (val == 'app.css' || val == 'static.css') ? './website/build/' : './website/public/';
}
}
css.push(path + val)
});

Expand All @@ -230,10 +230,19 @@ module.exports = function(grunt) {
// Register tasks.
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:dev', ['browserify', 'stylus']);
grunt.registerTask('build:dev', ['browserify', 'stylus', 'test:prepare:translations']);

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')
grunt.registerTask('default', ['build:prod']);
else
Expand Down
2 changes: 2 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports = function(config) {
'website/public/bower_components/js-emoji/emoji.js',
'common/dist/scripts/habitrpg-shared.js',

"test/spec/translations.js",

"website/public/js/env.js",

"website/public/js/app.js",
Expand Down
4 changes: 1 addition & 3 deletions test/spec/authCtrlSpec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

// @TODO translations aren't loading

xdescribe('Auth Controller', function() {
describe('Auth Controller', function() {

describe('AuthCtrl', function(){
var scope, ctrl, user, $httpBackend, $window;
Expand Down
1 change: 0 additions & 1 deletion test/spec/filtersCtrlSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
describe('Filters Controller', function() {
var scope, user;

beforeEach(module('habitrpg'));
beforeEach(inject(function($rootScope, $controller, Shared) {
user = specHelper.newUser();
Shared.wrap(user);
Expand Down
4 changes: 2 additions & 2 deletions test/spec/groupServicesSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

// @TODO the requests via $resource seem to be
// doing a full page reload which breaks the specs
// @TODO the requests via $resource seem to be
// doing a full page reload which breaks the specs

xdescribe('groupServices', function() {
var $httpBackend, groups;
Expand Down
4 changes: 2 additions & 2 deletions test/spec/inventoryCtrlSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ describe('Inventory Controller', function() {
expect(user.stats.gp).to.eql(1);
});

xit('chooses a pet', function(){
it('chooses a pet', function(){
user.items.pets['Cactus-Base'] = 5;
scope.choosePet('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']);
expect(user.balance).to.eql(3.25);
expect(user.items.eggs).to.eql({Cactus: 1, Wolf: 1})
Expand Down
9 changes: 5 additions & 4 deletions test/spec/rootCtrlSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

// @TODO: Something here is calling a full page reload
xdescribe('Root Controller', function() {
var scope, user, ctrl;

Expand All @@ -11,8 +12,7 @@ xdescribe('Root Controller', function() {

ctrl = $controller('RootCtrl', {$scope: scope, User: {user: user}});
}));

// @TODO: Fix translations not loading here

it('shows contributor level text', function(){
expect(scope.contribText()).to.eql(undefined);
expect(scope.contribText(null, {npc: 'NPC'})).to.eql('NPC');
Expand All @@ -24,8 +24,9 @@ xdescribe('Root Controller', function() {
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: 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'}, {npc: 'NPC'})).to.eql('NPC');
expect(scope.contribText({level: 8, text: 'Blacksmith'})).to.eql('Guardian Blacksmith');
expect(scope.contribText({level: 9, text: 'Blacksmith'})).to.eql('Heroic Blacksmith');
expect(scope.contribText({level: 9, text: 'Blacksmith'}, {npc: 'NPC'})).to.eql('NPC');
});

});
2 changes: 2 additions & 0 deletions test/spec/translations.js

Large diffs are not rendered by default.

0 comments on commit 09b6401

Please sign in to comment.