diff --git a/test/spec/presets/field.js b/test/spec/presets/field.js new file mode 100644 index 000000000..57b2e7bfb --- /dev/null +++ b/test/spec/presets/field.js @@ -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; + }); + }); +}); diff --git a/test/spec/presets/preset.js b/test/spec/presets/preset.js index 11093f62b..b8f89c16a 100644 --- a/test/spec/presets/preset.js +++ b/test/spec/presets/preset.js @@ -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; + }); + }); });