Skip to content

Commit 12d8565

Browse files
committed
Merge pull request mozilla-b2g#11219 from gasolin/issue-887670vs
Bug 887670 - [Test][System] Unit test for ValueSelector, r=rudy
2 parents bdf9f5b + 748616c commit 12d8565

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

apps/system/js/value_selector/value_selector.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ var ValueSelector = {
2727
var typeToHandle = ['select-one', 'select-multiple', 'date',
2828
'time', 'datetime', 'datetime-local', 'blur'];
2929

30-
var type = evt.detail.type;
30+
var currentInputType = evt.detail.type;
3131
// handle the <select> element and inputs with type of date/time
3232
// in system app for now
33-
if (typeToHandle.indexOf(type) == -1)
33+
if (typeToHandle.indexOf(currentInputType) == -1)
3434
return;
3535

3636
var currentValue = evt.detail.value;
37-
var currentInputType = evt.detail.type;
3837
self._currentDatetimeValue = currentValue;
3938
self._currentInputType = currentInputType;
4039

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'use strict';
2+
3+
mocha.globals(['ValueSelector']);
4+
5+
requireApp('system/js/value_selector/value_selector.js');
6+
requireApp('system/test/unit/mock_settings_listener.js');
7+
requireApp('system/test/unit/mock_l10n.js');
8+
9+
suite('value selector/value selector', function() {
10+
var element;
11+
12+
var realL10n;
13+
var realKeyboard;
14+
var realSettings;
15+
var stubById;
16+
17+
suiteSetup(function() {
18+
realSettings = navigator.mozSettings;
19+
navigator.mozSettings = MockNavigatorSettings;
20+
21+
realL10n = navigator.mozL10n;
22+
navigator.mozL10n = MockL10n;
23+
24+
realKeyboard = window.navigator.mozKeyboard;
25+
window.navigator.mozKeyboard = sinon.stub();
26+
});
27+
28+
suiteTeardown(function() {
29+
navigator.mozSettings = realSettings;
30+
navigator.mozL10n = realL10n;
31+
window.navigator.mozKeyboard = realKeyboard;
32+
});
33+
34+
teardown(function() {
35+
stubById.restore();
36+
});
37+
38+
setup(function() {
39+
// mockup element
40+
function mock_obj() {
41+
this.querySelector = function() {
42+
return document.createElement('div');
43+
};
44+
this.addEventListener = function() {
45+
return document.createElement('div');
46+
};
47+
};
48+
49+
stubById = this.sinon.stub(document, 'getElementById')
50+
.returns(new mock_obj());
51+
52+
ValueSelector.init();
53+
element = document.getElementById('value-selector');
54+
});
55+
56+
test('show', function() {
57+
ValueSelector.show();
58+
assert.isFalse(element.hidden);
59+
});
60+
61+
test('hide', function() {
62+
ValueSelector.hide();
63+
assert.isTrue(element.hidden);
64+
});
65+
});

0 commit comments

Comments
 (0)