Mahasiswa (operator.halaman list_mahasiswa) dari DB lama; data dari seedLegacyOverview(). * Halaman memakai template SATU; filter, cari, dan halaman diambil dari operator.mahasiswa.data (JSON). */ class LegacyStudentListTest extends TestCase { use FakesLegacyDatabase; use InspectsHtml; use RefreshDatabase; protected function setUp(): void { parent::setUp(); $this->useLegacyDatabase(); $this->seedLegacyOverview(); $this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf']) ->assertRedirect(route('operator.dashboard')); } private function page(): TestResponse { return $this->get(route('operator.halaman', 'list_mahasiswa'))->assertOk(); } private function data(array $query = []): TestResponse { return $this->getJson(route('operator.mahasiswa.data', $query))->assertOk(); } /** @return array> NIM => [nama, jenjang, prodi, masuk, status, smt, sks, ipk] */ private function rows(array $query = []): array { return collect($this->data($query)->json('rows')) ->mapWithKeys(fn (array $r): array => [$r['nim'] => [$r['nama'], $r['jenjang'], $r['prodi'], $r['masuk'], $r['status'], $r['smt'], $r['sks'], $r['ipk']]]) ->all(); } public function test_page_keeps_the_satu_template(): void { $response = $this->page() ->assertSee('Data mahasiswa asli dari SIAKAD untuk program studi yang Anda kelola.') ->assertDontSee('Isi tabel adalah data contoh') ->assertSee('satuRemoteTable', false) ->assertSee('Rina Lestari'); $xpath = $this->dom($response); $panel = "//*[@aria-label='Daftar Mahasiswa']"; // Kolom dan filter sama dengan halaman SATU list_mahasiswa. $headers = array_map(fn ($th): string => $this->textOf($th), iterator_to_array($xpath->query("{$panel}//thead/tr/th"))); $this->assertSame(['', 'NIM', 'Nama', 'Jenjang', 'Program Studi', 'Masuk', 'Status', 'Smt', 'SKS', 'IPK', 'Aksi'], $headers); $labels = array_map(fn ($label): string => $this->textOf($label), iterator_to_array($xpath->query("//section[@aria-label='Filter data']//label"))); $this->assertSame(['Unit / Program Studi', 'Angkatan', 'Status Mahasiswa', 'Sistem Kuliah', 'Jalur Pendaftaran'], $labels); foreach (['Tambah', 'Hapus', 'Cetak'] as $label) { $this->assertSame(1, $xpath->query("{$panel}//div[contains(@class, 'satu-bar__tools')]//button[normalize-space()='{$label}']")->length, "Tombol {$label}"); } foreach (['Lihat', 'Ubah', 'Hapus'] as $label) { $this->assertSame(1, $xpath->query("{$panel}//tbody/template//button[@aria-label='{$label}']")->length, "Aksi baris {$label}"); } $this->assertSame(1, $xpath->query("//nav[@aria-label='Halaman data']")->length); // Tidak ada formulir: filter dan halaman tidak mengubah alamat halaman. $this->assertSame(0, $xpath->query('//main//form[not(ancestor::dialog)]')->length); $nav = $xpath->query("//a[@aria-current='page' and contains(@href, '/list_mahasiswa')]"); $this->assertSame(1, $nav->length, 'Menu Portal > Mahasiswa aktif.'); } public function test_data_returns_real_students_of_the_operators_programs(): void { $this->seedLegacyGrades(); $this->data()->assertJson(['page' => 1, 'last_page' => 1, 'total' => 9, 'per_page' => 10]); $rows = $this->rows(); $this->assertSame(['D1041191001', 'X501', 'X502', 'X503', 'X504', 'X505', 'X506', 'X510', 'X511'], array_keys($rows), 'Jenjang ganda di PDDIKTI tidak menggandakan baris.'); $this->assertSame(['Rina Lestari', 'S1', 'Teknik Informatika', '2019', 'Aktif', '3', '8', '3,07'], $rows['D1041191001']); $this->assertSame(['Cuti', '3'], array_slice($rows['X501'], 4, 2)); $this->assertSame(['Aktif', '1', '0', '–'], array_slice($rows['X502'], 4)); $this->assertSame('Belum berstatus', $rows['X503'][4]); $this->assertSame(['Belum berstatus', '–'], array_slice($rows['X504'], 4, 2), 'Angkatan setelah periode aktif tanpa nomor semester.'); $this->assertSame(['Lulus', '–'], array_slice($rows['X505'], 4, 2)); $this->assertSame('Mengundurkan diri', $rows['X506'][4]); $this->assertSame(['–', 'Teknik Sipil'], array_slice($rows['X510'], 1, 2)); $this->assertSame(['success', 'info', null], [ $this->data()->json('rows.0.tone'), $this->data(['status' => 'lulus'])->json('rows.0.tone'), $this->data(['status' => 'keluar'])->json('rows.0.tone'), ]); } public function test_search_and_filters(): void { $this->assertSame(['D1041191001'], array_keys($this->rows(['q' => 'rina']))); $this->assertSame(['X505'], array_keys($this->rows(['q' => 'x505']))); $this->assertSame(['X510', 'X511'], array_keys($this->rows(['prodi' => 22]))); $this->assertSame(['X502', 'X510', 'X511'], array_keys($this->rows(['angkatan' => 2020]))); $this->assertSame(['X505'], array_keys($this->rows(['status' => 'lulus']))); $this->assertSame(['X506'], array_keys($this->rows(['status' => 'keluar']))); $this->assertSame(['X503'], array_keys($this->rows(['program' => 2]))); $this->assertSame(['X502', 'X503'], array_keys($this->rows(['jalur' => 3]))); $this->data(['q' => 'tidak-ada'])->assertJson(['rows' => [], 'total' => 0]); } public function test_paging_and_rows_per_page(): void { foreach (range(520, 532) as $id) { DB::connection('untan')->table('t_mahasiswa')->insert(['idmahasiswa' => $id, 'nim' => 'Y'.$id, 'nama' => 'Tambahan '.$id, 'idprogdi' => 21, 'idangkatan' => 160]); } $this->data()->assertJson(['page' => 1, 'last_page' => 3, 'total' => 22])->assertJsonCount(10, 'rows'); $this->assertSame(['Y530', 'Y531', 'Y532'], array_keys($this->rows(['page' => 2, 'q' => 'tambahan']))); $this->data(['per' => 25])->assertJson(['per_page' => 25, 'last_page' => 1])->assertJsonCount(22, 'rows'); $this->data(['per' => 500])->assertJson(['per_page' => 10]); } public function test_out_of_scope_filters_are_ignored(): void { // Prodi milik akun lain dan nilai pilihan yang tidak ada diabaikan. $this->assertCount(9, $this->rows(['prodi' => 99, 'angkatan' => 1990, 'status' => 'semua', 'jalur' => 42])); DB::connection('untan')->table('t_mahasiswa')->insert(['idmahasiswa' => 900, 'nim' => 'Z900', 'nama' => 'Prodi Lain', 'idprogdi' => 99]); $this->data(['q' => 'Z900'])->assertJson(['total' => 0]); } public function test_account_without_programs_sees_empty_state(): void { DB::connection('untan')->table('t_unituser')->whereNotNull('idprogdi')->delete(); $this->page()->assertSee('Akun belum terhubung ke program studi'); $this->getJson(route('operator.mahasiswa.data'))->assertNotFound(); } public function test_demo_operator_keeps_the_prototype_page(): void { Auth::logout(); config(['auth.guards.web.provider' => 'users']); Auth::forgetGuards(); $operator = User::factory()->operator()->create(); $this->actingAs($operator)->get(route('operator.halaman', 'list_mahasiswa'))->assertOk()->assertSee('Tampilan prototipe'); $this->actingAs($operator)->getJson(route('operator.mahasiswa.data'))->assertNotFound(); } public function test_data_endpoint_requires_the_operator_role(): void { Auth::logout(); $this->get(route('operator.mahasiswa.data'))->assertRedirect(route('login')); $this->post(route('login.store'), ['username' => 'D1041191001', 'password' => 'rahasia-mhs']); $this->getJson(route('operator.mahasiswa.data'))->assertForbidden(); } }