/
inspector.js
86 lines (68 loc) 路 2.75 KB
/
inspector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
describe("iD.Inspector", function () {
var inspector, element,
tags = {highway: 'residential'},
entity;
function render() {
inspector = iD.Inspector();
element = d3.select('body')
.append('div')
.attr('id', 'inspector-wrap')
.datum(entity)
.call(inspector);
}
beforeEach(function () {
entity = iD.Entity({type: 'node', id: "n12345", tags: tags});
render();
});
afterEach(function () {
element.remove();
});
describe("#tags", function () {
it("returns the current tags", function () {
expect(inspector.tags()).to.eql(tags);
});
it("returns updated tags when input values have changed", function () {
element.selectAll("input.key").property('value', 'k');
element.selectAll("input.value").property('value', 'v');
expect(inspector.tags()).to.eql({k: 'v'});
});
});
it("creates input elements for each key-value pair", function () {
expect(element.selectAll("input[value=highway]")).not.to.be.empty;
expect(element.selectAll("input[value=residential]")).not.to.be.empty;
});
it("creates a pair of empty input elements if the entity has no tags", function () {
element.remove();
entity = entity.update({tags: {}});
render();
expect(element.selectAll("input.value").property('value')).to.be.empty;
expect(element.selectAll("input.key").property('value')).to.be.empty;
});
it("adds tags when clicking the add button", function () {
element.selectAll("button.add-tag").trigger('click');
expect(element.selectAll("input")[0][2].value).to.be.empty;
expect(element.selectAll("input")[0][3].value).to.be.empty;
});
it("removes tags when clicking the remove button", function () {
element.selectAll("button.remove").trigger('click');
expect(inspector.tags()).to.eql({});
});
it("emits a close event when the close button is clicked", function () {
var spy = sinon.spy();
inspector.on('close', spy);
element.select('.close').trigger('click');
expect(spy).to.have.been.calledWith(entity);
});
it("emits a changeTags event when the apply button is clicked", function () {
var spy = sinon.spy();
inspector.on('changeTags', spy);
element.select('.apply').trigger('click');
expect(spy).to.have.been.calledWith(entity, tags);
});
it("emits a remove event when the delete button is clicked", function () {
var spy = sinon.spy();
inspector.on('remove', spy);
element.select('.delete').trigger('click');
expect(spy).to.have.been.calledWith(entity);
});
});