-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from grawk/feature-jit-locale
Feature jit locale
- Loading branch information
Showing
9 changed files
with
207 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = function (nemo) { | ||
return function locatex(viewJSON, locatorArray) { | ||
var locale = (nemo.data && nemo.data.locale) ? nemo.data.locale : 'default', | ||
locatr = viewJSON; | ||
locatorArray.forEach(function (level) { | ||
locatr = locatr[level]; | ||
}); | ||
return locatr[locale] || locatr['default'] || locatr; | ||
return function locatex(locatorJSON) { | ||
var locale = nemo._config.get('data:locale') || 'default'; | ||
var localizedLocatorJSON = locatorJSON[locale] || locatorJSON['default'] || locatorJSON; | ||
return localizedLocatorJSON; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* global describe,before,after,beforeEach,it */ | ||
'use strict'; | ||
|
||
var Nemo = require('nemo'), | ||
nemo = {}, | ||
path = require('path'), | ||
assert = require('assert'), | ||
util = require(path.resolve(__dirname, 'util')); | ||
|
||
describe('nemo-view @locale@', function () { | ||
before(function (done) { | ||
nemo = Nemo({ | ||
plugins: { | ||
view: { | ||
module: 'path:../', | ||
arguments: ['path:mocks/locale'] | ||
} | ||
} | ||
}, done); | ||
}); | ||
after(function (done) { | ||
nemo.driver.quit().then(done); | ||
}); | ||
beforeEach(function (done) { | ||
nemo.driver.get(nemo.data.baseUrl); | ||
util.waitForJSReady(nemo).then(util.doneSuccess(done), util.doneError(done)); | ||
}); | ||
it('works for standard locators', function (done) { | ||
nemo.view.form.text().getAttribute('id').then(function (idValue) { | ||
assert.equal(idValue, 'foo_text'); | ||
nemo._config.set('data:locale', 'DE'); | ||
}).then(function () { | ||
return nemo.view.form.text().getAttribute('id'); | ||
}).then(function (idValue) { | ||
assert.equal(idValue, 'bar_text'); | ||
nemo._config.set('data:locale', ''); | ||
}).then(function () { | ||
return nemo.view.form.text().getAttribute('id'); | ||
}).then(function (idValue) { | ||
assert.equal(idValue, 'foo_text'); | ||
done(); | ||
}); | ||
}); | ||
it('works for Elements with inner locale scope', function (done) { | ||
nemo.view.form.boxInnerLocale().then(function (elts) { | ||
return elts[0].elt().getAttribute('type').then(function (typeValue) { | ||
assert.equal(typeValue, 'text'); | ||
nemo._config.set('data:locale', 'DE'); | ||
return elts[0].elt().getAttribute('type'); | ||
}); | ||
}).then(function (typeValue) { | ||
assert.equal(typeValue, 'button'); | ||
done(); | ||
}); | ||
}); | ||
it('works for Elements with outer locale scope', function (done) { | ||
nemo._config.set('data:locale', null); | ||
nemo.view.form.boxOuterLocale().then(function (elts) { | ||
elts[0].elt().getAttribute('id').then(function (idValue) { | ||
assert.equal(idValue, 'foo_text'); | ||
return true; | ||
}); | ||
}).then(function (typeValue) { | ||
nemo._config.set('data:locale', 'DE'); | ||
nemo.view.form.boxOuterLocale().then(function (elts) { | ||
elts[0].elt().getAttribute('id').then(function (idValue) { | ||
assert.equal(idValue, 'bar_text'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"text": { | ||
"default": { | ||
"locator": "#foo input.texty", | ||
"type": "css" | ||
}, | ||
"DE": { | ||
"locator": "#bar input.texty", | ||
"type": "css" | ||
} | ||
}, | ||
"boxInnerLocale": { | ||
"locator": "#foo", | ||
"type": "css", | ||
"Elements": { | ||
"elt": { | ||
"default": "input.texty", | ||
"DE": "[type=button]" | ||
} | ||
} | ||
}, | ||
"boxOuterLocale": { | ||
"default": { | ||
"locator": "#foo", | ||
"type": "css", | ||
"Elements": { | ||
"elt": "input.texty" | ||
} | ||
}, | ||
"DE": { | ||
"locator": "#bar", | ||
"type": "css", | ||
"Elements": { | ||
"elt": "input.texty" | ||
} | ||
} | ||
} | ||
} |