[Operator] Integrasi view laman Dashboard, Mahasiswa, dan Pegawai
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Operator;
|
||||
|
||||
use App\Models\User;
|
||||
use DOMXPath;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\Concerns\InspectsHtml;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Portal > Pegawai (operator.halaman list_pegawai) dari DB lama; data dari seedLegacyEmployees().
|
||||
* Tampilan sama dengan prototipe SATU; filter, cari, dan halaman diambil dari operator.pegawai.data (JSON).
|
||||
*/
|
||||
class LegacyEmployeeListTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
use InspectsHtml;
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
$this->seedLegacyOverview();
|
||||
$this->seedLegacyEmployees();
|
||||
$this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf'])
|
||||
->assertRedirect(route('operator.dashboard'));
|
||||
}
|
||||
|
||||
private function data(array $query = []): TestResponse
|
||||
{
|
||||
return $this->getJson(route('operator.pegawai.data', $query))->assertOk();
|
||||
}
|
||||
|
||||
/** @return array<string, list<string>> nama => [nip, l/p, nidn, nuptk, telp, email, status] */
|
||||
private function rows(array $query = []): array
|
||||
{
|
||||
return collect($this->data($query)->json('rows'))
|
||||
->mapWithKeys(fn (array $r): array => [$r['nama'] => [$r['nip'], $r['kelamin'], $r['nidn'], $r['nuptk'], $r['telepon'], $r['email'], $r['status']]])
|
||||
->all();
|
||||
}
|
||||
|
||||
/** Judul kolom, label filter, tombol bilah, dan aksi baris halaman daftar. */
|
||||
private function layout(DOMXPath $xpath): array
|
||||
{
|
||||
$panel = "//*[@aria-label='Daftar Pegawai']";
|
||||
$texts = fn (string $query): array => array_map(fn ($node): string => $this->textOf($node), iterator_to_array($xpath->query($query)));
|
||||
|
||||
return [
|
||||
'headers' => $texts("{$panel}//thead/tr/th"),
|
||||
'filters' => $texts("//section[@aria-label='Filter data']//label"),
|
||||
'tools' => $texts("{$panel}//div[contains(@class, 'satu-bar__tools')]//button"),
|
||||
'row_actions' => array_map(fn ($node): string => $node->getAttribute('aria-label'), iterator_to_array($xpath->query("{$panel}//tbody//td[contains(@class, 'table__actions')]//button"))),
|
||||
'pager' => $xpath->query("//nav[@aria-label='Halaman data']")->length,
|
||||
];
|
||||
}
|
||||
|
||||
public function test_page_matches_the_prototype_layout(): void
|
||||
{
|
||||
$response = $this->get(route('operator.halaman', 'list_pegawai'))->assertOk()
|
||||
->assertSee('Data pegawai asli dari SIAKAD')
|
||||
->assertSee('satuRemoteTable', false)
|
||||
->assertSee('Siti Aminah');
|
||||
$legacy = $this->layout($this->dom($response));
|
||||
|
||||
$this->assertSame(['', 'NIP', 'Nama', 'L/P', 'NIDN', 'NUPTK', 'No. Telp.', 'Email', 'Status', 'Aksi'], $legacy['headers']);
|
||||
$this->assertSame(['Kuota Pembimbing Akademik', 'Status Aktif', 'Status'], $legacy['filters']);
|
||||
$this->assertSame(['Aksi', 'Cetak'], $legacy['tools']);
|
||||
$this->assertSame(['Lihat', 'Ubah', 'Hapus'], $legacy['row_actions']);
|
||||
$this->assertSame(0, $this->dom($response)->query('//main//form')->length, 'Filter tidak memakai formulir (alamat tetap).');
|
||||
$this->assertSame(1, $this->dom($response)->query("//a[@aria-current='page' and contains(@href, '/list_pegawai')]")->length);
|
||||
|
||||
// Prototipe akun demo: susunan yang sama persis.
|
||||
Auth::logout();
|
||||
config(['auth.guards.web.provider' => 'users']);
|
||||
Auth::forgetGuards();
|
||||
$prototype = $this->actingAs(User::factory()->operator()->create())->get(route('operator.halaman', 'list_pegawai'))->assertOk();
|
||||
$this->assertSame($this->layout($this->dom($prototype)), $legacy);
|
||||
}
|
||||
|
||||
public function test_data_lists_employees_of_the_operators_units(): void
|
||||
{
|
||||
$this->data()->assertJson(['page' => 1, 'last_page' => 1, 'total' => 4, 'per_page' => 10]);
|
||||
|
||||
$this->assertSame([
|
||||
'Andi Wijaya, S.T., M.Eng.' => ['198502022010121001', 'L', '0002028501', '–', '–', '–', 'Tidak Tetap'],
|
||||
'Dewi Kartika' => ['199003032015032001', 'P', '–', '–', '0561-123456', '–', 'Belum diisi'],
|
||||
'Lina' => ['lina', '–', '–', '–', '–', '–', 'Tanpa status'],
|
||||
'Siti Aminah, M.Pd.' => ['197501012000031002', 'P', '0001017501', '–', '081234567890', 'siti@untan.ac.id', 'Tetap'],
|
||||
], $this->rows(), 'Dosen prodi lain, pegawai tanpa kaitan, dan jabatan lama tidak ikut.');
|
||||
$this->assertSame(['gold', null, null, 'success'], array_column($this->data()->json('rows'), 'tone'));
|
||||
}
|
||||
|
||||
public function test_search_and_filters(): void
|
||||
{
|
||||
$names = fn (array $query): array => array_keys($this->rows($query));
|
||||
|
||||
$this->assertSame(['Dewi Kartika'], $names(['q' => 'kartika']));
|
||||
$this->assertSame(['Siti Aminah, M.Pd.'], $names(['q' => '0001017501']));
|
||||
$this->assertSame(['Siti Aminah, M.Pd.'], $names(['advisor' => 'ada']));
|
||||
$this->assertSame(['Andi Wijaya, S.T., M.Eng.', 'Dewi Kartika', 'Lina'], $names(['advisor' => 'tidak']));
|
||||
$this->assertSame(['Andi Wijaya, S.T., M.Eng.'], $names(['active' => 'nonaktif']));
|
||||
$this->assertSame(['Dewi Kartika', 'Lina', 'Siti Aminah, M.Pd.'], $names(['active' => 'aktif']));
|
||||
$this->assertSame(['Siti Aminah, M.Pd.'], $names(['status' => 2]));
|
||||
$this->assertSame(['Lina'], $names(['status' => 1]));
|
||||
$this->assertSame(['Dewi Kartika'], $names(['status' => 0]));
|
||||
$this->data(['q' => 'tidak-ada'])->assertJson(['rows' => [], 'total' => 0]);
|
||||
}
|
||||
|
||||
public function test_unknown_filter_values_are_ignored_and_paging_works(): void
|
||||
{
|
||||
$this->assertCount(4, $this->rows(['advisor' => 'semua', 'active' => 'x', 'status' => 99]));
|
||||
|
||||
foreach (range(30, 40) as $id) {
|
||||
DB::connection('untan')->table('t_pegawai')->insert(['idpegawai' => $id, 'nip' => 'N'.$id, 'nama' => 'Zaki '.$id]);
|
||||
DB::connection('untan')->table('t_dosen')->insert(['idpegawai' => $id, 'idprogdi' => 21]);
|
||||
}
|
||||
$this->data()->assertJson(['total' => 15, 'last_page' => 2])->assertJsonCount(10, 'rows');
|
||||
$this->data(['page' => 2])->assertJsonCount(5, 'rows');
|
||||
$this->data(['per' => 25])->assertJson(['per_page' => 25, 'last_page' => 1]);
|
||||
}
|
||||
|
||||
public function test_account_without_programs_sees_empty_state(): void
|
||||
{
|
||||
DB::connection('untan')->table('t_unituser')->whereNotNull('idprogdi')->delete();
|
||||
|
||||
$this->get(route('operator.halaman', 'list_pegawai'))->assertOk()->assertSee('Akun belum terhubung ke program studi');
|
||||
$this->getJson(route('operator.pegawai.data'))->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_data_endpoint_access(): void
|
||||
{
|
||||
Auth::logout();
|
||||
$this->get(route('operator.pegawai.data'))->assertRedirect(route('login'));
|
||||
|
||||
$this->post(route('login.store'), ['username' => 'D1041191001', 'password' => 'rahasia-mhs']);
|
||||
$this->getJson(route('operator.pegawai.data'))->assertForbidden();
|
||||
|
||||
Auth::logout();
|
||||
config(['auth.guards.web.provider' => 'users']);
|
||||
Auth::forgetGuards();
|
||||
$this->actingAs(User::factory()->operator()->create())->getJson(route('operator.pegawai.data'))->assertNotFound();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Operator;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\Concerns\InspectsHtml;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Portal > 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<string, list<string>> 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', 'Aksi', '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')->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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Filter dan pilihan dimuat lewat fetch, jadi Referer formulir tidak membawa query.
|
||||
* Validasi gagal harus kembali ke alamat lengkap yang tercatat di sesi.
|
||||
*/
|
||||
class PreferSessionPreviousUrlTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_failed_validation_returns_to_the_filtered_page(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->dosen()->create());
|
||||
|
||||
// Pilihan kelas lewat fetch: tercatat di sesi, alamat peramban tetap tanpa query
|
||||
$this->get(route('dosen.penilaian', ['kelas' => 2]))->assertOk();
|
||||
|
||||
$this->withHeader('referer', route('dosen.penilaian'))
|
||||
->post(route('dosen.penilaian.store'), ['kelas' => 2, 'nilai' => [['tugas' => 999]]])
|
||||
->assertRedirect(route('dosen.penilaian', ['kelas' => 2]))
|
||||
->assertSessionHasErrors('nilai.0.tugas');
|
||||
}
|
||||
|
||||
public function test_referer_of_another_page_is_kept(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->dosen()->create());
|
||||
$this->get(route('dosen.penilaian', ['kelas' => 2]))->assertOk();
|
||||
|
||||
$this->withHeader('referer', route('dosen.dashboard'))
|
||||
->post(route('dosen.penilaian.store'), ['kelas' => 2, 'nilai' => [['tugas' => 999]]])
|
||||
->assertRedirect(route('dosen.dashboard'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user