forked from openstreetmap/iD
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
13 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,65 @@ | ||
describe('iD.uiSourceSubfield', function() { | ||
let entity, context, selection, field; | ||
|
||
beforeEach(function() { | ||
entity = iD.osmNode({id: 'n12345'}); | ||
context = iD.coreContext().assetPath('../dist/').init(); | ||
context.history().merge([entity]); | ||
selection = d3.select(document.createElement('div')); | ||
field = iD.presetField('name', { key: 'name', type: 'text' }); | ||
}); | ||
|
||
it('adds an source subfield when the @ button is clicked', function(done) { | ||
var uiField = iD.uiField(context, field, ['n12345'], {show: true, wrap: true}); | ||
window.setTimeout(function() { // async, so data will be available | ||
selection.call(uiField.render); | ||
happen.click(selection.selectAll('.source-icon').node()); | ||
expect(selection.selectAll('.field-source').nodes().length).to.equal(1); | ||
done(); | ||
}, 20); | ||
}); | ||
|
||
it('creates field:source tag after setting the value', function(done) { | ||
var uiField = iD.uiField(context, field, ['n12345'], {show: true, wrap: true}); | ||
window.setTimeout(function() { // async, so data will be available | ||
selection.call(uiField.render); | ||
happen.click(selection.selectAll('.source-icon').node()); | ||
|
||
iD.utilGetSetValue(selection.selectAll('.field-source-value'), 'Book 1'); | ||
|
||
uiField.on('change', function(tags) { | ||
expect(tags).to.eql({'name:source': 'Book 1'}); | ||
}); | ||
happen.once(selection.selectAll('.field-source-value').node(), {type: 'change'}); | ||
done(); | ||
|
||
}, 20); | ||
}); | ||
|
||
|
||
it('removes the tag when the value is emptied', function(done) { | ||
var uiField = iD.uiField(context, field, ['n12345'], {show: true, wrap: true}); | ||
window.setTimeout(function() { // async, so data will be available | ||
selection.call(uiField.render); | ||
happen.click(selection.selectAll('.source-icon').node()); | ||
iD.utilGetSetValue(selection.selectAll('.field-source-value'), 'abc'); | ||
|
||
uiField.on('change', function(tags) { | ||
expect(tags).to.eql({'name:source': undefined}); | ||
}); | ||
|
||
iD.utilGetSetValue(selection.selectAll('.field-source-value'), ''); | ||
happen.once(selection.selectAll('.field-source-value').node(), {type: 'change'}); | ||
done(); | ||
}, 20); | ||
}); | ||
|
||
it('there is no @ button on main source field', function(done) { | ||
var uiField = iD.uiField(context, {...field, source: false}, ['n12345'], {show: true, wrap: true}); | ||
window.setTimeout(function() { // async, so data will be available | ||
selection.call(uiField.render); | ||
expect(selection.selectAll('.source-icon').nodes().length).to.equal(0); | ||
done(); | ||
}, 20); | ||
}); | ||
}); |