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

Fix tests - do not rely on hardcoded/expected names #1245

Merged
merged 31 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b0ed358
init
ibelar Jun 5, 2020
ff3bd91
Apply fixes from StyleCI
ibelar Jun 5, 2020
3a9e2f0
wip
ibelar Jun 5, 2020
b2a5c41
Merge branch 'fix/unit-test-url' of https://github.com/atk4/ui into f…
ibelar Jun 5, 2020
aad6639
clean up unit test - add behat test
ibelar Jun 5, 2020
aafa316
final test
ibelar Jun 5, 2020
a457659
added basic action executor test in behat
ibelar Jun 5, 2020
71e7b4f
remove template from console output
ibelar Jun 5, 2020
f344249
Fix missing DIContainerTrait when StaticAddToTrait is used
mvorisek Jun 7, 2020
a83dc81
Fix missing DIContainerTrait when StaticAddToTrait is used
mvorisek Jun 7, 2020
78e1d09
Merge branch 'develop' into fix/unit-test-url
mvorisek Jun 7, 2020
6a6b03e
Merge branch 'fix_for_new_factory' into fix/unit-test-url
mvorisek Jun 7, 2020
5e4b2af
extra changes for merge
mvorisek Jun 7, 2020
035e349
Merge branch 'fix/unit-test-url' of https://github.com/atk4/ui into f…
ibelar Jun 7, 2020
e04b328
fix hardcode column name
ibelar Jun 7, 2020
0a72253
Apply fixes from StyleCI
ibelar Jun 7, 2020
a2d2a61
cs fixer
ibelar Jun 7, 2020
37a3b67
move utility function to trait
ibelar Jun 8, 2020
8a8d6a4
cs fixer
ibelar Jun 8, 2020
27a3f75
adding behat test for grid search
ibelar Jun 8, 2020
34daf33
refine search to kingdom only
ibelar Jun 8, 2020
5fc3b5c
wait for toast to hide
ibelar Jun 8, 2020
036291f
add crud testing in behat
ibelar Jun 8, 2020
cd275e2
replace jsNotify coverage
ibelar Jun 8, 2020
18bebc2
Merge branch 'develop' into fix/unit-test-url
ibelar Jun 9, 2020
959ba1b
Fix CS fixer config for "Callable" class
mvorisek Jun 10, 2020
30ca774
Refactor "I Wait x" to "I sleep x ms"
mvorisek Jun 10, 2020
2225c32
add FeatureContext::getSession() return type
mvorisek Jun 10, 2020
4a99f03
fix CS
mvorisek Jun 10, 2020
8c03449
add NS to FeatureContext
mvorisek Jun 10, 2020
3899e7a
fix bootstrap autoload/path
mvorisek Jun 10, 2020
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
20 changes: 20 additions & 0 deletions demos/_unit-test/console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
mvorisek marked this conversation as resolved.
Show resolved Hide resolved

namespace atk4\ui\demo;

use atk4\ui\jsSSE;

require_once __DIR__ . '/../atk-init.php';

$sse = jsSSE::addTo($app);
$sse->urlTrigger = 'console_test';

$console = \atk4\ui\Console::addTo($app, ['sse' => $sse]);

$console->set(function ($console) {
$console->output('Executing test process...');
$console->output('Now trying something dangerous..');
echo 'direct output is captured';

throw new \atk4\core\Exception('BOOM - exceptions are caught');
});
13 changes: 13 additions & 0 deletions demos/_unit-test/console_exec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\jsSSE;

require_once __DIR__ . '/../atk-init.php';

$sse = jsSSE::addTo($app);
$sse->urlTrigger = 'console_test';

$console = \atk4\ui\Console::addTo($app, ['sse' => $sse]);
$console->exec('/bin/pwd');
33 changes: 33 additions & 0 deletions demos/_unit-test/console_run.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\jsSSE;

require_once __DIR__ . '/../atk-init.php';

