Skip to content

Commit

Permalink
Dev: Finish ranking test
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Oct 7, 2019
1 parent 27e2001 commit 017cc15
Showing 1 changed file with 80 additions and 49 deletions.
129 changes: 80 additions & 49 deletions tests/surveys/RankingArrayFilterMaxColumnTest.php
Expand Up @@ -30,8 +30,6 @@ public static function setupBeforeClass()
*/
public function testRanking()
{
$this->markTestSkipped();

/** @var string */
$url = $this->getSurveyUrl();

Expand All @@ -57,38 +55,23 @@ public function testRanking()
$web->next();

/** @var string Answer id to first subquestion. */
$answerId = 'javatbd'
. self::$surveyId
. 'X' . $survey->groups[0]->gid
. 'X'
. $survey->groups[0]->questions[0]->qid
. '1';
$answerId = $this->getAnswerId($survey) . '1';

// Click it.
/** @var RemoteWebElement */
$label = $web->findByCss('#' . $answerId . ' label');
$label->click();

/** @var string Answer id to second subquestion. */
$answerId = 'javatbd'
. self::$surveyId
. 'X' . $survey->groups[0]->gid
. 'X'
. $survey->groups[0]->questions[0]->qid
. '2';
$answerId = $this->getAnswerId($survey) . '2';

// Click it.
/** @var RemoteWebElement */
$label = $web->findByCss('#' . $answerId . ' label');
$label->click();

/** @var string Answer id to third subquestion. */
$answerId = 'javatbd'
. self::$surveyId
. 'X' . $survey->groups[0]->gid
. 'X'
. $survey->groups[0]->questions[0]->qid
. '3';
$answerId = $this->getAnswerId($survey) . '3';

// Click it.
/** @var RemoteWebElement */
Expand All @@ -100,44 +83,92 @@ public function testRanking()
sleep(1);

/** @var string List item id to first answer option. */
$liId = 'javatbd'
. self::$surveyId
. 'X' . $survey->groups[1]->gid
. 'X'
. $survey->groups[1]->questions[0]->qid
. '1';

/** @var RemoteWebElement */
$li = $web->findById($liId);
$dropZone = $web->findById('sortable-rank-' . $survey->groups[1]->questions[0]->qid);
$sgqa1 = $this->getItemListId($survey) . '1';

// TODO: Can't use mouse with geckodriver and Selenium?
sleep(1);
//$web->getMouse()->mouseMove($li->getCoordinates());
//$web->action()->moveToElement($li)->perform();
//$web
//->action()
//->moveToElement($li)
//->clickAndHold($li)
//->moveToElement($dropZone)
//->release($dropZone)
//->perform();

//$web->getMouse()
//->mouseDown($li->getCoordinates())
//->mouseMove($dropZone->getCoordinates())
//->mouseUp($dropZone->getCoordinates());
sleep(3);
// NB: Couldn't get mouse to work, use JS to simulate double click.
/** @var string */
$javascript = $this->getJavascriptDoubleClick($sgqa1);
/** @var string */
$result = $web->executeAsyncScript($javascript, []);
$this->assertEquals('done', $result);
sleep(1);

/** @var string List item id to second answer option. */
$sgqa2 = $this->getItemListId($survey) . '2';

/** @var string */
$javascript = $this->getJavascriptDoubleClick($sgqa2);
/** @var string */
$result = $web->executeAsyncScript($javascript, []);
$this->assertEquals('done', $result);
sleep(1);

// Submit survey.
$web->submit();

// Check that answer was recorded correctly.

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Oct 8, 2019

Collaborator

For next Test system : maybe we can

  1. Add a <span is='checkValue'>{rank_1.NAOK}</span> in same page and check it's updated to the good value (JS check)
  2. Move next and add <span is='checkValue'>{rank_1.NAOK}</span> in end page : i think it this check the DB + $_SESSION

This comment has been minimized.

Copy link
@olleharstedt

olleharstedt Oct 8, 2019

Author Contributor

Hm

This comment has been minimized.

Copy link
@olleharstedt

olleharstedt Oct 8, 2019

Author Contributor

Is this related to all question on one page mode?

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Oct 8, 2019

Collaborator

No, it's just maybe a better solution to check if value is sent to PHP and saved in SQL. I use it on another Test.
In my opinion : it's more easy. But did it really check SQL save ?

There are NO issue in your test :) (or … i don't see it ;) )

This comment has been minimized.

Copy link
@olleharstedt

olleharstedt Oct 8, 2019

Author Contributor

Alright :)

/** @var string */
$query = sprintf('SELECT * FROM {{survey_%d}}', $survey->sid);
/** @var CDbConnection */
$dbo = \Yii::app()->getDb();
/** @var array */
$answers = $dbo->createCommand($query)->queryAll();
$this->assertCount(1, $answers);
$this->assertEquals('1', $answers[0][$sgqa1]);
$this->assertEquals('2', $answers[0][$sgqa2]);
} catch (\Exception $ex) {
self::$testHelper->takeScreenshot(self::$webDriver, __CLASS__ . '_' . __FUNCTION__);
$this->assertFalse(
true,
self::$testHelper->javaTrace($ex)
);
}
// fill in first question
// fill in second question
// submit
// check database result
}

/**
* Answer id to subquestion
*
* @param Survey $survey
* @return string
*/
protected function getAnswerId(\Survey $survey)
{
return 'javatbd'
. self::$surveyId
. 'X' . $survey->groups[0]->gid
. 'X'
. $survey->groups[0]->questions[0]->qid;
}

/**
* @param Survey $survey
* @return string
*/
protected function getItemListId(\Survey $survey)
{
return self::$surveyId
. 'X' . $survey->groups[1]->gid
. 'X'
. $survey->groups[1]->questions[0]->qid;
}

/**
* @param string $id
* @return string
*/
protected function getJavascriptDoubleClick($id)
{
return <<<END_JAVASCRIPT
var callback = arguments[arguments.length-1],
event = new MouseEvent('dblclick', {
'view': window,
'bubbles': true,
'cancelable': true
});
document.getElementById('javatbd$id').dispatchEvent(event);
callback('done');
END_JAVASCRIPT;
}
}

0 comments on commit 017cc15

Please sign in to comment.