Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Revert "Bug 975249 - [marionette-helper] add tapInput method"
Browse files Browse the repository at this point in the history
This reverts commit b4246b2.
  • Loading branch information
cctuan committed Mar 6, 2014
1 parent cc6c9b9 commit 38af34b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 166 deletions.
67 changes: 3 additions & 64 deletions index.js
Expand Up @@ -193,72 +193,11 @@ MarionetteHelper.prototype = {
},

/**
* Tap input element and fill the value.
* To do: Support the time, date, datetime, and datetime-local input
* correctly.
* Please refer to http://bugzil.la/976453.
*
* @param {Marionette.Element|String} el marionette element object or
* css selector.
* @param {String|Object} input text or datetime object for the input.
*/
fillInputField: function(el, input) {

if (!isElement(el)) {
el = this.client.findElement(el);
}

if (input instanceof Date) {
// XXX: bug 978685
// We cannot get type through element.getAttribute('type') if the type is
// datetime or datetime-local, so we use below workaround.
var eleType = this.client.executeScript(function(el) {
return el.getAttribute('type');
}, [el]);

switch (eleType) {
case 'date':
input = input.getFullYear() + '-' + addLeadZero(input.getMonth()) +
'-' + addLeadZero(input.getDate());
break;
case 'time':
input = addLeadZero(input.getHours()) + ':' +
addLeadZero(input.getMinutes());
break;
case 'datetime':
input = input.getFullYear() + '-' + addLeadZero(input.getMonth()) +
'-' + addLeadZero(input.getDate()) + 'T' +
addLeadZero(input.getHours()) + ':' +
addLeadZero(input.getMinutes()) + ':' +
addLeadZero(input.getSeconds()) + 'Z';
break;
}
}

// Below script is to trigger input event on the input correctly and fill
// the data.
this.client.executeScript(function(el, value) {
el.value = value;
var evt = new Event('input', {
'view': window,
'bubbles': true,
'cancelable': true
});
el.dispatchEvent(evt);
}, [el, input]);

function addLeadZero(num) {
return num >= 10 ? num : ('0' + num);
}
},

/**
* Select specific option from target select element.
*
* select specific option from target select element
* @param {Marionette.Element|String} el element or some css selector.
* @param {String} optionText text for the option.
* @param {String} optionText text for the option
*/
selectSelectOption: function(el, optionText) {
tapSelectOption: function(el, optionText) {
var selectedOption = null;

if (!isElement(el)) {
Expand Down
5 changes: 0 additions & 5 deletions test/integration/fakeapp/index.html
Expand Up @@ -17,10 +17,5 @@
<option value="option2">option2</option>
<option value="option3">option3</option>
</select>

<input id="input">
<input id="input-date" type="date">
<input id="input-time" type="time">
<input id="input-datetime" type="datetime">
</body>
</html>
75 changes: 0 additions & 75 deletions test/integration/index_test.js

This file was deleted.

23 changes: 1 addition & 22 deletions test/integration/lib/fake_app.js
Expand Up @@ -9,32 +9,11 @@ function FakeApp(client, origin) {

FakeApp.Selector = Object.freeze({
selectElement: '#select',
selectedOptionElement: '#select option:checked',
inputElement: '#input',
inputDateElement: '#input-date',
inputTimeElement: '#input-time',
inputDatetimeElement: '#input-datetime'
selectedOptionElement: '#select option:checked'
});

FakeApp.prototype = {
client: null,

get inputElementValue() {
return this.client.findElement(
FakeApp.Selector['inputElement']).getAttribute('value');
},
get inputDateElementValue() {
return this.client.findElement(
FakeApp.Selector['inputDateElement']).getAttribute('value');
},
get inputTimeElementValue() {
return this.client.findElement(
FakeApp.Selector['inputTimeElement']).getAttribute('value');
},
get inputDatetimeElementValue() {
return this.client.findElement(
FakeApp.Selector['inputDatetimeElement']).getAttribute('value');
},
get selectElement() {
return this.client.findElement(FakeApp.Selector.selectElement);
},
Expand Down
35 changes: 35 additions & 0 deletions test/integration/tap_select_option_test.js
@@ -0,0 +1,35 @@
suite('MarionetteHelper.tapSelectOption', function() {

// Require needed files
var FakeApp = require('./lib/fake_app');
marionette.plugin('helper', require('../../index'));
marionette.plugin('apps', require('marionette-apps'));

var helper;
var fakeApp;
var FAKE_APP_ORIGIN = 'fakeapp.gaiamobile.org';

var apps = {};
apps[FAKE_APP_ORIGIN] = __dirname + '/fakeapp';

var client = marionette.client({
settings: {
'ftu.manifestURL': null,
'lockscreen.enabled': false
},
apps: apps
});

setup(function(done) {
helper = client.helper;
fakeApp = new FakeApp(client, 'app://' + FAKE_APP_ORIGIN);
fakeApp.launch();
setTimeout(done, 2500); // Instead of using the BootWatcher.
});

test('should set on option', function() {
var optionValue = 'option2';
helper.tapSelectOption('#select', optionValue);
assert.ok(fakeApp.isSpecificSelectOptionSelected(optionValue));
});
});

0 comments on commit 38af34b

Please sign in to comment.