$testRun = get_class(new class() extends \atk4\data\Model {
use \atk4\core\DebugTrait;
use \atk4\core\StaticAddToTrait;

public function test()
{
$this->log('info', 'Console will automatically pick up output from all DebugTrait objects');
$this->debug('debug test');
$this->emergency('emergency {foo}', ['foo' => 'bar']);
mvorisek marked this conversation as resolved.
Show resolved Hide resolved
$this->alert('alert {foo}', ['foo' => 'bar']);
$this->critical('critical {foo}', ['foo' => 'bar']);
$this->error('error {foo}', ['foo' => 'bar']);
$this->warning('warning {foo}', ['foo' => 'bar']);
$this->notice('notice {foo}', ['foo' => 'bar']);
$this->info('info {foo}', ['foo' => 'bar']);

return 123;
}
});

$sse = jsSSE::addTo($app);
$sse->urlTrigger = 'console_test';

$console = \atk4\ui\Console::addTo($app, ['sse' => $sse]);
$console->runMethod($testRun::addTo($app), 'test');
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

namespace atk4\ui\demo;

use atk4\ui\CallbackLater;

require_once __DIR__ . '/../atk-init.php';

// JUST TO TEST Exceptions and Error throws

$modal = \atk4\ui\Modal::addTo($app);
$cb = CallbackLater::addTo($app);
$cb->urlTrigger = 'm_cb';

$modal = \atk4\ui\Modal::addTo($app, ['cb' => $cb]);
$modal->name = 'm_test';

