Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #563 from aik099/on-change-on-value-change-tests

Adding tests to cover existing value change in input
  • Loading branch information...
commit 4acb17811d7c57765bb3e0c2e0a0df5b84028f27 2 parents 1f11bbd + 110e542
@stof stof authored
View
57 driver-testsuite/tests/Js/ChangeEventTest.php
@@ -35,7 +35,7 @@ public function testIssue178()
* @dataProvider setValueChangeEventDataProvider
* @group change-event-detector
*/
- public function testSetValueChangeEvent($elementId, $elementValue)
+ public function testSetValueChangeEvent($elementId, $valueForEmpty, $valueForFilled = '')
{
$this->getSession()->visit($this->pathTo('/element_change_detector.html'));
$page = $this->getSession()->getPage();
@@ -43,19 +43,28 @@ public function testSetValueChangeEvent($elementId, $elementValue)
$input = $page->findById($elementId);
$this->assertNull($page->findById($elementId.'-result'));
- $input->setValue($elementValue);
- $this->assertElementChangeCount($elementId);
+ // Verify setting value, when control is initially empty.
+ $input->setValue($valueForEmpty);
+ $this->assertElementChangeCount($elementId, 'initial value setting triggers change event');
+
+ if ($valueForFilled) {
+ // Verify setting value, when control already has a value.
+ $page->findById('results')->click();
+ $input->setValue($valueForFilled);
+ $this->assertElementChangeCount($elementId, 'value change triggers change event');
+ }
}
public function setValueChangeEventDataProvider()
{
return array(
- 'input default' => array('the-input-default', 'some value'),
- 'input text' => array('the-input-text', 'some value'),
- 'input email' => array('the-email', 'some value'),
+ 'input default' => array('the-input-default', 'from empty', 'from existing'),
+ 'input text' => array('the-input-text', 'from empty', 'from existing'),
+ 'input email' => array('the-email', 'from empty', 'from existing'),
+ 'textarea' => array('the-textarea', 'from empty', 'from existing'),
+ 'file' => array('the-file', 'from empty', 'from existing'),
'select' => array('the-select', '30'),
- 'textarea' => array('the-textarea', 'some value'),
- 'file' => array('the-file', 'some value'),
+ 'radio' => array('the-radio-m', 'm'),
);
}
@@ -84,9 +93,10 @@ public function selectOptionChangeEventDataProvider()
}
/**
+ * @dataProvider checkboxTestWayDataProvider
* @group change-event-detector
*/
- public function testCheckChangeEvent()
+ public function testCheckChangeEvent($useSetValue)
{
$this->getSession()->visit($this->pathTo('/element_change_detector.html'));
$page = $this->getSession()->getPage();
@@ -94,14 +104,20 @@ public function testCheckChangeEvent()
$checkbox = $page->findById('the-unchecked-checkbox');
$this->assertNull($page->findById('the-unchecked-checkbox-result'));
- $checkbox->check();
+ if ($useSetValue) {
+ $checkbox->setValue(true);
+ } else {
+ $checkbox->check();
+ }
+
$this->assertElementChangeCount('the-unchecked-checkbox');
}
/**
+ * @dataProvider checkboxTestWayDataProvider
* @group change-event-detector
*/
- public function testUncheckChangeEvent()
+ public function testUncheckChangeEvent($useSetValue)
{
$this->getSession()->visit($this->pathTo('/element_change_detector.html'));
$page = $this->getSession()->getPage();
@@ -109,15 +125,28 @@ public function testUncheckChangeEvent()
$checkbox = $page->findById('the-checked-checkbox');
$this->assertNull($page->findById('the-checked-checkbox-result'));
- $checkbox->uncheck();
+ if ($useSetValue) {
+ $checkbox->setValue(false);
+ } else {
+ $checkbox->uncheck();
+ }
+
$this->assertElementChangeCount('the-checked-checkbox');
}
- private function assertElementChangeCount($elementId)
+ public function checkboxTestWayDataProvider()
+ {
+ return array(
+ array(true),
+ array(false),
+ );
+ }
+
+ private function assertElementChangeCount($elementId, $message = '')
{
$counterElement = $this->getSession()->getPage()->findById($elementId.'-result');
$actualCount = null === $counterElement ? 0 : $counterElement->getText();
- $this->assertEquals('1', $actualCount);
+ $this->assertEquals('1', $actualCount, $message);
}
}
View
11 driver-testsuite/web-fixtures/element_change_detector.html
@@ -15,7 +15,7 @@
<select id="the-select">
<option value="10">ten</option>
- <option selected="selected" value="20">twenty</option>
+ <option value="20" selected="selected">twenty</option>
<option value="30">thirty</option>
</select>
@@ -27,7 +27,7 @@
<input type="checkbox" id="the-checked-checkbox" value="cb-val" checked/>
<input type="checkbox" id="the-unchecked-checkbox" value="cb-val"/>
- <textarea id="the-textarea">original notes</textarea>
+ <textarea id="the-textarea"></textarea>
<input type="file" id="the-file" />
</form>
@@ -53,7 +53,12 @@
}
$('#' + $result_id).text($change_registry[this.id]);
- })
+ });
+
+ $results.click(function () {
+ $results.empty();
+ $change_registry = {};
+ });
});
</script>
</body>
Please sign in to comment.
Something went wrong with that request. Please try again.