Skip to content

Commit

Permalink
fix: fixing issue when log route name in breadcrumbs was ignoring con…
Browse files Browse the repository at this point in the history
…fig value
  • Loading branch information
czernika committed Jan 11, 2024
1 parent 9ac87fa commit 66a2faf
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
push:
branches:
- master
# paths:
# - "**/*.php"
paths:
- "**/*.php"
pull_request:

jobs:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Releases

## v1.0.1 Jan 11, 2024

- Fix: fixing issue when log route name in breadcrumbs was ignoring config value
- Feat: added separate options for menu localization
- Tests: added tests for default log screen

## v1.0.0 Jan 10, 2024

- Initial release
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "czernika/orchid-log-viewer",
"description": "",
"description": "Manage your Laravel app logs within Orchid admin panel ",
"license": "MIT",
"version": "1.0.0",
"version": "1.0.1",
"authors": [
{
"name": "Aliakseyenka Ihar",
Expand All @@ -18,10 +18,10 @@
"require-dev": {
"ergebnis/composer-normalize": "^2.41",
"laravel/pint": "^1.13",
"mockery/mockery": "^1.6",
"orchestra/testbench": "^8.19",
"pestphp/pest": "^2.30",
"plannr/laravel-fast-refresh-database": "^1.1",
"mockery/mockery": "^1.6"
"plannr/laravel-fast-refresh-database": "^1.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lang/en/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@
'success_message' => 'File :file was removed',
],
],

'menu' => [
'name' => 'Logs',
'title' => 'Logs',
],
];
6 changes: 6 additions & 0 deletions src/Contracts/LogServiceContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ public function logs(): LengthAwarePaginator;
*/
public function resolveSelectedFile(): string;

/**
* Clear selected file
*/
public function clearFile(string $file): void;

/**
* Delete selected file
*/
public function deleteFile(string $file): void;
}
10 changes: 6 additions & 4 deletions src/OrchidLogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,24 @@ public function boot(Dashboard $dashboard): void
public function routes(Router $route): void
{
if (config('orchid-log.screen.discover', true)) {
$name = config('orchid-log.screen.route', 'platform.logs');

$route
->screen('logs', LogManager::screen())
->name(config('orchid-log.screen.route', 'platform.logs'))
->name($name)
->breadcrumbs(fn (Trail $trail) => $trail
->parent('platform.index')
->push(trans('orchid-log::messages.screen.name'), route('platform.logs')));
->push(trans('orchid-log::messages.screen.name'), route($name)));
}
}

