element when the toolbar has one action.", function() {
61 | var subToolbar = new L.Toolbar2({ actions: [L.Toolbar2.Action] }),
62 | TestAction = Action.extend({ options: { subToolbar: subToolbar } }),
63 | ul;
64 |
65 | toolbar = new L.Toolbar2({ actions: [TestAction] }).addTo(map);
66 |
67 | TestAction.prototype._addSubToolbar(toolbar, container, [map]);
68 | ul = container.querySelectorAll('ul');
69 |
70 | expect(ul.length).to.equal(1);
71 | expect(L.DomUtil.hasClass(subToolbar._ul, 'leaflet-toolbar-1')).to.equal(true);
72 | });
73 | });
74 |
75 | describe("#addHooks", function() {
76 | beforeEach(function() {
77 | var subToolbar = new L.Toolbar2({ actions: [L.Toolbar2.Action] }),
78 | action = new L.Toolbar2.Action();
79 |
80 | L.setOptions(action, { subToolbar: subToolbar });
81 | toolbar = new L.Toolbar2({ actions: [L.Toolbar2.Action] }).addTo(map);
82 |
83 | action._addSubToolbar(toolbar, container, [map]);
84 | });
85 |
86 | /* How to test this without access to the action itself? */
87 | it.skip("Should show the subToolbar when the action is enabled.", function() {
88 | var ul = container.querySelectorAll('ul')[0],
89 | action = new L.Toolbar2.Action();
90 |
91 | expect(getComputedStyle(ul).display).to.equal('none');
92 |
93 | action.enable();
94 | expect(ul.style.display).to.equal('block');
95 | });
96 | });
97 |
98 | describe("#removeHooks", function() {
99 | beforeEach(function() {
100 | var subToolbar = new L.Toolbar2({ actions: [L.Toolbar2.Action] }),
101 | action = new L.Toolbar2.Action();
102 |
103 | L.setOptions(action, { subToolbar: subToolbar });
104 | toolbar = new L.Toolbar2({ actions: [L.Toolbar2.Action] }).addTo(map);
105 |
106 | action._addSubToolbar(toolbar, container, [map]);
107 | });
108 |
109 | /* How to test this without access to the action itself? */
110 | it.skip("Should hide the subToolbar when the hndler is disabled.", function() {
111 | var ul = container.querySelectorAll('ul')[0],
112 | action = new L.Toolbar2.Action();
113 |
114 | expect(getComputedStyle(ul).display).to.equal('none');
115 |
116 | action.enable();
117 | action.disable();
118 |
119 | expect(ul.style.display).to.equal('none');
120 | });
121 | });
122 |
123 | describe("#enable", function() {
124 | it("Should enable the action.", function() {
125 | var action = new L.Toolbar2.Action();
126 |
127 | action.enable();
128 | expect(action.enabled()).to.equal(true);
129 | });
130 |
131 | it("Should re-enable the action after it is disabled.", function() {
132 | var action = new L.Toolbar2.Action();
133 |
134 | action.enable();
135 | action.disable();
136 | action.enable();
137 |
138 | /* Regression test: code written to maintain a single active action at a time
139 | * was inadvertently disabling actions.
140 | */
141 | expect(action.enabled()).to.equal(true);
142 | });
143 | });
144 |
145 | describe("#disable", function() {
146 | it("Should disable the action.", function() {
147 | var action = new L.Toolbar2.Action();
148 |
149 | action.enable();
150 | action.disable();
151 |
152 | expect(action.enabled()).to.equal(false);
153 | });
154 | });
155 |
156 | describe(".extendOptions", function() {
157 | it("Should return a new constructor with parent options merged with those passed to .extendOptions", function() {
158 | var H = L.Toolbar2.Action.extendOptions({ color: '#d1bd0f' }),
159 | h = new H(map);
160 |
161 | /* New option should be passed to the new constructor. */
162 | expect(h.options.color).to.equal('#d1bd0f');
163 |
164 | /* Options of the parent constructor should be retained. */
165 | expect(h.options.toolbarIcon.html).to.equal('');
166 | });
167 | });
168 | });
169 |
170 | describe("L.toolbarAction", function() {
171 | describe("class factory", function() {
172 | it("Creates an L.Toolbar2.Action instance.", function() {
173 | var options = { toolbarIcon: { html: 'hello' } };
174 |
175 | expect(L.toolbarAction(options)).to.deep.equal(new L.Toolbar2.Action(options));
176 | });
177 | });
178 | });
--------------------------------------------------------------------------------
/test/src/ToolbarControlSpec.js:
--------------------------------------------------------------------------------
1 | describe("L.Toolbar2.Control", function() {
2 | var map,
3 | toolbar;
4 |
5 | beforeEach(function() {
6 | map = new L.Map(L.DomUtil.create('div')).setView([41.7896,-87.5996], 15);
7 | toolbar = new L.Toolbar2.Control([L.Toolbar2.Action]).addTo(map);
8 | });
9 |
10 | describe("#onAdd", function() {
11 | it("Adds the toolbar to the map.", function() {
12 | expect(map.hasLayer(toolbar)).to.equal(true);
13 | });
14 | });
15 |
16 | describe("#onRemove", function() {
17 | it("Removes the toolbar from the map", function() {
18 | map.removeLayer(toolbar);
19 | expect(map.hasLayer(toolbar)).to.equal(false);
20 | });
21 | });
22 | });
23 |
24 | describe("L.toolbar.control", function() {
25 | describe("class factory", function() {
26 | it("creates L.Toolbar2.Control instance", function() {
27 | var options = {position: 'bottomleft'};
28 | expect(L.toolbar.control(options)).to.eql(new L.Toolbar2.Control(options));
29 | });
30 | });
31 | });
32 |
--------------------------------------------------------------------------------
/test/src/ToolbarPopupSpec.js:
--------------------------------------------------------------------------------
1 | describe("L.Toolbar2.Popup", function() {
2 | var map,
3 | toolbar;
4 |
5 | beforeEach(function() {
6 | var latlng = new L.LatLng(0, 0);
7 |
8 | /* need to add the to document.body in order for external CSS stylesheets to be applied. */
9 | map = new L.Map(L.DomUtil.create('div', 'map', document.body)).setView([41.7896,-87.5996], 15);
10 | toolbar = new L.Toolbar2.Popup(latlng, {
11 | actions: [L.Toolbar2.Action, L.Toolbar2.Action]
12 | });
13 | });
14 |
15 | describe("#onRemove", function() {
16 | it("Should remove the toolbar from the map.", function() {
17 | toolbar.addTo(map);
18 | map.removeLayer(toolbar);
19 |
20 | expect(map.hasLayer(toolbar)).to.equal(false);
21 | });
22 |
23 | it.skip("Should not throw an error if toolbar removal is triggered by clicking a toolbar icon.", function() {
24 | /* Need to be able to trigger a click event on a toolbar icon. */
25 | });
26 | });
27 |
28 | describe("#_setStyles", function() {
29 | it("Sets the width of the toolbar to a nonzero value if there are toolbar actions.", function() {
30 | var actionsLength = toolbar.options.actions.length,
31 | toolbarContainer,
32 | toolbarButtons,
33 | toolbarWidth,
34 | buttonWidth;
35 |
36 | /* Want to test the width of the toolbar with more than one action. */
37 | expect(actionsLength).to.be.above(1);
38 |
39 | toolbar.addTo(map);
40 |
41 | toolbarContainer = toolbar._ul;
42 | toolbarButtons = toolbar._container.querySelectorAll('.leaflet-toolbar-icon');
43 |
44 | expect(toolbarButtons.length).to.equal(actionsLength);
45 |
46 | toolbarWidth = parseInt(L.DomUtil.getStyle(toolbarContainer, 'width'), 10);
47 | buttonWidth = parseInt(L.DomUtil.getStyle(toolbarButtons[0], 'width'), 10);
48 |
49 | expect(toolbarWidth).to.be.above(buttonWidth);
50 | });
51 | });
52 |
53 | describe("setLatLng", function() {
54 | it("Should change the latlng of the popup", function() {
55 | var latlng = new L.LatLng(1, 2);
56 |
57 | toolbar.setLatLng(latlng);
58 | });
59 | });
60 | });
61 |
62 | describe("L.toolbar.popup", function() {
63 | describe("class factory", function() {
64 | it("creates L.Toolbar2.Popup instance", function() {
65 | var options = {position: 'bottomleft'};
66 | expect(L.toolbar.popup(options)).to.eql(new L.Toolbar2.Popup(options));
67 | });
68 | });
69 | });
70 |
--------------------------------------------------------------------------------
/test/src/ToolbarSpec.js:
--------------------------------------------------------------------------------
1 | describe("L.Toolbar2", function() {
2 | var map,
3 | container,
4 | toolbarTemplate,
5 | toolbar;
6 |
7 | beforeEach(function() {
8 | map = new L.Map(L.DomUtil.create('div')).setView([41.7896,-87.5996], 15);
9 | container = L.DomUtil.create('div');
10 |
11 | toolbarTemplate = [L.Toolbar2.Action];
12 | toolbar = new L.Toolbar2({ actions: toolbarTemplate });
13 | });
14 |
15 | describe("#onAdd", function() {
16 | it.skip("Should replace the current toolbar when a duplicate is added to the map.", function() {
17 | var toolbar1 = new L.Toolbar2().addTo(map);
18 |
19 | new L.Toolbar2().addTo(map);
20 | expect(map.hasLayer(toolbar1)).to.equal(false);
21 | });
22 |
23 | it.skip("Should allow multiple toolbars of different types on the map.", function() {
24 | var Toolbar1 = L.Toolbar2.extend({}),
25 | Toolbar2 = L.Toolbar2.extend({}),
26 | toolbar1 = new Toolbar1().addTo(map);
27 |
28 | new Toolbar2().addTo(map);
29 |
30 | expect(map.hasLayer(toolbar1)).to.equal(true);
31 | });
32 | });
33 |
34 | describe("#addTo", function() {
35 | it("Should add a toolbar to the map.", function() {
36 | toolbar.addTo(map);
37 | expect(map.hasLayer(toolbar)).to.equal(true);
38 | });
39 |
40 | it("Should pass along its arguments to each toolbar action factory.", function(done) {
41 | var TestHandler = L.Toolbar2.Action.extend({
42 | initialize: function(arg1, arg2) {
43 | expect(arg1).to.equal(map);
44 | expect(arg2).to.equal(2);
45 | done();
46 | }
47 | });
48 |
49 | toolbar = new L.Toolbar2({ actions: [TestHandler] });
50 |
51 | toolbar.addTo(map, 2);
52 | toolbar.appendToContainer(container);
53 | });
54 | });
55 |
56 | describe("#appendToContainer", function() {
57 | it("Should create an icon for each toolbar action.", function() {
58 | var icons;
59 |
60 | toolbar.appendToContainer(container);
61 |
62 | icons = container.querySelectorAll('.leaflet-toolbar-icon');
63 |
64 | expect(icons.length).to.equal(toolbarTemplate.length);
65 | });
66 | });
67 |
68 | describe("#_show", function() {
69 | it("Should set the display of the toolbar container to 'block'", function() {
70 | toolbar.addTo(map);
71 | toolbar.appendToContainer(container);
72 |
73 | toolbar._show();
74 | expect(toolbar._ul.style.display).to.equal('block');
75 | });
76 | });
77 |
78 | describe("#_hide", function() {
79 | it("Should set the display of the toolbar container to 'block'", function() {
80 | toolbar.addTo(map);
81 | toolbar.appendToContainer(container);
82 |
83 | toolbar._hide();
84 | expect(toolbar._ul.style.display).to.equal('none');
85 | });
86 | });
87 |
88 | describe("#_calculateToolbarDepth", function() {
89 | it("Should return 0 for a single toolbar", function() {
90 | toolbar.addTo(map);
91 | expect(toolbar._calculateDepth()).to.equal(0);
92 | });
93 |
94 | it("Should return 1 for a nested toolbar", function() {
95 | var subToolbar = new L.Toolbar2(),
96 | TestHandler = L.Toolbar2.Action.extend({ options: { subToolbar: subToolbar } });
97 |
98 | toolbar = new L.Toolbar2({ actions: [TestHandler] }).addTo(map);
99 | toolbar.appendToContainer(container);
100 |
101 | expect(subToolbar._calculateDepth()).to.equal(1);
102 | });
103 | });
104 | });
105 |
--------------------------------------------------------------------------------