add tests

This commit is contained in:
Martin Raifer
2022-10-10 13:17:19 +02:00
parent 674421eec7
commit 52ae374cee
2 changed files with 93 additions and 0 deletions

View 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;
});
});
});

View File

@@ -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;
});
});
});