public function menu(): array
{
if (config('orchid-log.menu.register', true)) {
return [
Menu::make(trans('orchid-log::messages.screen.name'))
Menu::make(trans('orchid-log::messages.menu.name'))
->icon('bs.bug')
->title(trans('orchid-log::messages.screen.name'))
->title(trans('orchid-log::messages.menu.title'))
->route('platform.logs'),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tests\Actions;
namespace Tests\App\Actions;

use Czernika\OrchidLogViewer\Actions\ClearLogFile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tests\Actions;
namespace Tests\App\Actions;

use Czernika\OrchidLogViewer\Actions\DeleteLogFile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tests\Layouts;
namespace Tests\App\Layouts;

use Czernika\OrchidLogViewer\Layouts\OrchidLogTableLayout;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tests\Screen;
namespace Tests\App\Screen;

use Czernika\OrchidLogViewer\Screen\OrchidLogListScreen;

Expand Down
2 changes: 1 addition & 1 deletion tests/Data/TestLogData.php → tests/App/TestLogData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tests\Data;
namespace Tests\App;

use Czernika\OrchidLogViewer\LogData;

Expand Down
77 changes: 77 additions & 0 deletions tests/Feature/ScreenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

use Czernika\OrchidLogViewer\LogData;
use Czernika\OrchidLogViewer\LogManager;
use Czernika\OrchidLogViewer\Screen\OrchidLogListScreen;
use Illuminate\Testing\TestResponse;
use Tests\App\Screen\TestOrchidLogListScreen;

uses()->group('feature.screen');

beforeEach(function () {
$this->withoutExceptionHandling();
});

afterAll(function () {
// Rollback
LogManager::useScreen(OrchidLogListScreen::class);
});

describe('default screen', function () {
it('shows headings', function () {
$this->mockLogsWith();

/** @var TestResponse */
$response = $this->see();

$response
->assertSee('<h1 class="m-0 fw-light h3 text-black">Logs</h1>', false)
->assertSee('Manage app storage logs');
});

it('shows empty table if there are no logs', function () {
$this->mockLogsWith();

/** @var TestResponse */
$response = $this->see();

$response->assertSee('There are no objects currently displayed');
});

it('shows correct log data if there are some logs', function () {
$this->mockLogsWith([
new LogData([
'text' => 'Log message',
'stack' => 'Some really long stack trace',
'date' => '2024-01-01 12:00:00',
'level' => 'error',
'level_img' => 'exclamation-triangle',
]),
]);

/** @var TestResponse */
$response = $this->see();

$response
->assertSee('Log message') // log message
->assertSee('Error') // log level with capitalized first letter
->assertSee('path="bs.exclamation-triangle"', false) // log level icon
->assertSee('<time class="mb-0 text-capitalize">Jan 1, 2024<span class="text-muted d-block">Mon, 12:00</span></time>', false) // formatted date
->assertSee('data-controller="modal-toggle"', false) // stack trace button
->assertSee('data-modal-toggle-params=\'{"stack":"Some really long stack trace"}\'', false); // stack trace param
});

it('will not show stack trace button if there are no log stack trace', function () {
$this->mockLogsWith([
new LogData([
'text' => 'Log message',
'stack' => '', // No stack trace
]),
]);

/** @var TestResponse */
$response = $this->see();

$response->assertDontSee('data-controller="modal-toggle"', false);
});
});
3 changes: 2 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
|
*/

uses(Tests\TestCase::class)->in('Unit');
uses(Tests\TestUnitCase::class)->in('Unit');
uses(Tests\TestFeatureCase::class)->in('Feature');
15 changes: 1 addition & 14 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@

namespace Tests;

use App\Models\User;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase as BaseTestCase;
use Orchid\Support\Facades\Alert;
use Orchid\Support\Facades\Dashboard;
use Orchid\Support\Testing\ScreenTesting;
use Plannr\Laravel\FastRefreshDatabase\Traits\FastRefreshDatabase;
use Tabuna\Breadcrumbs\Breadcrumbs;
use Watson\Active\Active;

abstract class TestCase extends BaseTestCase
{
use FastRefreshDatabase, ScreenTesting, WithWorkbench;

protected function setUp(): void
{
parent::setUp();
}
use WithWorkbench;

/**
* @param \Illuminate\Foundation\Application $app
Expand All @@ -41,9 +33,4 @@ protected function getPackageAliases($app): array
'Dashboard' => Dashboard::class,
];
}

public function admin()
{
return User::factory()->admin()->create();
}
}
36 changes: 36 additions & 0 deletions tests/TestFeatureCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Tests;

use App\Models\User;
use Czernika\OrchidLogViewer\Contracts\LogServiceContract;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Testing\TestResponse;
use Mockery\MockInterface;
use Orchid\Support\Testing\ScreenTesting;
use Plannr\Laravel\FastRefreshDatabase\Traits\FastRefreshDatabase;

class TestFeatureCase extends TestCase
{
use FastRefreshDatabase, ScreenTesting;

public function see(): TestResponse
{
return $this->screen('platform.logs')
->actingAs(User::factory()->admin()->create())
->display();
}

public function mockLogsWith(array $logs = [], string $file = 'laravel.log'): void
{
$this->partialMock(LogServiceContract::class, function (MockInterface $mock) use ($logs, $file) {
$mock->shouldReceive('logs')->once()->andReturn(
new LengthAwarePaginator($logs, count($logs), 15),
);

$mock->shouldReceive('resolveSelectedFile')->once()->andReturn($file);
});
}
}
9 changes: 9 additions & 0 deletions tests/TestUnitCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Tests;

class TestUnitCase extends TestCase
{
}
34 changes: 14 additions & 20 deletions tests/Unit/LogManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
use Czernika\OrchidLogViewer\LogData;
use Czernika\OrchidLogViewer\LogManager;
use Czernika\OrchidLogViewer\Screen\OrchidLogListScreen;
use Tests\Actions\TestClearLogFile;
use Tests\Actions\TestDeleteLogFile;
use Tests\Data\TestLogData;
use Tests\Layouts\TestOrchidLogTableLayout;
use Tests\Screen\TestOrchidLogListScreen;
use Tests\App\Actions\TestClearLogFile;
use Tests\App\Actions\TestDeleteLogFile;
use Tests\App\TestLogData;
use Tests\App\Layouts\TestOrchidLogTableLayout;
use Tests\App\Screen\TestOrchidLogListScreen;

afterAll(function () {
// Rollback
LogManager::useScreen(OrchidLogListScreen::class);
LogManager::useLayout(OrchidLogTableLayout::class);
LogManager::useMapper(LogData::class);
LogManager::clearLogFileUsing(ClearLogFile::class);
LogManager::deleteLogFileUsing(DeleteLogFile::class);
});

describe('log manager', function () {
it('resolves default screen', function () {
Expand All @@ -20,9 +29,6 @@
it('can change screen', function () {
LogManager::useScreen(TestOrchidLogListScreen::class);
expect(LogManager::screen())->toBe(TestOrchidLogListScreen::class);

// Rollback
LogManager::useScreen(OrchidLogListScreen::class);
});

it('resolves default layout', function () {
Expand All @@ -32,9 +38,6 @@
it('can change layout', function () {
LogManager::useLayout(TestOrchidLogTableLayout::class);
expect(LogManager::layout())->toBe(TestOrchidLogTableLayout::class);

// Rollback
LogManager::useLayout(OrchidLogTableLayout::class);
});

it('resolves default mapper', function () {
Expand All @@ -44,9 +47,6 @@
it('can change mapper', function () {
LogManager::useMapper(TestLogData::class);
expect(LogManager::mapper())->toBe(TestLogData::class);

// Rollback
LogManager::useMapper(LogData::class);
});

it('resolves default clear action', function () {
Expand All @@ -56,9 +56,6 @@
it('can change clear action', function () {
LogManager::clearLogFileUsing(TestClearLogFile::class);
expect(LogManager::clearLogFileAction())->toBe(TestClearLogFile::class);

// Rollback
LogManager::clearLogFileUsing(ClearLogFile::class);
});

it('resolves default delete action', function () {
Expand All @@ -68,8 +65,5 @@
it('can change delete action', function () {
LogManager::deleteLogFileUsing(TestDeleteLogFile::class);
expect(LogManager::deleteLogFileAction())->toBe(TestDeleteLogFile::class);

// Rollback
LogManager::deleteLogFileUsing(DeleteLogFile::class);
});
});

0 comments on commit 66a2faf

Please sign in to comment.