[Operator] Kelengkapan Halaman Dosen
This commit is contained in:
@@ -12,6 +12,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use ReflectionProperty;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\TestCase;
|
||||
@@ -66,7 +67,8 @@ class LegacyLaporanTest extends TestCase
|
||||
// panel "Parameter laporan", KOP, maupun tombol Tampilkan.
|
||||
$page = $this->get(route('operator.halaman', ['slug' => $this->slug]))->assertOk()
|
||||
->assertSee('satuRemoteTable', false)->assertDontSee('Parameter laporan')->assertDontSee('Gunakan KOP')->assertDontSee('laporanReport', false)
|
||||
->assertSee('Unduh (CSV)')->assertDontSee('Lihat di Tab Baru')->assertSee('Catatan uji laporan.')
|
||||
->assertSee('Unduh (CSV)')->assertSee('class="btn btn--secondary btn--sm"', false)->assertDontSee('btn--teal', false)
|
||||
->assertDontSee('Lihat di Tab Baru')->assertSee('Catatan uji laporan.')
|
||||
->assertSee('Lengkapi filter yang wajib diisi (Program Studi)')->assertDontSee('Tampilkan');
|
||||
foreach (['filter_prodi', 'filter_q', 'filter_tgl', 'filter_n'] as $name) {
|
||||
$page->assertSee('name="'.$name.'"', false);
|
||||
@@ -245,6 +247,91 @@ class LegacyLaporanTest extends TestCase
|
||||
$this->assertSame('A2', $sheet->getFreezePane(), 'Baris kepala dibekukan.');
|
||||
}
|
||||
|
||||
public function test_daftar_dosen_diunduh_sebagai_excel(): void
|
||||
{
|
||||
(new ReflectionProperty(ReportRegistry::class, 'map'))->setValue($this->original);
|
||||
$this->seedLegacyEmployees();
|
||||
|
||||
$this->get(route('operator.halaman', 'repp_daftardosen'))->assertOk()->assertSee('Unduh (Excel)')->assertDontSee('Unduh (CSV)')
|
||||
->assertSee('class="btn btn--teal btn--sm"', false);
|
||||
|
||||
$sheetOf = function (array $query): Worksheet {
|
||||
$response = $this->get(route('operator.laporan.unduh', ['slug' => 'repp_daftardosen'] + $query))->assertOk();
|
||||
$this->assertSame('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
|
||||
$this->assertMatchesRegularExpression('/attachment; filename=repp_daftardosen-\d{8}-\d{6}\.xlsx/', $response->headers->get('Content-Disposition'));
|
||||
$path = $response->baseResponse->getFile()->getPathname();
|
||||
$sheet = IOFactory::createReader('Xlsx')->load($path)->getActiveSheet();
|
||||
@unlink($path);
|
||||
|
||||
return $sheet;
|
||||
};
|
||||
|
||||
$semua = $sheetOf([]);
|
||||
$this->assertSame('Daftar Dosen', $semua->getTitle());
|
||||
$this->assertSame(['NIP', 'NIDN', 'Nama'], array_slice($semua->toArray(null, false, false)[0], 0, 3));
|
||||
$jumlah = count($this->getJson(route('operator.laporan.data', ['slug' => 'repp_daftardosen', 'per' => 100]))->assertOk()->json('rows'));
|
||||
$this->assertGreaterThan(1, $jumlah);
|
||||
$this->assertSame($jumlah + 1, $semua->getHighestRow(), 'Semua baris laporan ikut diunduh.');
|
||||
|
||||
// Laporan ini tidak mengenal kata cari di sumbernya: kotak cari menyaring baris unduhan seperti di tabel.
|
||||
$cari = $sheetOf(['q' => 'andi wij']);
|
||||
$this->assertSame(2, $cari->getHighestRow(), 'Kepala + satu dosen yang cocok dengan kata cari.');
|
||||
$this->assertSame(['198502022010121001', '0002028501', 'Andi Wijaya, S.T., M.Eng.'], array_slice($cari->toArray(null, false, false)[1], 0, 3));
|
||||
$this->assertSame(DataType::TYPE_STRING, $cari->getCell('A2')->getDataType());
|
||||
}
|
||||
|
||||
public function test_rasio_dosen_diunduh_sebagai_excel_dengan_angka(): void
|
||||
{
|
||||
(new ReflectionProperty(ReportRegistry::class, 'map'))->setValue($this->original);
|
||||
$this->seedLegacyEmployees();
|
||||
|
||||
$this->get(route('operator.halaman', 'repp_rasiodosenins'))->assertOk()->assertSee('Unduh (Excel)')->assertDontSee('Unduh (CSV)')
|
||||
->assertSee('class="btn btn--teal btn--sm"', false);
|
||||
|
||||
$response = $this->get(route('operator.laporan.unduh', 'repp_rasiodosenins'))->assertOk();
|
||||
$this->assertSame('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
|
||||
$this->assertMatchesRegularExpression('/attachment; filename=repp_rasiodosenins-\d{8}-\d{6}\.xlsx/', $response->headers->get('Content-Disposition'));
|
||||
$path = $response->baseResponse->getFile()->getPathname();
|
||||
$sheet = IOFactory::createReader('Xlsx')->load($path)->getActiveSheet();
|
||||
@unlink($path);
|
||||
|
||||
// Isi berkas sama dengan tabel di layar: kepala, baris per prodi, lalu baris Jumlah.
|
||||
$json = $this->getJson(route('operator.laporan.data', ['slug' => 'repp_rasiodosenins', 'per' => 100]))->assertOk()->json();
|
||||
$rows = $sheet->toArray(null, false, false);
|
||||
$this->assertSame('Rasio Dosen', $sheet->getTitle());
|
||||
$this->assertSame(array_column($json['columns'], 'label'), $rows[0]);
|
||||
$this->assertSame(['Program Studi', 'Jumlah Dosen', 'Dosen Tetap', 'Dosen Tidak Tetap', 'Mahasiswa Aktif', 'Mahasiswa per Dosen'], $rows[0]);
|
||||
$this->assertNotEmpty($json['rows']);
|
||||
$this->assertEquals(array_map(fn (array $row): array => array_values(array_diff_key($row, ['id' => 1, '_total' => 1])), $json['rows']), array_slice($rows, 1));
|
||||
$last = $sheet->getHighestRow();
|
||||
$this->assertSame('Jumlah', $sheet->getCell('A'.$last)->getValue());
|
||||
|
||||
// Baris Jumlah diberi arsir agar terpisah dari baris prodi: penanda di JSON (kelas table__row--total di tabel),
|
||||
// arsir + tebal selebar tabel di Excel, dan kelas tersendiri di halaman cetak. Baris lain tidak.
|
||||
$this->assertSame([count($json['rows']) - 1], array_keys(array_filter($json['rows'], fn (array $row): bool => $row['_total'] ?? false)));
|
||||
$this->assertArrayNotHasKey('_total', $json['rows'][0]);
|
||||
foreach (['A', 'F'] as $column) {
|
||||
$this->assertSame('FFF2CC', $sheet->getStyle($column.$last)->getFill()->getStartColor()->getRGB(), "Sel {$column}{$last} berarsir.");
|
||||
$this->assertTrue($sheet->getStyle($column.$last)->getFont()->getBold());
|
||||
$this->assertNotSame('FFF2CC', $sheet->getStyle($column.'2')->getFill()->getStartColor()->getRGB());
|
||||
}
|
||||
$this->assertFalse($sheet->getStyle('A2')->getFont()->getBold());
|
||||
$this->assertSame(1, substr_count($this->get(route('operator.laporan.cetak', 'repp_rasiodosenins'))->assertOk()->getContent(), 'class="report-print__total"'));
|
||||
// Kata cari hanya mencocokkan kolom, bukan penanda baris: "jumlah" menemukan baris Jumlah saja (penandanya ikut),
|
||||
// kata yang tidak ada di kolom mana pun tidak menemukan apa-apa.
|
||||
$cari = fn (string $q): array => $this->getJson(route('operator.laporan.data', ['slug' => 'repp_rasiodosenins', 'q' => $q]))->assertOk()->json('rows');
|
||||
$this->assertSame([['Jumlah', true]], array_map(fn (array $row): array => [$row['prodi'], $row['_total'] ?? false], $cari('jumlah')));
|
||||
$this->assertSame([], $cari('true'));
|
||||
|
||||
// Kolom angka ditulis sebagai bilangan (bisa dijumlahkan di Excel), termasuk nol; nama prodi tetap teks.
|
||||
$this->assertSame(DataType::TYPE_STRING, $sheet->getCell('A2')->getDataType());
|
||||
foreach (['B', 'C', 'D', 'E'] as $column) {
|
||||
foreach (range(2, $sheet->getHighestRow()) as $n) {
|
||||
$this->assertSame(DataType::TYPE_NUMERIC, $sheet->getCell($column.$n)->getDataType(), "Sel {$column}{$n} berupa bilangan.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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).
|
||||
|
||||
Reference in New Issue
Block a user