$modal->set(function ($m) use ($modal) {
throw new \Exception('TEST!');
Expand All @@ -15,7 +21,10 @@
$button = \atk4\ui\Button::addTo($app, ['Test modal exception']);
$button->on('click', $modal->show());

$modal2 = \atk4\ui\Modal::addTo($app);
$cb1 = CallbackLater::addTo($app);

$cb1->urlTrigger = 'm2_cb';
$modal2 = \atk4\ui\Modal::addTo($app, ['cb' => $cb1]);

$modal2->set(function ($m) use ($modal2) {
trigger_error('error triggered');
Expand Down
17 changes: 17 additions & 0 deletions demos/_unit-test/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\Form;
use atk4\ui\jsToast;

require_once __DIR__ . '/../atk-init.php';

$f = Form::addTo($app);
$f->name = 'test_form';

$f->addField('f1')->set('v1');

$f->onSubmit(function ($f) {
return new jsToast('Post ok');
});
24 changes: 24 additions & 0 deletions demos/_unit-test/reload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\Button;
use atk4\ui\Callback;
use atk4\ui\jsReload;
use atk4\ui\View;

require_once __DIR__ . '/../atk-init.php';

$v = View::addTo($app, ['ui' => 'segment']);
$v->set('Test');
$v->name = 'reload';

$b = Button::addTo($app)->set('Reload');
$b->on('click', new jsReload($v));

$cb = Callback::addTo($app);
$cb->urlTrigger = 'c_reload';

\atk4\ui\Loader::addTo($app, ['cb' => $cb])->set(function ($page) {
$v = View::addTo($page, ['ui' => 'segment'])->set('loaded');
});
24 changes: 24 additions & 0 deletions demos/_unit-test/sse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\jsExpression;
use atk4\ui\View;

require_once __DIR__ . '/../atk-init.php';

$v = View::addTo($app)->set('This will trigger a network request for testing sse...');

$sse = \atk4\ui\jsSSE::addTo($app);
// url trigger must match php_unit test in sse provider.
$sse->urlTrigger = 'see_test';

$v->js(true, $sse->set(function () use ($sse) {
$sse->send(new jsExpression('console.log("test")'));
$sse->send(new jsExpression('console.log("test")'));
$sse->send(new jsExpression('console.log("test")'));
$sse->send(new jsExpression('console.log("test")'));

// non-SSE way
return $sse->send(new jsExpression('console.log("test")'));
}));
3 changes: 0 additions & 3 deletions demos/atk-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
$app->initLayout($app->stickyGET('layout') ?: \atk4\ui\Layout\Maestro::class);

$layout = $app->layout;
// Need for phpunit only for producing right url.
$layout->name = 'atk_admin';
$layout->id = $layout->name;

if ($layout instanceof \atk4\ui\Layout\Navigable) {
$layout->addMenuItem(['Welcome to Agile Toolkit', 'icon' => 'gift'], [$demosUrl . 'index']);
Expand Down
3 changes: 2 additions & 1 deletion demos/collection/tablefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

//For popup positioning to work correctly, table need to be inside a view segment.
$view = \atk4\ui\View::addTo($app, ['ui' => 'basic segment']);
$g = \atk4\ui\Grid::addTo($view);
// Important: menu class added for Behat testing.
$g = \atk4\ui\Grid::addTo($view, ['menu' => ['class' => ['atk-grid-menu']]]);

$m = new CountryLock($db);
$m->addExpression('is_uk', $m->expr('if([iso] = [country], 1, 0)', ['country' => 'GB']))->type = 'boolean';
Expand Down
8 changes: 5 additions & 3 deletions demos/interactive/card-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace atk4\ui\demo;

use atk4\ui\Button;

require_once __DIR__ . '/../atk-init.php';

\atk4\ui\Button::addTo($app, ['Card Deck', 'small right floated basic blue', 'iconRight' => 'right arrow'])
Expand All @@ -25,10 +27,10 @@
'args' => [
'note' => ['type' => 'string', 'required' => true],
],
'callback' => function ($m) {
return 'Note to client is sent.';
'callback' => function ($m, $note) {
return 'Note to client is sent: ' . $note;
},
]);
$c->addSection('Client Country:', $client, ['iso', 'numcode', 'phonecode'], true);

$c->addClickAction($notify, null, [$client->get('id')]);
$c->addClickAction($notify, new Button(['Send Note']), [$client->get('id')]);
6 changes: 4 additions & 2 deletions demos/interactive/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace atk4\ui\demo;

use atk4\ui\Callback;
use atk4\ui\Wizard;

require_once __DIR__ . '/../atk-init.php';

/**
* Demonstrates how to use a wizard.
*/
$t = Wizard::addTo($app);

$t = Wizard::addTo($app, ['stepCallback' => Callback::addTo($app, ['urlTrigger' => 'demo_wizard'])]);
// First step will automatcally be active when you open page first. It
// will contain the 'Next' button with a link.
$t->addStep('Welcome', function (Wizard $w) {
Expand All @@ -26,6 +26,8 @@
// to store wizard-specific variables
$t->addStep(['Set DSN', 'icon' => 'configure', 'description' => 'Database Connection String'], function (Wizard $w) {
$f = \atk4\ui\Form::addTo($w);
// IMPORTANT - needed for php_unit Wizard test.
$f->name = 'w_form';

$f->addField('dsn', 'Connect DSN', ['required' => true])->placeholder = 'mysql://user:pass@db-host.example.com/mydb';
$f->onSubmit(function (\atk4\ui\Form $form) use ($w) {
Expand Down
44 changes: 44 additions & 0 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ public function iPressButton($arg1)
$button->click();
}

/**
* @Then I press menu button :arg1 using class :arg2
*/
public function iPressMenuButtonUsingClass($arg1, $arg2)
{
$menu = $this->getSession()->getPage()->find('css', '.ui.menu.' . $arg2);
if (!$menu) {
throw new \Exception('Unable to find a menu with class ' . $arg2);
}

$link = $menu->find('xpath', '//a[text()="' . $arg1 . '"]');
if (!$link) {
throw new \Exception('Unable to find menu with title ' . $arg1);
}

$script = '$("#' . $link->getAttribute('id') . '").click()';
$this->getSession()->executeScript($script);
}

/**
* @Given I click link :arg1
*/
Expand All @@ -75,6 +94,20 @@ public function iClickLink($arg1)
$link->click();
}

/**
* @Then I click filter column name :arg1
*/
public function iClickFilterColumnName($arg1)
{
$column = $this->getSession()->getPage()->find('css', "th[data-column='" . $arg1 . "']");
if (!$column) {
throw new \Exception('Unable to find a column ' . $arg1);
}
$icon = $column->find('css', 'i');
$script = '$("#' . $icon->getAttribute('id') . '").click()';
$this->getSession()->executeScript($script);
}

/**
* @Given I click tab with title :arg1
*
Expand Down Expand Up @@ -182,6 +215,17 @@ public function modalIsOpenWithText($arg1)
}
}

/**
* @Then Active tab should be :arg1
*/
public function activeTabShouldBe($arg1)
{
$tab = $this->getSession()->getPage()->find('css', '.ui.tabular.menu > .item.active');
if ($tab->getText() !== $arg1) {
throw new \Exception('Active tab is not ' . $arg1);
}
}

/**
* @Then Modal is showing text :arg1 inside tag :arg2
*
Expand Down
12 changes: 12 additions & 0 deletions features/card.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Card
Testing card with model action

Scenario:
Given I am on "interactive/card-action.php"
And I press button "Send Note"
And wait for callback
Then Modal is showing text "Note" inside tag "label"
When I fill in "note" with "This is a test note"
Then I press Modal button "Notify"
And wait for callback
Then Toast display should contains text "This is a test note"
10 changes: 9 additions & 1 deletion features/filter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ Feature: Filter
Scenario:
Given I am on "collection/tablefilter.php"
Then I should see "Clear Filters"

Then I click filter column name "name"
When I fill in "value" with "united kingdom"
Then I press button "Set"
And wait for callback
And wait for callback
Then I should see "United Kingdom"
Then I press menu button "Clear Filters" using class "atk-grid-menu"
And wait for callback
Then I should see "Australia"
11 changes: 11 additions & 0 deletions features/tab.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Tab
Testing Tab

Scenario:
Given I am on "interactive/tabs.php"
And wait for callback
Then Active tab should be "Default Active Tab"
Then I should see "This is the active tab by default"
Then I click tab with title "Dynamic Lorem Ipsum"
And wait for callback
Then I should see "you will see a different text"
5 changes: 4 additions & 1 deletion src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public function set($callback = null, $event = null)
$this->event = $event;
}

$this->sse = jsSSE::addTo($this);
if (!$this->sse) {
$this->sse = jsSSE::addTo($this);
}

$this->sse->set(function () use ($callback) {
$this->sseInProgress = true;

Expand Down
4 changes: 3 additions & 1 deletion src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public function init(): void
$this->shim = [View::class, 'class' => ['padded segment'], 'style' => ['min-height' => '7em']];
}

$this->cb = Callback::addTo($this, ['appSticky' => $this->appStickyCb]);
if (!$this->cb) {
$this->cb = Callback::addTo($this, ['appSticky' => $this->appStickyCb]);
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public function enableCallback()
{
$this->cb_view = View::addTo($this);
$this->cb_view->stickyGet('__atk_m', $this->name);
$this->cb = CallbackLater::addTo($this->cb_view, ['appSticky' => $this->appStickyCb]);
if (!$this->cb) {
$this->cb = CallbackLater::addTo($this->cb_view, ['appSticky' => $this->appStickyCb]);
}

$this->cb->set(function () {
if ($this->cb->triggered() && $this->fx) {
Expand Down
7 changes: 5 additions & 2 deletions src/Wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Wizard extends View
/**
* Callback, that triggers selection of a step.
*
* @var callable
* @var callback
mvorisek marked this conversation as resolved.
Show resolved Hide resolved
*/
public $stepCallback;

Expand Down Expand Up @@ -60,7 +60,10 @@ class Wizard extends View
public function init(): void
{
parent::init();
$this->stepCallback = Callback::addTo($this, ['urlTrigger' => $this->name]);

if (!$this->stepCallback) {
$this->stepCallback = Callback::addTo($this, ['urlTrigger' => $this->name]);
}

$this->currentStep = (int) $this->stepCallback->triggered() ?: 0;

Expand Down
Loading