Skip to content

Commit

Permalink
Fix auto test
Browse files Browse the repository at this point in the history
  • Loading branch information
jorikfon committed Sep 20, 2024
1 parent fcd7ffb commit 839edae
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
28 changes: 27 additions & 1 deletion tests/AdminCabinet/Lib/MikoPBXTestsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ protected function waitForAjax(): void
}
}

/**
* Wait until datatable draw
* @param $datatableId
* @param $timeoutInSeconds
* @return void
* @throws Exception
*/
protected function waitForDataTableDraw(string $datatableId, int $timeoutInSeconds = 10)
{
$endTime = time() + $timeoutInSeconds;
while (time() < $endTime) {
$isDrawComplete = self::$driver->executeScript("
var table = $('#$datatableId').DataTable();
return table && table.draw && table.draw(false) !== undefined;
");
if ($isDrawComplete) {
return;
}
usleep(500000);
}
throw new \Exception("Timeout waiting for DataTable draw to complete.");
}

/**
* Fails a test with the given message.
*
Expand Down Expand Up @@ -724,7 +747,7 @@ protected function checkIfElementExistOnDropdownMenu(string $name, string $value
*
* @return void
*/
protected function fillDataTableSearchInput(string $name, string $value): void
protected function fillDataTableSearchInput(string $datatableId, string $name, string $value): void
{

self::annotate("Test action: Fill datatable search input field $name with value=$value");
Expand All @@ -738,6 +761,9 @@ protected function fillDataTableSearchInput(string $name, string $value): void

// Wait for any AJAX calls to complete
$this->waitForAjax();

// Wait for DataTableDraw
$this->waitForDataTableDraw($datatableId,10);
}

/**
Expand Down
15 changes: 8 additions & 7 deletions tests/AdminCabinet/Tests/ChangeExtensionsSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testChangeExtension(array $params):void
{
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');
// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table','global-search', $params['username']);

$this->clickModifyButtonOnRowWithText($params['username']);
$this->changeInputField('number', $params['number']);
Expand Down Expand Up @@ -90,7 +90,7 @@ public function testChangeMobile(array $params):void

$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');
// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);

$this->clickModifyButtonOnRowWithText($params['username']);
$this->changeInputField('mobile_number', $params['mobile']);
Expand Down Expand Up @@ -131,7 +131,8 @@ public function testClearMobile(array $params):void
{
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');
// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);


$this->clickModifyButtonOnRowWithText($params['username']);
$this->changeInputField('mobile_number', '');
Expand Down Expand Up @@ -172,7 +173,7 @@ public function testChangeEmail(array $params):void
{
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');
// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);

$this->clickModifyButtonOnRowWithText($params['username']);

Expand Down Expand Up @@ -203,7 +204,7 @@ public function testClearEmail(array $params):void
{
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');
// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);

$this->clickModifyButtonOnRowWithText($params['username']);

Expand Down Expand Up @@ -233,7 +234,7 @@ public function testChangeForwarding(array $params): void
{
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');
// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);

$this->clickModifyButtonOnRowWithText($params['username']);

Expand Down Expand Up @@ -273,7 +274,7 @@ public function testChangeExtensions(array $params): void
{
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');
// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);

$this->clickModifyButtonOnRowWithText($params['username']);

Expand Down
4 changes: 2 additions & 2 deletions tests/AdminCabinet/Tests/CreateExtensionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testCreateExtensions(array $params): void
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');

// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);

// Delete any existing extension with the same username
$this->clickDeleteButtonOnRowWithText($params['username']);
Expand Down Expand Up @@ -105,7 +105,7 @@ function () {
// Navigate back to the extensions page
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');
// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);
$this->clickModifyButtonOnRowWithText($params['username']);

// Assert input field values
Expand Down
6 changes: 3 additions & 3 deletions tests/AdminCabinet/Tests/DeleteExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testDeleteExtension(array $params): void
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');

// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);
$this->clickModifyButtonOnRowWithText($params['username']);

// TESTS
Expand All @@ -62,12 +62,12 @@ public function testDeleteExtension(array $params): void
$this->clickSidebarMenuItemByHref('/admin-cabinet/extensions/index/');

// Fill search field
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);
$this->clickDeleteButtonOnRowWithText($params['username']);
$this->waitForAjax();

// Try to find element with ID on page
$this->fillDataTableSearchInput('global-search', $params['username']);
$this->fillDataTableSearchInput('extensions-table', 'global-search', $params['username']);
$xpath = "//table[@id='extensions-table']//tr[@id='{$elementID}']";
$els = self::$driver->findElements(WebDriverBy::xpath($xpath));

Expand Down

0 comments on commit 839edae

Please sign in to comment.