From 72a15da7ba396d41b4bbd6f930cfca83bef451c3 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Tue, 23 Jan 2024 12:54:15 +0000 Subject: [PATCH 1/5] feat: Conversation messages list --- .../Controller/ConversationsController.php | 31 +++++++++++++++++++ .../src/Table/Tables/messages-view.table.php | 29 +++++++++++++++++ module/Olcs/view/messages-view.phtml | 27 ++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 module/Olcs/src/Table/Tables/messages-view.table.php create mode 100644 module/Olcs/view/messages-view.phtml diff --git a/module/Olcs/src/Controller/ConversationsController.php b/module/Olcs/src/Controller/ConversationsController.php index 48f72aecf..058d88d10 100644 --- a/module/Olcs/src/Controller/ConversationsController.php +++ b/module/Olcs/src/Controller/ConversationsController.php @@ -9,6 +9,7 @@ use Common\FeatureToggle; use Common\Service\Helper\FlashMessengerHelperService; use Common\Service\Table\TableFactory; +use Dvsa\Olcs\Transfer\Query\Messaging\Messages\ByConversation as ByConversationQuery; use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByOrganisation as ByOrganisationQuery; use Dvsa\Olcs\Utils\Translation\NiTextTranslation; use Laminas\View\Model\ViewModel; @@ -69,4 +70,34 @@ public function indexAction(): ViewModel return $view; } + + public function viewAction(): ViewModel + { + $params = [ + 'page' => $this->params()->fromQuery('page', 1), + 'limit' => $this->params()->fromQuery('limit', 10), + 'conversation' => $this->params()->fromRoute('conversationId'), + 'query' => $this->params()->fromQuery(), + ]; + + $response = $this->handleQuery(ByConversationQuery::create($params)); + if ($response === null) { + return $this->notFoundAction(); + } + + if ($response->isOk()) { + $messages = $response->getResult(); + } else { + $this->flashMessengerHelper->addErrorMessage('unknown-error'); + $messages = []; + } + + $table = $this->tableFactory + ->buildTable('messages-view', $messages, $params); + + $view = new ViewModel(['table' => $table]); + $view->setTemplate('messages-view'); + + return $view; + } } diff --git a/module/Olcs/src/Table/Tables/messages-view.table.php b/module/Olcs/src/Table/Tables/messages-view.table.php new file mode 100644 index 000000000..adde0edad --- /dev/null +++ b/module/Olcs/src/Table/Tables/messages-view.table.php @@ -0,0 +1,29 @@ + [ + 'class' => 'no-row-border-separator' + ], + 'variables' => [ + 'id' => 'messages-list-table', + 'title' => 'Messages', + 'empty_message' => 'There are no message records linked to this conversation to display' + ], + 'settings' => [ + 'paginate' => [ + 'limit' => [ + 'options' => [10, 25, 50], + ], + ], + ], + 'columns' => [ + [ + 'name' => 'id', + 'formatter' => ExternalConversationMessage::class, + ], + ], +]; diff --git a/module/Olcs/view/messages-view.phtml b/module/Olcs/view/messages-view.phtml new file mode 100644 index 000000000..374a94cc1 --- /dev/null +++ b/module/Olcs/view/messages-view.phtml @@ -0,0 +1,27 @@ +partial( + 'partials/page-header-simple', + [ + 'pageTitle' => $this->translate('dashboard.messages.view.title'), + ], +); +?> + +
+
+ flashMessengerAll(); + + /* @var \Laminas\View\Helper\Navigation\Menu $menu */ + $menu = $this->navigation($this->navigation('navigation')->getContainer()->findBy('id', 'dashboard-licences-applications'))->menu(); + + echo $menu->setMinDepth(0) + ->setMaxDepth(0) + ->setPartial('partials/tabs-nav'); + + echo $this->table; + ?> +
+ + partial('partials/dashboard-right-column'); ?> +
From 0069734f568e4480d31d7622c781fcde1deb5520 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:12:28 +0000 Subject: [PATCH 2/5] feat: Controller view test --- .../ConversationsControllerTest.php | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 test/Olcs/src/Controller/ConversationsControllerTest.php diff --git a/test/Olcs/src/Controller/ConversationsControllerTest.php b/test/Olcs/src/Controller/ConversationsControllerTest.php new file mode 100644 index 000000000..2e7723701 --- /dev/null +++ b/test/Olcs/src/Controller/ConversationsControllerTest.php @@ -0,0 +1,95 @@ +mockniTextTranslationUtil = m::mock(NiTextTranslation::class)->makePartial(); + $this->mockauthService = m::mock(AuthorizationService::class)->makePartial(); + $this->mockflashMessengerHelper = m::mock(FlashMessengerHelperService::class)->makePartial(); + $this->mocktableFactory = m::mock(TableFactory::class)->makePartial(); + + $this->sut = m::mock(Sut::class) + ->makePartial() + ->shouldAllowMockingProtectedMethods(); + + $reflectionClass = new ReflectionClass(Sut::class); + $this->setMockedProperties($reflectionClass, 'niTextTranslationUtil', $this->mockniTextTranslationUtil); + $this->setMockedProperties($reflectionClass, 'authService', $this->mockauthService); + $this->setMockedProperties($reflectionClass, 'flashMessengerHelper', $this->mockflashMessengerHelper); + $this->setMockedProperties($reflectionClass, 'tableFactory', $this->mocktableFactory); + } + + public function setMockedProperties(ReflectionClass $reflectionClass, string $property, $value): void + { + $reflectionProperty = $reflectionClass->getProperty($property); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->sut, $value); + } + + public function testViewAction(): void + { + $mockResponse = m::mock(Response::class); + $mockResponse->shouldReceive('isOk') + ->andReturn(true); + $mockResponse->shouldReceive('getResult') + ->andReturn([]); + + $mockHandleQuery = m::mock(HandleQuery::class) + ->makePartial(); + $mockHandleQuery->shouldReceive('__invoke') + ->andReturn($mockResponse); + + $mockParams = m::mock(Params::class); + $mockParams->shouldReceive('fromQuery') + ->with('page', 1) + ->andReturn(1); + $mockParams->shouldReceive('fromQuery') + ->with('limit', 10) + ->andReturn(10); + $mockParams->shouldReceive('fromQuery') + ->withNoArgs() + ->andReturn([]); + $mockParams->shouldReceive('fromRoute') + ->with('conversationId') + ->andReturn(1); + + $this->sut->shouldReceive('params') + ->andReturn($mockParams); + $this->sut->shouldReceive('plugin') + ->with('handleQuery') + ->andReturn($mockHandleQuery); + + $table = ''; + + $this->mocktableFactory->shouldReceive('buildTable') + ->with( + 'messages-view', + [], + ['page' => 1, 'limit' => 10, 'conversation' => 1, 'query' => []], + ) + ->andReturn($table); + + $view = $this->sut->viewAction(); + $this->assertInstanceOf(ViewModel::class, $view); + $this->assertEquals($table, $view->getVariable('table')); + } +} From 3fb78958ec6f044420daedc82f05e01e4afe88df Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:15:34 +0000 Subject: [PATCH 3/5] fix: Unused null check --- module/Olcs/src/Controller/ConversationsController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/module/Olcs/src/Controller/ConversationsController.php b/module/Olcs/src/Controller/ConversationsController.php index 058d88d10..943eb06f6 100644 --- a/module/Olcs/src/Controller/ConversationsController.php +++ b/module/Olcs/src/Controller/ConversationsController.php @@ -81,9 +81,6 @@ public function viewAction(): ViewModel ]; $response = $this->handleQuery(ByConversationQuery::create($params)); - if ($response === null) { - return $this->notFoundAction(); - } if ($response->isOk()) { $messages = $response->getResult(); From d1e731f546148e62ecee19f2e9c79fc196a540c5 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:42:31 +0000 Subject: [PATCH 4/5] fix: Test PR changes (case and unused var) --- .../ConversationsControllerTest.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/Olcs/src/Controller/ConversationsControllerTest.php b/test/Olcs/src/Controller/ConversationsControllerTest.php index 2e7723701..c17becdca 100644 --- a/test/Olcs/src/Controller/ConversationsControllerTest.php +++ b/test/Olcs/src/Controller/ConversationsControllerTest.php @@ -17,25 +17,24 @@ class ConversationsControllerTest extends TestCase { - protected $sut; - protected $sm; + protected $sut; public function setUp(): void { - $this->mockniTextTranslationUtil = m::mock(NiTextTranslation::class)->makePartial(); - $this->mockauthService = m::mock(AuthorizationService::class)->makePartial(); - $this->mockflashMessengerHelper = m::mock(FlashMessengerHelperService::class)->makePartial(); - $this->mocktableFactory = m::mock(TableFactory::class)->makePartial(); + $this->mockNiTextTranslationUtil = m::mock(NiTextTranslation::class)->makePartial(); + $this->mockAuthService = m::mock(AuthorizationService::class)->makePartial(); + $this->mockFlashMessengerHelper = m::mock(FlashMessengerHelperService::class)->makePartial(); + $this->mockTableFactory = m::mock(TableFactory::class)->makePartial(); $this->sut = m::mock(Sut::class) ->makePartial() ->shouldAllowMockingProtectedMethods(); $reflectionClass = new ReflectionClass(Sut::class); - $this->setMockedProperties($reflectionClass, 'niTextTranslationUtil', $this->mockniTextTranslationUtil); - $this->setMockedProperties($reflectionClass, 'authService', $this->mockauthService); - $this->setMockedProperties($reflectionClass, 'flashMessengerHelper', $this->mockflashMessengerHelper); - $this->setMockedProperties($reflectionClass, 'tableFactory', $this->mocktableFactory); + $this->setMockedProperties($reflectionClass, 'niTextTranslationUtil', $this->mockNiTextTranslationUtil); + $this->setMockedProperties($reflectionClass, 'authService', $this->mockAuthService); + $this->setMockedProperties($reflectionClass, 'flashMessengerHelper', $this->mockFlashMessengerHelper); + $this->setMockedProperties($reflectionClass, 'tableFactory', $this->mockTableFactory); } public function setMockedProperties(ReflectionClass $reflectionClass, string $property, $value): void @@ -80,7 +79,7 @@ public function testViewAction(): void $table = '
'; - $this->mocktableFactory->shouldReceive('buildTable') + $this->mockTableFactory->shouldReceive('buildTable') ->with( 'messages-view', [], From bcb8c02f1724f2b3e47f5de61f6df404b12b6cda Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:43:27 +0000 Subject: [PATCH 5/5] fix: Just added whitespace! --- test/Olcs/src/Controller/ConversationsControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Olcs/src/Controller/ConversationsControllerTest.php b/test/Olcs/src/Controller/ConversationsControllerTest.php index c17becdca..19da55ecd 100644 --- a/test/Olcs/src/Controller/ConversationsControllerTest.php +++ b/test/Olcs/src/Controller/ConversationsControllerTest.php @@ -17,7 +17,7 @@ class ConversationsControllerTest extends TestCase { - protected $sut; + protected $sut; public function setUp(): void {