mysterious casperjs errors....

This commit is contained in:
Peter Cottle 2015-03-28 13:59:19 -07:00
parent 1afd48bb39
commit 8493b51ec2
7 changed files with 80 additions and 18 deletions

View file

@ -149,6 +149,7 @@ module.exports = function(grunt) {
browser: true, browser: true,
debug: true, debug: true,
globals: { globals: {
casper: true,
Raphael: true, Raphael: true,
require: true, require: true,
console: true, console: true,

View file

@ -12,7 +12,15 @@ var CasperUtils = {
}, },
getUrl: function () { getUrl: function () {
return 'file://localhost/' + this.getRoot() + '/index.html?NODEMO'; return 'file://localhost/' + this.getRoot() + 'index.html?NODEMO';
},
getUrlWithQueryParams: function(params) {
var paramsString = '';
Object.keys(params).forEach(function(key) {
paramsString = paramsString + '&' + key + '=' + params[key];
});
return this.getUrl() + paramsString;
}, },
getUrlForCommands: function(commands) { getUrlForCommands: function(commands) {
@ -40,6 +48,7 @@ var CasperUtils = {
}, },
asserts: { asserts: {
visibleIDs: function(visibleIDs) { visibleIDs: function(visibleIDs) {
return function then() { return function then() {
visibleIDs.forEach(function(id) { visibleIDs.forEach(function(id) {
@ -62,6 +71,22 @@ var CasperUtils = {
}; };
}, },
selectorContainsText: function(selector, text) {
return function then() {
this.test.assertEvalEquals(function(selector) {
__utils__.echo('hellow');
__utils__.echo('hellow' + selector);
__utils__.echo(document.querySelector(selector).innerText);
return document.querySelector(selector).innerText;
},
text,
'Checking that selector "' + selector + '" contains "' +
text + '".',
{selector: selector}
);
};
},
existingIDs: function(existingIDs) { existingIDs: function(existingIDs) {
return function then() { return function then() {
existingIDs.forEach(function(id) { existingIDs.forEach(function(id) {

View file

@ -1,5 +1,9 @@
var CasperUtils = require('./casperUtils').CasperUtils; var CasperUtils = require('./casperUtils').CasperUtils;
/**
* TODO(pcottle) -- find a way to get this from
* LocaleStore but not have the import error
*/
var langLocaleMap = { var langLocaleMap = {
en: 'en_US', en: 'en_US',
zh: 'zh_CN', zh: 'zh_CN',
@ -11,12 +15,11 @@ var langLocaleMap = {
pt: 'pt_BR' pt: 'pt_BR'
}; };
/*
var headerLocaleMap = { var headerLocaleMap = {
'zh-CN': 'zh_CN', 'zh-CN': 'zh_CN',
'zh-TW': 'zh_TW', 'zh-TW': 'zh_TW',
'pt-BR': 'pt_BR' 'pt-BR': 'pt_BR'
};*/ };
casper.start( casper.start(
CasperUtils.getUrl(), CasperUtils.getUrl(),
@ -24,11 +27,7 @@ casper.start(
this.test.assertTitle('Learn Git Branching'); this.test.assertTitle('Learn Git Branching');
casper.waitFor(CasperUtils.waits.jsMount) casper.waitFor(CasperUtils.waits.jsMount)
.then(CasperUtils.asserts.visibleIDs([
'commandLineHistory',
]))
.then(function() { .then(function() {
Object.keys(langLocaleMap).forEach(function(lang) { Object.keys(langLocaleMap).forEach(function(lang) {
var locale = langLocaleMap[lang]; var locale = langLocaleMap[lang];
this.test.assertEvalEquals(function(lang) { this.test.assertEvalEquals(function(lang) {
@ -42,6 +41,20 @@ casper.start(
); );
}.bind(this)); }.bind(this));
}) })
.then(function() {
Object.keys(headerLocaleMap).forEach(function(header) {
var locale = headerLocaleMap[header];
this.test.assertEvalEquals(function(header) {
debug_LocaleActions_changeLocaleFromHeader(header);
return debug_LocaleStore_getLocale();
},
locale,
'Testing changing store locale from ' + header +
' to ' + locale,
{header: header}
);
}.bind(this));
})
.then(CasperUtils.testDone); .then(CasperUtils.testDone);
}).run(); }).run();

View file

@ -0,0 +1,20 @@
var CasperUtils = require('./casperUtils').CasperUtils;
casper.start(
CasperUtils.getUrlForCommands([
'locale fr_FR'
]),
function() {
this.test.assertTitle('Learn Git Branching');
casper.waitFor(CasperUtils.waits.jsMount)
.then(CasperUtils.screenshot.entirePage)
.wait(3000)
.then(CasperUtils.screenshot.entirePage)
.then(CasperUtils.asserts.selectorContainsText(
// The title bar on command line history
'span[data-intl="learn-git-branching"]',
"APRENDÉ A BRANCHEAR EN GIT"
))
.then(CasperUtils.testDone);
}).run();

View file

@ -1,10 +1,6 @@
var AppConstants = require('../constants/AppConstants');
var AppDispatcher = require('../dispatcher/AppDispatcher');
var LocaleActions = require('../actions/LocaleActions'); var LocaleActions = require('../actions/LocaleActions');
var LocaleStore = require('../stores/LocaleStore'); var LocaleStore = require('../stores/LocaleStore');
var ActionTypes = AppConstants.ActionTypes;
describe('LocaleStore', function() { describe('LocaleStore', function() {
it('has default locale', function() { it('has default locale', function() {

View file

@ -14,6 +14,13 @@ var LocaleActions = {
}); });
}, },
changeLocaleFromURI: function(newLocale) {
AppDispatcher.handleURIAction({
type: ActionTypes.CHANGE_LOCALE,
locale: newLocale
});
},
changeLocaleFromHeader: function(header) { changeLocaleFromHeader: function(header) {
AppDispatcher.handleViewAction({ AppDispatcher.handleViewAction({
type: ActionTypes.CHANGE_LOCALE_FROM_HEADER, type: ActionTypes.CHANGE_LOCALE_FROM_HEADER,

View file

@ -217,7 +217,7 @@ var initDemo = function(sandbox) {
} }
if (params.locale !== undefined && params.locale.length) { if (params.locale !== undefined && params.locale.length) {
LocaleActions.changeLocale(params.locale); LocaleActions.changeLocaleFromURI(params.locale);
} else { } else {
tryLocaleDetect(); tryLocaleDetect();
} }