[Operator] Perbaikan Halaman Pegawai dan Export Excel

This commit is contained in:
Ariyutta
2026-11-14 07:11:15 +07:00
parent 1d38086488
commit 59e941d2ce
22 changed files with 904 additions and 146 deletions
+27 -1
View File
@@ -10,6 +10,8 @@ use App\Support\Legacy\Reports\ReportResult;
use App\Support\Legacy\Reports\ReportSource;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\IOFactory;
use ReflectionProperty;
use Tests\Concerns\FakesLegacyDatabase;
use Tests\TestCase;
@@ -202,7 +204,7 @@ class LegacyLaporanTest extends TestCase
$page = $this->get(route('operator.halaman', 'repp_daftarpeg'))->assertOk()
->assertSee('satuRemoteTable', false)->assertDontSee('Parameter laporan')->assertDontSee('Gunakan KOP')->assertDontSee('Lihat di Tab Baru')
->assertSee('Unduh (CSV)')->assertSee('linkWith(', false)->assertSee(str_replace('/', '\\/', route('operator.laporan.unduh', 'repp_daftarpeg')), false)
->assertSee('Unduh (Excel)')->assertDontSee('Unduh (CSV)')->assertSee('linkWith(', false)->assertSee(str_replace('/', '\\/', route('operator.laporan.unduh', 'repp_daftarpeg')), false)
->assertSee('id="satu-q"', false);
foreach (['filter_homebase', 'filter_jenis', 'filter_kelamin', 'filter_aktif'] as $name) {
$page->assertSee('name="'.$name.'"', false);
@@ -219,6 +221,30 @@ class LegacyLaporanTest extends TestCase
$this->assertSame(['Andi Wijaya, S.T., M.Eng.'], array_column($cari, 'nama'), 'Kotak cari daftar menyaring NIP/NIDN/nama.');
}
public function test_daftar_pegawai_diunduh_sebagai_excel(): void
{
(new ReflectionProperty(ReportRegistry::class, 'map'))->setValue($this->original);
$this->seedLegacyEmployees();
$response = $this->get(route('operator.laporan.unduh', ['slug' => 'repp_daftarpeg', 'q' => 'andi wij']))->assertOk();
$this->assertSame('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
$this->assertMatchesRegularExpression('/attachment; filename=repp_daftarpeg-\d{8}-\d{6}\.xlsx/', $response->headers->get('Content-Disposition'));
// Berkas dibuka kembali dengan PhpSpreadsheet: benar-benar .xlsx, bukan CSV berganti nama.
$path = $response->baseResponse->getFile()->getPathname();
$sheet = IOFactory::createReader('Xlsx')->load($path)->getActiveSheet();
@unlink($path);
$this->assertSame('Daftar Pegawai', $sheet->getTitle());
$this->assertSame(2, $sheet->getHighestRow(), 'Kepala + satu pegawai yang cocok dengan filter.');
$rows = $sheet->toArray(null, false, false);
$this->assertSame(['NIP', 'NIDN', 'Nama'], array_slice($rows[0], 0, 3));
$this->assertSame(['198502022010121001', '0002028501', 'Andi Wijaya, S.T., M.Eng.'], array_slice($rows[1], 0, 3), 'NIP dan NIDN tetap teks utuh.');
$this->assertSame([DataType::TYPE_STRING, DataType::TYPE_STRING], [$sheet->getCell('A2')->getDataType(), $sheet->getCell('B2')->getDataType()]);
$this->assertTrue($sheet->getStyle('A1')->getFont()->getBold(), 'Baris kepala tebal.');
$this->assertSame('A2', $sheet->getFreezePane(), 'Baris kepala dibekukan.');
}
public function test_kotak_cari_generik_menyaring_hasil_laporan(): void
{
// Sumber tanpa parameter q: kotak cari tampil dan menyaring semua kolom hasil di server (sampai CAP baris).