diff --git a/module/Olcs/src/Controller/ConversationsController.php b/module/Olcs/src/Controller/ConversationsController.php index f73f4182d..2246a7fed 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; @@ -66,4 +67,31 @@ 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->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'); ?> +
diff --git a/test/Olcs/src/Controller/ConversationsControllerTest.php b/test/Olcs/src/Controller/ConversationsControllerTest.php new file mode 100644 index 000000000..19da55ecd --- /dev/null +++ b/test/Olcs/src/Controller/ConversationsControllerTest.php @@ -0,0 +1,94 @@ +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')); + } +}