From b0ed3582b6b399403b29a573d16e44e59d507528 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Fri, 5 Jun 2020 09:29:28 -0400 Subject: [PATCH 01/26] init --- demos/_unit-test/sse_test.php | 44 +++++++++++++++++++++++++++++++++++ tests/DemoCallExitTest.php | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 demos/_unit-test/sse_test.php diff --git a/demos/_unit-test/sse_test.php b/demos/_unit-test/sse_test.php new file mode 100644 index 0000000000..17921507ac --- /dev/null +++ b/demos/_unit-test/sse_test.php @@ -0,0 +1,44 @@ +on('click', $bar->js()->progress(['percent'=> 40])); + +$sse = \atk4\ui\jsSSE::addTo($app, ['showLoader' => true]); +// url trigger must match php_unit test in sse provider. +$sse->urlTrigger = 'see_test'; + +$button->on( + 'click', + $sse->set( + function () use ($button, $sse, $bar) { + $sse->send($button->js()->addClass('disabled')); + + $sse->send($bar->jsValue(20)); + sleep(1); + $sse->send($bar->jsValue(40)); + sleep(1); + $sse->send($bar->jsValue(60)); + sleep(2); + $sse->send($bar->jsValue(80)); + sleep(1); + + // non-SSE way + return [ + $bar->jsValue(100), + $button->js()->removeClass('disabled'), + ]; + } + ) +); + +$btn_stop->on('click', [$button->js()->atkServerEvent('stop'), $button->js()->removeClass('disabled')]); \ No newline at end of file diff --git a/tests/DemoCallExitTest.php b/tests/DemoCallExitTest.php index e640f50dff..fc0be0ef23 100644 --- a/tests/DemoCallExitTest.php +++ b/tests/DemoCallExitTest.php @@ -189,7 +189,7 @@ public function testDemoAssertSSEResponse(string $uri) public function SSEResponseDataProvider() { $files = []; - $files[] = ['interactive/sse.php?atk_admin_jssse=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/sse_test.php?see_test=ajax&__atk_callback=1&__atk_sse=1']; $files[] = ['interactive/console.php?atk_admin_tabs_tabssubview_console_jssse=ajax&__atk_callback=1&__atk_sse=1']; if (!($this instanceof DemoCallExitExceptionTest)) { // ignore content type mismatch when App->call_exit equals to true $files[] = ['interactive/console.php?atk_admin_tabs_tabssubview_2_virtualpage=cut&atk_admin_tabs_tabssubview_2_virtualpage_console_jssse=ajax&__atk_callback=1&__atk_sse=1']; From ff3bd91a62c1a86258eb2df45fa554787a4cd4a6 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Fri, 5 Jun 2020 13:29:49 +0000 Subject: [PATCH 02/26] Apply fixes from StyleCI --- demos/_unit-test/sse_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/_unit-test/sse_test.php b/demos/_unit-test/sse_test.php index 17921507ac..4e6f4cb5dc 100644 --- a/demos/_unit-test/sse_test.php +++ b/demos/_unit-test/sse_test.php @@ -41,4 +41,4 @@ function () use ($button, $sse, $bar) { ) ); -$btn_stop->on('click', [$button->js()->atkServerEvent('stop'), $button->js()->removeClass('disabled')]); \ No newline at end of file +$btn_stop->on('click', [$button->js()->atkServerEvent('stop'), $button->js()->removeClass('disabled')]); From 3a9e2f0d8d49d3a7d2882c32b2032a1e899526f5 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Fri, 5 Jun 2020 12:21:19 -0400 Subject: [PATCH 03/26] wip --- demos/_unit-test/console.php | 20 +++ demos/_unit-test/console_exec.php | 13 ++ demos/_unit-test/console_run.php | 33 +++++ .../{exception_test.php => exception.php} | 13 +- demos/_unit-test/post.php | 17 +++ demos/_unit-test/reload.php | 24 ++++ demos/_unit-test/{sse_test.php => sse.php} | 4 +- demos/interactive/wizard.php | 6 +- src/Console.php | 5 +- src/Loader.php | 4 +- src/Modal.php | 4 +- src/Wizard.php | 7 +- tests/DemoCallExitTest.php | 132 ++++-------------- 13 files changed, 164 insertions(+), 118 deletions(-) create mode 100644 demos/_unit-test/console.php create mode 100644 demos/_unit-test/console_exec.php create mode 100644 demos/_unit-test/console_run.php rename demos/_unit-test/{exception_test.php => exception.php} (63%) create mode 100644 demos/_unit-test/post.php create mode 100644 demos/_unit-test/reload.php rename demos/_unit-test/{sse_test.php => sse.php} (92%) diff --git a/demos/_unit-test/console.php b/demos/_unit-test/console.php new file mode 100644 index 0000000000..f19036e13b --- /dev/null +++ b/demos/_unit-test/console.php @@ -0,0 +1,20 @@ +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'); +}); diff --git a/demos/_unit-test/console_exec.php b/demos/_unit-test/console_exec.php new file mode 100644 index 0000000000..ca1250e96e --- /dev/null +++ b/demos/_unit-test/console_exec.php @@ -0,0 +1,13 @@ +urlTrigger = 'console_test'; + +$console = \atk4\ui\Console::addTo($app, ['sse' => $sse]); +$console->exec('/bin/pwd'); diff --git a/demos/_unit-test/console_run.php b/demos/_unit-test/console_run.php new file mode 100644 index 0000000000..c2ec8a85b4 --- /dev/null +++ b/demos/_unit-test/console_run.php @@ -0,0 +1,33 @@ +log('info', 'Console will automatically pick up output from all DebugTrait objects'); + $this->debug('debug {foo}', ['foo' => 'bar']); + $this->emergency('emergency {foo}', ['foo' => 'bar']); + $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($testConsoleClass::addTo($app), 'generateReport'); diff --git a/demos/_unit-test/exception_test.php b/demos/_unit-test/exception.php similarity index 63% rename from demos/_unit-test/exception_test.php rename to demos/_unit-test/exception.php index 838215fbb6..03ff107718 100644 --- a/demos/_unit-test/exception_test.php +++ b/demos/_unit-test/exception.php @@ -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!'); @@ -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'); diff --git a/demos/_unit-test/post.php b/demos/_unit-test/post.php new file mode 100644 index 0000000000..79eb7d063b --- /dev/null +++ b/demos/_unit-test/post.php @@ -0,0 +1,17 @@ +name = 'test_form'; + +$f->addField('f1')->set('v1'); + +$f->onSubmit(function ($f) { + return new jsToast('Post ok'); +}); diff --git a/demos/_unit-test/reload.php b/demos/_unit-test/reload.php new file mode 100644 index 0000000000..4b7bbdd617 --- /dev/null +++ b/demos/_unit-test/reload.php @@ -0,0 +1,24 @@ + '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'); +}); diff --git a/demos/_unit-test/sse_test.php b/demos/_unit-test/sse.php similarity index 92% rename from demos/_unit-test/sse_test.php rename to demos/_unit-test/sse.php index 17921507ac..bf31a27b42 100644 --- a/demos/_unit-test/sse_test.php +++ b/demos/_unit-test/sse.php @@ -8,7 +8,7 @@ $bar = \atk4\ui\ProgressBar::addTo($app); -$button = \atk4\ui\Button::addTo($app, ['Turn On']); +$button = \atk4\ui\Button::addTo($app, ['Turn On']); $btn_stop = \atk4\ui\Button::addTo($app, ['Turn Off']); // non-SSE way //$button->on('click', $bar->js()->progress(['percent'=> 40])); @@ -41,4 +41,4 @@ function () use ($button, $sse, $bar) { ) ); -$btn_stop->on('click', [$button->js()->atkServerEvent('stop'), $button->js()->removeClass('disabled')]); \ No newline at end of file +$btn_stop->on('click', [$button->js()->atkServerEvent('stop'), $button->js()->removeClass('disabled')]); diff --git a/demos/interactive/wizard.php b/demos/interactive/wizard.php index 03356011f3..097100ec61 100644 --- a/demos/interactive/wizard.php +++ b/demos/interactive/wizard.php @@ -2,6 +2,7 @@ namespace atk4\ui\demo; +use atk4\ui\Callback; use atk4\ui\Wizard; require_once __DIR__ . '/../atk-init.php'; @@ -9,8 +10,7 @@ /** * 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) { @@ -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) { diff --git a/src/Console.php b/src/Console.php index 9bb661f785..366ef04d47 100644 --- a/src/Console.php +++ b/src/Console.php @@ -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; diff --git a/src/Loader.php b/src/Loader.php index 8a6d255d1f..a11d411b69 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -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]); + } } /** diff --git a/src/Modal.php b/src/Modal.php index 3d09cec981..fdebd4e428 100644 --- a/src/Modal.php +++ b/src/Modal.php @@ -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) { diff --git a/src/Wizard.php b/src/Wizard.php index 4774c1399d..c84afbb6c0 100644 --- a/src/Wizard.php +++ b/src/Wizard.php @@ -15,7 +15,7 @@ class Wizard extends View /** * Callback, that triggers selection of a step. * - * @var callable + * @var callback */ public $stepCallback; @@ -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; diff --git a/tests/DemoCallExitTest.php b/tests/DemoCallExitTest.php index fc0be0ef23..44e39da95e 100644 --- a/tests/DemoCallExitTest.php +++ b/tests/DemoCallExitTest.php @@ -108,10 +108,10 @@ public function casesDemoGETDataProvider() public function testWizard() { $response = $this->getResponseFromRequest( - 'interactive/wizard.php?atk_admin_wizard=1&atk_admin_wizard_form_submit=ajax&__atk_callback=1', + 'interactive/wizard.php?demo_wizard=1&w_form_submit=ajax&__atk_callback=1', ['form_params' => [ 'dsn' => 'mysql://root:root@db-host.example.com/atk4', - 'atk_admin_wizard_form_submit' => 'submit', + 'w_form_submit' => 'submit', ]] ); @@ -138,19 +138,21 @@ public function testDemoAssertJSONResponse(string $uri) $this->assertMatchesRegularExpression($this->regexJSON, $response->getBody()->getContents(), ' RegExp error on ' . $uri); } + /** + * Test reload and loader callback. + * + * @return array + */ public function JSONResponseDataProvider() { $files = []; - $files[] = ['others/sticky2.php?__atk_reload=atk_admin_button']; - $files[] = ['others/sticky2.php?atk_admin_loader_callback=ajax&__atk_callback1']; - $files[] = ['collection/actions.php?atk_admin_gridlayout_basic_button_click=ajax&__atk_callback=1']; // need to call this before calls other actions to fill model files - $files[] = ['collection/actions.php?atk_useraction_file_edit_loader_callback=ajax&__atk_callback=1&atk_useraction_file_edit=1&step=fields']; - $files[] = ['obsolete/notify.php?__atk_m=atk_admin_modal&atk_admin_modal_view_callbacklater=ajax&__atk_callback=1&__atk_json=1']; - $files[] = ['interactive/scroll-lister.php?atk_admin_view_2_view_lister_jspaginator=ajax&__atk_callback=1&page=2']; - + // simple reload + $files[] = ['_unit-test/reload.php?__atk_reload=reload']; + // loader callback reload + $files[] = ['_unit-test/reload.php?c_reload=ajax&__atk_callback=1']; // test catch exceptions - $files[] = ['_unit-test/exception_test.php?__atk_m=atk_admin_modal&atk_admin_modal_view_callbacklater=ajax&__atk_callback=1&__atk_json=1']; - $files[] = ['_unit-test/exception_test.php?__atk_m=atk_admin_modal_2&atk_admin_modal_2_view_callbacklater=ajax&__atk_callback=1&__atk_json=1']; + $files[] = ['_unit-test/exception.php?m_cb=ajax&__atk_callback=1&__atk_json=1']; + $files[] = ['_unit-test/exception.php?m2_cb=ajax&__atk_callback=1&__atk_json=1']; return $files; } @@ -186,14 +188,19 @@ public function testDemoAssertSSEResponse(string $uri) } } + /** + * Test jsSSE and Console. + * + * @return array + */ public function SSEResponseDataProvider() { $files = []; - $files[] = ['_unit-test/sse_test.php?see_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['interactive/console.php?atk_admin_tabs_tabssubview_console_jssse=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/sse.php?see_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; if (!($this instanceof DemoCallExitExceptionTest)) { // ignore content type mismatch when App->call_exit equals to true - $files[] = ['interactive/console.php?atk_admin_tabs_tabssubview_2_virtualpage=cut&atk_admin_tabs_tabssubview_2_virtualpage_console_jssse=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['interactive/console.php?atk_admin_tabs_tabssubview_3_virtualpage=cut&atk_admin_tabs_tabssubview_3_virtualpage_console_jssse=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_run.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_exec.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; } return $files; @@ -212,100 +219,11 @@ public function testDemoAssertJSONResponsePOST(string $uri, array $postData) public function JSONResponsePOSTDataProvider() { $files = []; - - // IMPORT FROM FILESYSTEM - // this is needed to populate grid for later calls to row actions - $files[] = [ - 'collection/actions.php?atk_admin_gridlayout_basic_button_click=ajax&__atk_callback=1', - [], - ]; // btn confirm - - $files[] = [ - 'collection/actions.php?atk_admin_gridlayout_argumentform_form_submit=ajax&__atk_callback=1', - [ - 'path' => '.', - 'atk_admin_gridlayout_argumentform_form_submit' => 'submit', - ], - ]; // btn run - // - $files[] = [ - 'collection/actions.php?atk_admin_gridlayout_preview_button_click=ajax&__atk_callback=1', - [], - ]; // btn confirm (console) - // Lines below gives error on Travis - // Error is clear "Exception : record not found" - // like the Model Files is not imported and there no records in table to be loaded - // But few lines above i make the import and if run locally it works perfect - /* - // Grid buttons - $files[] = [ - '/collection/actions.php?atk_admin_crud_edit=cut&atk_admin_crud_edit_form_submit=ajax&atk_admin_crud=1&__atk_callback=1', - [ - 'name' => 'index.php', - 'type' => 'php', - 'parent_folder_id' => '1', - 'atk_admin_crud_edit_form_submit' => 'submit', - ], - ]; // edit - - $files[] = [ - '/collection/actions.php?atk_admin_crud_view_view_paginator=1&__atk_m=atk_admin_crud_modal&atk_admin_crud_modal_view_callbacklater=ajax&atk_admin_crud_modal_view_basic_button_click=ajax&atk_admin_crud_view_table_actions=1&__atk_callback=1', - [], - ]; // download : confirm - */ - // JS ACTIONS - $files[] = [ - 'collection/jsactions.php?atk_admin_jsuseraction=ajax&__atk_callback=1', - [ - 'path' => '.', - ], - ]; - - $files[] = [ - 'collection/jsactions.php?atk_admin_card_view_view_button_jsuseraction=ajax&__atk_callback=1', - [ - ], - ]; - - $files[] = [ - 'obsolete/notify.php?__atk_m=atk_admin_modal&atk_admin_modal_view_callbacklater=ajax&atk_admin_modal_view_form_submit=ajax&__atk_callback=1', - [ - 'name' => 'test', - 'atk_admin_modal_view_form_submit' => 'submit', - ], - ]; - - $files[] = [ - 'obsolete/notify2.php?atk_admin_form_submit=ajax&__atk_callback=1', - [ - 'text' => 'This text will appear in notification', - 'icon' => 'warning sign', - 'color' => 'green', - 'transition' => 'jiggle', - 'width' => '25%', - 'position' => 'topRight', - 'attach' => 'Body', - 'atk_admin_form_submit' => 'submit', - ], - ]; - - $files[] = [ - 'collection/tablefilter.php?atk_admin_view_grid_view_filterpopup_5_form_submit=ajax&__atk_callback=1', - [ - 'op' => '=', - 'value' => '374', - 'range' => '', - 'atk_admin_view_grid_view_filterpopup_5_form_submit' => 'submit', - ], - ]; - $files[] = [ - 'collection/tablefilter.php?atk_admin_view_grid_view_filterpopup_4_form_submit=ajax&__atk_callback=1', + '_unit-test/post.php?test_form_submit=ajax&__atk_callback=1', [ - 'op' => 'between', - 'value' => '10', - 'range' => '20', - 'atk_admin_view_grid_view_filterpopup_4_form_submit' => 'submit', + 'f1' => 'v1', + 'test_form_submit' => 'submit', ], ]; From aad663947d00be20fec48ce533b82b7b679ef4fb Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Fri, 5 Jun 2020 15:24:32 -0400 Subject: [PATCH 04/26] clean up unit test - add behat test --- demos/_unit-test/console_run.php | 8 ++--- demos/_unit-test/sse.php | 46 ++++++++------------------- demos/collection/tablefilter.php | 3 +- demos/interactive/card-action.php | 8 +++-- features/bootstrap/FeatureContext.php | 44 +++++++++++++++++++++++++ features/card.feature | 12 +++++++ features/filter.feature | 10 +++++- features/tab.feature | 11 +++++++ 8 files changed, 100 insertions(+), 42 deletions(-) create mode 100644 features/card.feature create mode 100644 features/tab.feature diff --git a/demos/_unit-test/console_run.php b/demos/_unit-test/console_run.php index c2ec8a85b4..52b639dbf6 100644 --- a/demos/_unit-test/console_run.php +++ b/demos/_unit-test/console_run.php @@ -6,14 +6,14 @@ require_once __DIR__ . '/../atk-init.php'; -$testConsoleClass = get_class(new class() extends \atk4\data\Model { +$testRun = get_class(new class() extends \atk4\data\Model { use \atk4\core\DebugTrait; use \atk4\core\StaticAddToTrait; - public function generateReport() + public function test() { $this->log('info', 'Console will automatically pick up output from all DebugTrait objects'); - $this->debug('debug {foo}', ['foo' => 'bar']); + $this->debug('debug test'); $this->emergency('emergency {foo}', ['foo' => 'bar']); $this->alert('alert {foo}', ['foo' => 'bar']); $this->critical('critical {foo}', ['foo' => 'bar']); @@ -30,4 +30,4 @@ public function generateReport() $sse->urlTrigger = 'console_test'; $console = \atk4\ui\Console::addTo($app, ['sse' => $sse]); -$console->runMethod($testConsoleClass::addTo($app), 'generateReport'); +$console->runMethod($testRun::addTo($app), 'test'); diff --git a/demos/_unit-test/sse.php b/demos/_unit-test/sse.php index bf31a27b42..baacd4aae3 100644 --- a/demos/_unit-test/sse.php +++ b/demos/_unit-test/sse.php @@ -2,43 +2,23 @@ namespace atk4\ui\demo; -require_once __DIR__ . '/../atk-init.php'; - -\atk4\ui\Header::addTo($app, ['SSE with ProgressBar']); +use atk4\ui\jsExpression; +use atk4\ui\View; -$bar = \atk4\ui\ProgressBar::addTo($app); +require_once __DIR__ . '/../atk-init.php'; -$button = \atk4\ui\Button::addTo($app, ['Turn On']); -$btn_stop = \atk4\ui\Button::addTo($app, ['Turn Off']); -// non-SSE way -//$button->on('click', $bar->js()->progress(['percent'=> 40])); +$v = View::addTo($app)->set('This will trigger a network request for testing sse...'); -$sse = \atk4\ui\jsSSE::addTo($app, ['showLoader' => true]); +$sse = \atk4\ui\jsSSE::addTo($app); // url trigger must match php_unit test in sse provider. $sse->urlTrigger = 'see_test'; -$button->on( - 'click', - $sse->set( - function () use ($button, $sse, $bar) { - $sse->send($button->js()->addClass('disabled')); - - $sse->send($bar->jsValue(20)); - sleep(1); - $sse->send($bar->jsValue(40)); - sleep(1); - $sse->send($bar->jsValue(60)); - sleep(2); - $sse->send($bar->jsValue(80)); - sleep(1); - - // non-SSE way - return [ - $bar->jsValue(100), - $button->js()->removeClass('disabled'), - ]; - } - ) -); +$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")')); -$btn_stop->on('click', [$button->js()->atkServerEvent('stop'), $button->js()->removeClass('disabled')]); + // non-SSE way + return $sse->send(new jsExpression('console.log("test")')); +})); diff --git a/demos/collection/tablefilter.php b/demos/collection/tablefilter.php index 639354062c..d957b8fd32 100644 --- a/demos/collection/tablefilter.php +++ b/demos/collection/tablefilter.php @@ -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'; diff --git a/demos/interactive/card-action.php b/demos/interactive/card-action.php index 31c5cc4290..39860a1765 100644 --- a/demos/interactive/card-action.php +++ b/demos/interactive/card-action.php @@ -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']) @@ -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')]); diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 5531835b1f..d7251e64d8 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -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 */ @@ -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 * @@ -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 * diff --git a/features/card.feature b/features/card.feature new file mode 100644 index 0000000000..47a702c02b --- /dev/null +++ b/features/card.feature @@ -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" diff --git a/features/filter.feature b/features/filter.feature index 70aca79ff5..900c0480e3 100644 --- a/features/filter.feature +++ b/features/filter.feature @@ -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" diff --git a/features/tab.feature b/features/tab.feature new file mode 100644 index 0000000000..7c034f352e --- /dev/null +++ b/features/tab.feature @@ -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" From aafa31614eaa8cf42aef849d9865891607650286 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Fri, 5 Jun 2020 15:35:17 -0400 Subject: [PATCH 05/26] final test Will confirm all works --- demos/atk-init.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/demos/atk-init.php b/demos/atk-init.php index 548ec053ee..63883eb029 100644 --- a/demos/atk-init.php +++ b/demos/atk-init.php @@ -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']); From a4576590264e621750761babe3e6e11cd324f25a Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Fri, 5 Jun 2020 16:52:13 -0400 Subject: [PATCH 06/26] added basic action executor test in behat --- demos/collection/actions.php | 12 +++++++----- features/basicexecutor.feature | 24 ++++++++++++++++++++++++ features/bootstrap/FeatureContext.php | 3 +++ 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 features/basicexecutor.feature diff --git a/demos/collection/actions.php b/demos/collection/actions.php index 2d4cf629ba..fed02eaeb5 100644 --- a/demos/collection/actions.php +++ b/demos/collection/actions.php @@ -2,6 +2,8 @@ namespace atk4\ui\demo; +use atk4\ui\Button; + require_once __DIR__ . '/../atk-init.php'; \atk4\ui\Button::addTo($app, ['js Event Executor', 'small right floated basic blue', 'iconRight' => 'right arrow']) @@ -39,13 +41,13 @@ $app->add($grid = new \atk4\ui\GridLayout(['columns' => 3])); -$grid->add($executor = new \atk4\ui\ActionExecutor\Basic(), 'r1c1'); +$grid->add($executor = new \atk4\ui\ActionExecutor\Basic(['executorButton' => [Button::class, 'Import', 'primary']]), 'r1c1'); $executor->setAction($action); $executor->ui = 'segment'; $executor->description = 'Execute action using "Basic" executor and path="." argument'; $executor->setArguments(['path' => '.']); -$executor->onHook(\atk4\ui\ActionExecutor\Basic::HOOK_AFTER_EXECUTE, function ($x, $ret) { - return new \atk4\ui\jsToast('Files imported: ' . $ret); +$executor->onHook(\atk4\ui\ActionExecutor\Basic::HOOK_AFTER_EXECUTE, function ($x) { + return new \atk4\ui\jsToast('Done!'); }); $grid->add($executor = new \atk4\ui\ActionExecutor\ArgumentForm(), 'r1c2'); @@ -53,7 +55,7 @@ $executor->description = 'ArgumentForm executor will ask user about arguments'; $executor->ui = 'segment'; $executor->onHook(\atk4\ui\ActionExecutor\Basic::HOOK_AFTER_EXECUTE, function ($x, $ret) { - return new \atk4\ui\jsToast('Files imported: ' . $ret); + return new \atk4\ui\jsToast('Imported!'); }); $grid->add($executor = new \atk4\ui\ActionExecutor\Preview(), 'r1c3'); @@ -63,7 +65,7 @@ $executor->description = 'Displays preview in console prior to executing'; $executor->setArguments(['path' => '.']); $executor->onHook(\atk4\ui\ActionExecutor\Basic::HOOK_AFTER_EXECUTE, function ($x, $ret) { - return new \atk4\ui\jsToast('Files imported: ' . $ret); + return new \atk4\ui\jsToast('Confirm!'); }); \atk4\ui\CRUD::addTo($app, ['ipp' => 5])->setModel($files); diff --git a/features/basicexecutor.feature b/features/basicexecutor.feature new file mode 100644 index 0000000000..7f8e16ef66 --- /dev/null +++ b/features/basicexecutor.feature @@ -0,0 +1,24 @@ +Feature: Executor + Testing basic action executor + + Scenario: basic + Given I am on "collection/actions.php" + And I press button "Import" + And wait for callback + Then Toast display should contains text "Done!" + + Scenario: form + Given I am on "collection/actions.php" + And I press button "Run" + And wait for callback + Then I should see "Must not be empty" + Then I fill in "path" with "." + Then I press button "Run" + And wait for callback + Then Toast display should contains text "Imported!" + + Scenario: preview + Given I am on "collection/actions.php" + And I press button "Confirm" + And wait for callback + Then Toast display should contains text "Confirm!" diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index d7251e64d8..ab9abc3443 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -104,6 +104,9 @@ public function iClickFilterColumnName($arg1) throw new \Exception('Unable to find a column ' . $arg1); } $icon = $column->find('css', 'i'); + if (!$icon) { + throw new \Exception('Column does not contain clickable icon.'); + } $script = '$("#' . $icon->getAttribute('id') . '").click()'; $this->getSession()->executeScript($script); } From 71e7b4fddfc5c036f86bd7ed69af27f91f996ea3 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Fri, 5 Jun 2020 17:17:28 -0400 Subject: [PATCH 07/26] remove template from console output --- demos/_unit-test/console_run.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/demos/_unit-test/console_run.php b/demos/_unit-test/console_run.php index 52b639dbf6..26fd6eeb49 100644 --- a/demos/_unit-test/console_run.php +++ b/demos/_unit-test/console_run.php @@ -13,14 +13,14 @@ 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']); - $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']); + $this->debug('debug'); + $this->emergency('emergency'); + $this->alert('alert'); + $this->critical('critical'); + $this->error('error'); + $this->warning('warning'); + $this->notice('notice'); + $this->info('info'); return 123; } From f34424994c98afb420b0b84d7d731ee627516eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 7 Jun 2020 13:41:49 +0200 Subject: [PATCH 08/26] Fix missing DIContainerTrait when StaticAddToTrait is used --- demos/_unit-test/console_run.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/demos/_unit-test/console_run.php b/demos/_unit-test/console_run.php index 26fd6eeb49..c370d237db 100644 --- a/demos/_unit-test/console_run.php +++ b/demos/_unit-test/console_run.php @@ -6,9 +6,8 @@ require_once __DIR__ . '/../atk-init.php'; -$testRun = get_class(new class() extends \atk4\data\Model { +$testRun = new class() extends \atk4\data\Model { use \atk4\core\DebugTrait; - use \atk4\core\StaticAddToTrait; public function test() { @@ -24,10 +23,10 @@ public function test() return 123; } -}); +}; $sse = jsSSE::addTo($app); $sse->urlTrigger = 'console_test'; $console = \atk4\ui\Console::addTo($app, ['sse' => $sse]); -$console->runMethod($testRun::addTo($app), 'test'); +$console->runMethod($app->add($testRun), 'test'); From a83dc81af888ad4be0c63e3321ce169ab4ec3304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 7 Jun 2020 14:52:59 +0200 Subject: [PATCH 09/26] Fix missing DIContainerTrait when StaticAddToTrait is used --- demos/interactive/console.php | 7 +++---- src/Template.php | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/demos/interactive/console.php b/demos/interactive/console.php index 796f23bc05..d24b6fbb9a 100644 --- a/demos/interactive/console.php +++ b/demos/interactive/console.php @@ -4,9 +4,8 @@ require_once __DIR__ . '/../atk-init.php'; -$testConsoleClass = get_class(new class() extends \atk4\data\Model { +$testRunClass = get_class(new class() extends \atk4\ui\View { use \atk4\core\DebugTrait; - use \atk4\core\StaticAddToTrait; public function generateReport() { @@ -42,13 +41,13 @@ public function generateReport() throw new \atk4\core\Exception('BOOM - exceptions are caught'); }); -$t = $tt->addTab('runMethod()', function ($t) use ($testConsoleClass) { +$t = $tt->addTab('runMethod()', function ($t) use ($testRunClass) { \atk4\ui\Header::addTo($t, [ 'icon' => 'terminal', 'Non-interractive method invocation', 'subHeader' => 'console can invoke a method, which normaly would be non-interractive and can still capture debug output', ]); - \atk4\ui\Console::addTo($t)->runMethod($testConsoleClass::addTo($t), 'generateReport'); + \atk4\ui\Console::addTo($t)->runMethod($testRunClass::addTo($t), 'generateReport'); }); $t = $tt->addTab('exec() single', function ($t) { diff --git a/src/Template.php b/src/Template.php index 702ee24eb8..cd7bbc4d19 100644 --- a/src/Template.php +++ b/src/Template.php @@ -27,6 +27,7 @@ class Template implements \ArrayAccess { use \atk4\core\AppScopeTrait; + use \atk4\core\DIContainerTrait; // needed for StaticAddToTrait, removed once php7.2 support is dropped use \atk4\core\StaticAddToTrait; // {{{ Properties of a template From 5e4b2afdb8247911c7bdc7abaf41ec7afad3f3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 7 Jun 2020 14:54:35 +0200 Subject: [PATCH 10/26] extra changes for merge --- demos/_unit-test/console_run.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/demos/_unit-test/console_run.php b/demos/_unit-test/console_run.php index 26fd6eeb49..48aed9d353 100644 --- a/demos/_unit-test/console_run.php +++ b/demos/_unit-test/console_run.php @@ -6,9 +6,8 @@ require_once __DIR__ . '/../atk-init.php'; -$testRun = get_class(new class() extends \atk4\data\Model { +$testRunClass = get_class(new class() extends \atk4\ui\View { use \atk4\core\DebugTrait; - use \atk4\core\StaticAddToTrait; public function test() { @@ -30,4 +29,4 @@ public function test() $sse->urlTrigger = 'console_test'; $console = \atk4\ui\Console::addTo($app, ['sse' => $sse]); -$console->runMethod($testRun::addTo($app), 'test'); +$console->runMethod($testRunClass::addTo($app), 'test'); From e04b3282131fc32b2b5d22162357e452974dea09 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Sun, 7 Jun 2020 18:03:18 -0400 Subject: [PATCH 11/26] fix hardcode column name --- tests/GridTest.php | 8 +++--- tests/TableColumnColorRatingTest.php | 17 +++++++++--- tests/TableColumnLinkTest.php | 39 ++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/tests/GridTest.php b/tests/GridTest.php index d437f79d31..d588c01be5 100644 --- a/tests/GridTest.php +++ b/tests/GridTest.php @@ -6,7 +6,7 @@ use atk4\ui\Table; use atk4\ui\TableColumn\Template; -class GridTest extends AtkPhpunit\TestCase +class GridTest extends \atk4\core\AtkPhpunit\TestCase { use Concerns\HandlesTable; @@ -58,11 +58,11 @@ public function test2() $t = new Table(); $t->init(); $t->setModel($this->m, ['email']); - $t->addColumn(null, \atk4\ui\TableColumn\Delete::class); + $del = $t->addColumn(null, \atk4\ui\TableColumn\Delete::class); - $this->assertSame('{$email}Delete', $t->getDataRowHTML()); + $this->assertSame('{$email}Delete', $t->getDataRowHTML()); $this->assertSame( - 'test@test.comDelete', + 'test@test.comDelete', $this->extractTableRow($t) ); } diff --git a/tests/TableColumnColorRatingTest.php b/tests/TableColumnColorRatingTest.php index b349aee2f6..43ba807cc3 100644 --- a/tests/TableColumnColorRatingTest.php +++ b/tests/TableColumnColorRatingTest.php @@ -5,6 +5,7 @@ use atk4\core\AtkPhpunit; use atk4\ui\Table; use atk4\ui\TableColumn\ColorRating; +use atk4\ui\TableColumn\Generic; class TableColumnColorRatingTest extends AtkPhpunit\TestCase { @@ -40,7 +41,7 @@ protected function setUp(): void public function testValueGreaterThanMax() { - $this->table->addDecorator('rating', [ + $rating = $this->table->addDecorator('rating', [ ColorRating::class, [ 'min' => 0, @@ -55,7 +56,7 @@ public function testValueGreaterThanMax() ]); $this->assertSame( - '{$name}{$ref}{$rating}', + '{$name}{$ref}{$rating}', $this->table->getDataRowHTML() ); @@ -90,7 +91,7 @@ public function testValueGreaterThanMaxNoColor() public function testValueLowerThanMin() { - $this->table->addDecorator('rating', [ + $rating = $this->table->addDecorator('rating', [ ColorRating::class, [ 'min' => 4, @@ -105,7 +106,7 @@ public function testValueLowerThanMin() ]); $this->assertSame( - '{$name}{$ref}{$rating}', + '{$name}{$ref}{$rating}', $this->table->getDataRowHTML() ); @@ -211,4 +212,12 @@ public function testExceptionLessThan2ColorsDefined() ], ]); } + + /** + * return column template style name. + */ + private function getColumnStyle(Generic $column): string + { + return '_' . $column->short_name . '_color_rating'; + } } diff --git a/tests/TableColumnLinkTest.php b/tests/TableColumnLinkTest.php index e06eb5cacf..11ce8eed8b 100644 --- a/tests/TableColumnLinkTest.php +++ b/tests/TableColumnLinkTest.php @@ -3,6 +3,7 @@ namespace atk4\ui\tests; use atk4\core\AtkPhpunit; +use atk4\ui\TableColumn\Generic; class TableColumnLinkTest extends AtkPhpunit\TestCase { @@ -49,10 +50,10 @@ public function testMultipleFormatters() public function testTDLast() { - $this->table->addColumn('salary', new \atk4\ui\TableColumn\Money()); + $salary = $this->table->addColumn('salary', new \atk4\ui\TableColumn\Money()); $this->assertSame( - '{$name}{$ref}{$salary}', + '{$name}{$ref}{$salary}', $this->table->getDataRowHTML() ); @@ -64,11 +65,11 @@ public function testTDLast() public function testTDNotLast() { - $this->table->addColumn('salary', new \atk4\ui\TableColumn\Money()); + $salary = $this->table->addColumn('salary', new \atk4\ui\TableColumn\Money()); $this->table->addDecorator('salary', new \atk4\ui\TableColumn\Template('{$salary}')); $this->assertSame( - '{$name}{$ref}{$salary}', + '{$name}{$ref}{$salary}', $this->table->getDataRowHTML() ); @@ -80,12 +81,12 @@ public function testTDNotLast() public function testTwoMoneys() { - $this->table->addDecorator('name', new \atk4\ui\TableColumn\Money()); - $this->table->addColumn('salary', new \atk4\ui\TableColumn\Money()); + $salary_1 = $this->table->addDecorator('name', new \atk4\ui\TableColumn\Money()); + $salary_2 = $this->table->addColumn('salary', new \atk4\ui\TableColumn\Money()); $this->table->addDecorator('salary', new \atk4\ui\TableColumn\Template('{$salary}')); $this->assertSame( - '{$name}{$ref}{$salary}', + '{$name}{$ref}{$salary}', $this->table->getDataRowHTML() ); @@ -142,10 +143,10 @@ public function testRender1a() public function testLink1() { - $this->table->addDecorator('name', new \atk4\ui\TableColumn\Link('example.php?id={$id}')); + $link = $this->table->addDecorator('name', new \atk4\ui\TableColumn\Link('example.php?id={$id}')); $this->assertSame( - '{$name}{$ref}', + '{$name}{$ref}', $this->table->getDataRowHTML() ); @@ -157,10 +158,10 @@ public function testLink1() public function testLink1a() { - $this->table->addDecorator('name', [\atk4\ui\TableColumn\Link::class, 'url' => 'example.php?id={$id}']); + $link = $this->table->addDecorator('name', [\atk4\ui\TableColumn\Link::class, 'url' => 'example.php?id={$id}']); $this->assertSame( - '{$name}{$ref}', + '{$name}{$ref}', $this->table->getDataRowHTML() ); @@ -283,6 +284,22 @@ public function testLink11() ); } + /** + * Return column template reference name. + */ + private function getColumnRef(Generic $column): string + { + return 'c_' . $column->short_name; + } + + /** + * Return column template class name. + */ + private function getColumnClass(Generic $column): string + { + return '_' . $column->short_name . '_class'; + } + /* function testLink1() { From 0a722531233af633210489d0867f122393fdc816 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Sun, 7 Jun 2020 22:03:40 +0000 Subject: [PATCH 12/26] Apply fixes from StyleCI --- tests/GridTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/GridTest.php b/tests/GridTest.php index d588c01be5..d386c2f814 100644 --- a/tests/GridTest.php +++ b/tests/GridTest.php @@ -60,7 +60,7 @@ public function test2() $t->setModel($this->m, ['email']); $del = $t->addColumn(null, \atk4\ui\TableColumn\Delete::class); - $this->assertSame('{$email}Delete', $t->getDataRowHTML()); + $this->assertSame('{$email}Delete', $t->getDataRowHTML()); $this->assertSame( 'test@test.comDelete', $this->extractTableRow($t) From a2d2a61f9756f6d045713d7305964699a0ca0736 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Sun, 7 Jun 2020 18:06:20 -0400 Subject: [PATCH 13/26] cs fixer --- tests/GridTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/GridTest.php b/tests/GridTest.php index d386c2f814..ba7a0e3c8e 100644 --- a/tests/GridTest.php +++ b/tests/GridTest.php @@ -2,7 +2,6 @@ namespace atk4\ui\tests; -use atk4\core\AtkPhpunit; use atk4\ui\Table; use atk4\ui\TableColumn\Template; From 37a3b671d6107c2cb1b8b5fd1ee5a9d958d42c1d Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Mon, 8 Jun 2020 10:23:45 -0400 Subject: [PATCH 14/26] move utility function to trait just realized we had a trait file for table test. --- tests/Concerns/HandlesTable.php | 25 +++++++++++++++++++++++++ tests/TableColumnColorRatingTest.php | 8 -------- tests/TableColumnLinkTest.php | 16 ---------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/tests/Concerns/HandlesTable.php b/tests/Concerns/HandlesTable.php index 4a06e80d5f..c933428d67 100644 --- a/tests/Concerns/HandlesTable.php +++ b/tests/Concerns/HandlesTable.php @@ -3,6 +3,7 @@ namespace atk4\ui\tests\Concerns; use atk4\ui\Table; +use atk4\ui\TableColumn\Generic; trait HandlesTable { @@ -21,4 +22,28 @@ protected function extractTableRow(Table $table, $rowDataId = '1') return preg_replace('~\r?\n|\r~', '', $matches[0]); } + + /** + * Return column template reference name. + */ + protected function getColumnRef(Generic $column): string + { + return 'c_' . $column->short_name; + } + + /** + * Return column template class name. + */ + protected function getColumnClass(Generic $column): string + { + return '_' . $column->short_name . '_class'; + } + + /** + * return column template style name. + */ + protected function getColumnStyle(Generic $column): string + { + return '_' . $column->short_name . '_color_rating'; + } } diff --git a/tests/TableColumnColorRatingTest.php b/tests/TableColumnColorRatingTest.php index 43ba807cc3..20b485cbf1 100644 --- a/tests/TableColumnColorRatingTest.php +++ b/tests/TableColumnColorRatingTest.php @@ -212,12 +212,4 @@ public function testExceptionLessThan2ColorsDefined() ], ]); } - - /** - * return column template style name. - */ - private function getColumnStyle(Generic $column): string - { - return '_' . $column->short_name . '_color_rating'; - } } diff --git a/tests/TableColumnLinkTest.php b/tests/TableColumnLinkTest.php index 11ce8eed8b..bc61bd365d 100644 --- a/tests/TableColumnLinkTest.php +++ b/tests/TableColumnLinkTest.php @@ -284,22 +284,6 @@ public function testLink11() ); } - /** - * Return column template reference name. - */ - private function getColumnRef(Generic $column): string - { - return 'c_' . $column->short_name; - } - - /** - * Return column template class name. - */ - private function getColumnClass(Generic $column): string - { - return '_' . $column->short_name . '_class'; - } - /* function testLink1() { From 8a8d6a4c744a310c235c471ff86fac97251b530e Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Mon, 8 Jun 2020 10:24:41 -0400 Subject: [PATCH 15/26] cs fixer --- tests/TableColumnColorRatingTest.php | 1 - tests/TableColumnLinkTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/TableColumnColorRatingTest.php b/tests/TableColumnColorRatingTest.php index 20b485cbf1..00132b0457 100644 --- a/tests/TableColumnColorRatingTest.php +++ b/tests/TableColumnColorRatingTest.php @@ -5,7 +5,6 @@ use atk4\core\AtkPhpunit; use atk4\ui\Table; use atk4\ui\TableColumn\ColorRating; -use atk4\ui\TableColumn\Generic; class TableColumnColorRatingTest extends AtkPhpunit\TestCase { diff --git a/tests/TableColumnLinkTest.php b/tests/TableColumnLinkTest.php index bc61bd365d..1db085ec53 100644 --- a/tests/TableColumnLinkTest.php +++ b/tests/TableColumnLinkTest.php @@ -3,7 +3,6 @@ namespace atk4\ui\tests; use atk4\core\AtkPhpunit; -use atk4\ui\TableColumn\Generic; class TableColumnLinkTest extends AtkPhpunit\TestCase { From 27a3f75e719dba03834e7128892e358b7c41df73 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Mon, 8 Jun 2020 15:18:44 -0400 Subject: [PATCH 16/26] adding behat test for grid search --- features/bootstrap/FeatureContext.php | 39 +++++++++++++++++++++++++++ features/grid.feature | 17 ++++++++++++ template/semantic-ui/js-search.html | 3 ++- template/semantic-ui/js-search.pug | 2 +- 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 features/grid.feature diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index ab9abc3443..589c4b9f2b 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -327,6 +327,45 @@ public function iSelectValueInLookup($arg1, $arg2) $this->getSession()->executeScript($script); } + /** + * @Then I search grid for :arg1 + */ + public function iSearchGridFor($arg1) + { + $search = $this->getSession()->getPage()->find('css', 'input.atk-grid-search'); + if (!$search) { + throw new \Exception('Unable to find search input.'); + } + + $search->setValue($arg1); + } + + /** + * @Then I click icon using css :arg1 + */ + public function iClickIconUsingCss($arg1) + { + $icon = $this->getSession()->getPage()->find('css', $arg1); + if (!$icon) { + throw new \Exception('Unable to find search remove icon.'); + } + + $icon->click(); + } + + /** + * Wait for an element, usually an auto trigger element, to show that loading has start" + * Example, when entering value in jsSearch for grid. We need to auto trigger to fire before + * doing waiting for callback. + * $arg1 should represent the element selector for jQuery. + * + * @Then I wait for loading to start in :arg1 + */ + public function iWaitForLoadingToStartIn($arg1) + { + $this->getSession()->wait(2000, '$("' . $arg1 . '").hasClass("loading")'); + } + /** * @Then I test javascript */ diff --git a/features/grid.feature b/features/grid.feature new file mode 100644 index 0000000000..cf8c3f2339 --- /dev/null +++ b/features/grid.feature @@ -0,0 +1,17 @@ +Feature: Grid + Testing grid search + + Scenario: search + Given I am on "collection/grid.php" + Then I search grid for "united" +# make sure auto query trigger + And I wait for loading to start in "button.atk-search-button" + And wait for callback + Then I should see "United Kingdom" + Then I press button "Test" + And wait for callback + Then Toast display should contains text "United Kingdom" +# click search remove icon + Then I click icon using css "i.atk-remove-icon" + And wait for callback + Then I should not see "United Kingdom" diff --git a/template/semantic-ui/js-search.html b/template/semantic-ui/js-search.html index 5fff2be3c0..1128f53136 100644 --- a/template/semantic-ui/js-search.html +++ b/template/semantic-ui/js-search.html @@ -1,6 +1,7 @@ +
- +