mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-12 16:52:50 +00:00
add tests
This commit is contained in:
61
test/spec/presets/field.js
Normal file
61
test/spec/presets/field.js
Normal file
@@ -0,0 +1,61 @@
|
||||
describe('iD.presetField', function() {
|
||||
describe('#references', function() {
|
||||
it('references label and terms of another field', function() {
|
||||
var allFields = {};
|
||||
var other = iD.presetField('other', {}, allFields);
|
||||
var field = iD.presetField('test', {label: '{other}'}, allFields);
|
||||
allFields.other = other;
|
||||
allFields.preset = field;
|
||||
|
||||
// mock localizer
|
||||
sinon.spy(other, 't');
|
||||
sinon.spy(field, 't');
|
||||
|
||||
field.title();
|
||||
expect(other.t).to.have.been.calledOnce;
|
||||
expect(field.t).not.to.have.been.called;
|
||||
|
||||
other.t.resetHistory();
|
||||
field.t.resetHistory();
|
||||
|
||||
field.terms();
|
||||
expect(other.t).to.have.been.calledOnce;
|
||||
expect(field.t).not.to.have.been.called;
|
||||
});
|
||||
|
||||
it('references placeholder of another field', function() {
|
||||
var allFields = {};
|
||||
var other = iD.presetField('other', {}, allFields);
|
||||
var field = iD.presetField('test', {placeholder: '{other}'}, allFields);
|
||||
allFields.other = other;
|
||||
allFields.preset = field;
|
||||
|
||||
// mock localizer
|
||||
sinon.spy(other, 't');
|
||||
sinon.spy(field, 't');
|
||||
|
||||
field.placeholder();
|
||||
expect(other.t).to.have.been.calledOnce;
|
||||
expect(field.t).not.to.have.been.called;
|
||||
});
|
||||
|
||||
it('references string options of another field', function() {
|
||||
var allFields = {};
|
||||
var other = iD.presetField('other', {}, allFields);
|
||||
var field = iD.presetField('test', {stringsCrossReference: '{other}', options: ['v'], key: 'k'}, allFields);
|
||||
allFields.other = other;
|
||||
allFields.preset = field;
|
||||
|
||||
// mock localizer
|
||||
sinon.spy(other, 't');
|
||||
sinon.spy(field, 't');
|
||||
sinon.stub(other, 'hasTextForStringId').returns(true);
|
||||
|
||||
var context = iD.coreContext().assetPath('../dist/').init();
|
||||
var uiField = iD.uiFieldCombo(field, context);
|
||||
uiField.tags({k: 'v'});
|
||||
expect(field.t).not.to.have.been.called;
|
||||
expect(other.t).to.have.been.calledOnce;
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -228,4 +228,36 @@ describe('iD.presetPreset', function() {
|
||||
expect(preset.addable()).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#references', function() {
|
||||
it('references name, aliases and terms of another preset', function() {
|
||||
var allPresets = {};
|
||||
var other = iD.presetPreset('other', {}, undefined, undefined, allPresets);
|
||||
var preset = iD.presetPreset('test', {name: '{other}'}, undefined, undefined, allPresets);
|
||||
allPresets.other = other;
|
||||
allPresets.preset = preset;
|
||||
|
||||
// mock localizer
|
||||
sinon.spy(other, 't');
|
||||
sinon.spy(preset, 't');
|
||||
|
||||
preset.name();
|
||||
expect(other.t).to.have.been.calledOnce;
|
||||
expect(preset.t).not.to.have.been.called;
|
||||
|
||||
other.t.resetHistory();
|
||||
preset.t.resetHistory();
|
||||
|
||||
preset.aliases();
|
||||
expect(other.t).to.have.been.calledOnce;
|
||||
expect(preset.t).not.to.have.been.called;
|
||||
|
||||
other.t.resetHistory();
|
||||
preset.t.resetHistory();
|
||||
|
||||
preset.terms();
|
||||
expect(other.t).to.have.been.calledOnce;
|
||||
expect(preset.t).not.to.have.been.called;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user