Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve display test result #44

Merged
merged 5 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions admin/pages/connections/odoo_connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ protected function handle_route($action)

private function test_connection($id)
{
show_message(json_encode(odoo_conn_test_odoo_connection(
["id" => $id]
)));
$test_result = odoo_conn_test_odoo_connection(
["id" => $id]
);
$this->display_test_connection_result($test_result);
}

protected function display_test_connection_result($test_result)
{
// $test_result variable is used in the test_connection_result.php file.
wp_enqueue_style("test-connection-result", plugins_url("test_connection_result.css", __FILE__));
require_once "test_connection_result.php";
}

protected function display_input_form()
{
require_once "odoo_connection_input_form.php";
Expand Down
15 changes: 15 additions & 0 deletions admin/pages/connections/test_connection_result.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

.odoo-conn-message-notification-box {
background-color: #fff;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
border: 1px solid #c3c4c7;
padding: 8px 10px;
}

.test-result-ok {
background: #ddffdd;
}

.test-result-failure {
background: #ffdddd;
}
22 changes: 22 additions & 0 deletions admin/pages/connections/test_connection_result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
$test_result = $test_result ?? null;
if (!is_null($test_result)) {
$connection_result_class = $test_result['success'] ? 'test-result-ok' : 'test-result-failure'
?>
<div class="wrap odoo-conn-message-notification-box <?= $connection_result_class ?>">
<h1>Test Result: <?= $test_result['success'] ? 'Success' : 'Failure' ?> </h1>

<?php if (!$test_result['success']) { ?>
<!-- Display error details on failure -->
<div>
<b>Error Message: </b>
<span><?= esc_html__($test_result['error_string']) ?></span>
</div>

<div>
<b>Error Code: </b>
<span><?= esc_html__($test_result['error_code']) ?></span>
</div>
<?php } ?>
</div>
<?php } ?>
2 changes: 1 addition & 1 deletion odoo_conn.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Requires PHP: 8.1
* Text Domain: cf7-odoo-connector
* Requires Plugins: contact-form-7
* Version: 0.1.6
* Version: 0.1.7
*/

// Exit if accessed directly.
Expand Down
22 changes: 18 additions & 4 deletions tests/end_to_end_tests/tests/selenium_tests/Error_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@ public function test_broken_connection_alert()
$test_button->click();
sleep(2);

$expected_error_message = "{\"success\":false,\"error_string\":\"Username or API Key is incorrect\",\"error_code\":0}";
$elements = $this->wait_for_elements(
$this->wait_for_elements(
WebDriverBy::xpath(
"//p[contains(text(), '$expected_error_message')]"
"//h1[contains(text(), 'Test Result: Failure')]"
)
);
$this->assertCount(1, $elements);
$this->driver->findElement(
WebDriverBy::xpath("//b[contains(text(), 'Error Message: ')]")
);
$this->driver->findElement(
WebDriverBy::xpath("//span[contains(text(), 'Username or API Key is incorrect')]")
);
$this->driver->findElement(
WebDriverBy::xpath("//b[contains(text(), 'Error Code: ')]")
);
$this->driver->findElement(
WebDriverBy::xpath("//span[contains(text(), '0')]")
);

// to make the test not appear to be 'risky' as it hasn't made any assertions.
// findElement will raise an exception if the test fails.
$this->assertTrue(true);
}

public function test_broken_send_data()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ function test_request_edit()
$this->odoo_conn_page_router->request();
}

function test_request_test_connection()
{
$GLOBALS['_REQUEST'] = ['page_action' => 'test_connection', 'id' => 3];
$this->odoo_conn_page_router->shouldReceive('display_test_connection_result')->with(
['success' => true]
)->once();
$this->odoo_conn_page_router->shouldReceive('display_table')->once();
Functions\expect('current_user_can')->once()->with(
'administrator'
)->andReturn(true);
Functions\expect(
'odoo_conn\admin\database_connection\odoo_conn_test_odoo_connection'
)->with(
['id' => 3]
)->andReturn(['success' => true]);

$this->odoo_conn_page_router->request();
}

function test_request_other()
{
$GLOBALS['_REQUEST'] = ['id' => 3, 'page_action' => 'other'];
Expand Down
Loading