|
| 1 | +<?php |
| 2 | + |
| 3 | +use Opcodes\LogViewer\Enums\FolderSortingMethod; |
| 4 | + |
| 5 | +use function Pest\Laravel\getJson; |
| 6 | + |
| 7 | +beforeEach(function () { |
| 8 | + config(['log-viewer.include_files' => ['*.log']]); |
| 9 | +}); |
| 10 | + |
| 11 | +it('you can get time sorted default desc logs files controller', function () { |
| 12 | + config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::ModifiedTime]); |
| 13 | + |
| 14 | + $names = [ |
| 15 | + 'one.log', |
| 16 | + 'two.log', |
| 17 | + 'three.log', |
| 18 | + ]; |
| 19 | + generateLogFiles($names, randomContent: true); |
| 20 | + array_map(function (string $name) { |
| 21 | + $this->travelTo(now()->addSecond()); |
| 22 | + touch(storage_path('logs/'.$name), now()->timestamp); |
| 23 | + }, $names); |
| 24 | + |
| 25 | + $response = getJson(route('log-viewer.files')); |
| 26 | + |
| 27 | + expect(array_column($response->json(), 'name'))->toBe([ |
| 28 | + 'three.log', |
| 29 | + 'two.log', |
| 30 | + 'one.log', |
| 31 | + ]); |
| 32 | +}); |
| 33 | + |
| 34 | +it('you can get time sorted desc logs files controller', function () { |
| 35 | + config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::ModifiedTime]); |
| 36 | + |
| 37 | + $names = [ |
| 38 | + 'one.log', |
| 39 | + 'two.log', |
| 40 | + 'three.log', |
| 41 | + ]; |
| 42 | + generateLogFiles($names, randomContent: true); |
| 43 | + array_map(function (string $name) { |
| 44 | + $this->travelTo(now()->addSecond()); |
| 45 | + touch(storage_path('logs/'.$name), now()->timestamp); |
| 46 | + }, $names); |
| 47 | + |
| 48 | + $response = getJson(route('log-viewer.files', ['direction' => 'desc'])); |
| 49 | + // dd($response->json()); |
| 50 | + |
| 51 | + expect(array_column($response->json(), 'name'))->toBe([ |
| 52 | + 'three.log', |
| 53 | + 'two.log', |
| 54 | + 'one.log', |
| 55 | + ]); |
| 56 | +}); |
| 57 | + |
| 58 | +it('you can get time sorted asc logs files controller', function () { |
| 59 | + config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::ModifiedTime]); |
| 60 | + |
| 61 | + $names = [ |
| 62 | + 'one.log', |
| 63 | + 'two.log', |
| 64 | + 'three.log', |
| 65 | + ]; |
| 66 | + generateLogFiles($names, randomContent: true); |
| 67 | + array_map(function (string $name) { |
| 68 | + $this->travelTo(now()->addSecond()); |
| 69 | + touch(storage_path('logs/'.$name), now()->timestamp); |
| 70 | + }, $names); |
| 71 | + |
| 72 | + $response = getJson(route('log-viewer.files', ['direction' => 'asc'])); |
| 73 | + |
| 74 | + expect(array_column($response->json(), 'name'))->toBe([ |
| 75 | + 'one.log', |
| 76 | + 'two.log', |
| 77 | + 'three.log', |
| 78 | + ]); |
| 79 | +}); |
0 commit comments