[Operator] Integrasi view laman Dashboard, Mahasiswa, dan Pegawai
This commit is contained in:
@@ -75,6 +75,11 @@ trait FakesLegacyDatabase
|
||||
$table->string('gelardepan')->nullable();
|
||||
$table->string('gelarbelakang')->nullable();
|
||||
$table->string('email')->nullable();
|
||||
$table->smallInteger('kelamin')->nullable();
|
||||
$table->string('hp')->nullable();
|
||||
$table->string('telepon')->nullable();
|
||||
$table->smallInteger('statusaktif')->default(1);
|
||||
$table->smallInteger('idstatuspegawai')->nullable();
|
||||
});
|
||||
$schema->create('t_mahasiswa', function (Blueprint $table) {
|
||||
$table->integer('idmahasiswa')->primary();
|
||||
@@ -87,6 +92,7 @@ trait FakesLegacyDatabase
|
||||
$table->integer('idkurikulum')->nullable();
|
||||
$table->integer('idpa')->nullable();
|
||||
$table->smallInteger('stataktif')->default(1);
|
||||
$table->smallInteger('jalur_masuk')->nullable();
|
||||
});
|
||||
$schema->create('t_angkatanmhs', function (Blueprint $table) {
|
||||
$table->integer('idangkatan')->primary();
|
||||
@@ -199,6 +205,21 @@ trait FakesLegacyDatabase
|
||||
$schema->create('t_dosen', function (Blueprint $table) {
|
||||
$table->integer('idpegawai')->primary();
|
||||
$table->integer('idjabatanfungsional')->nullable();
|
||||
$table->integer('idprogdi')->nullable();
|
||||
});
|
||||
$schema->create('t_statuspegawai', function (Blueprint $table) {
|
||||
$table->smallInteger('idstatuspegawai')->primary();
|
||||
$table->string('statuspegawai');
|
||||
});
|
||||
$schema->create('t_jabatanbagian', function (Blueprint $table) {
|
||||
$table->integer('idjabatanbagian')->primary();
|
||||
$table->integer('idbagian');
|
||||
});
|
||||
$schema->create('t_jabatanpegawai', function (Blueprint $table) {
|
||||
$table->increments('idjabatan');
|
||||
$table->integer('idpegawai');
|
||||
$table->integer('idjabatanbagian');
|
||||
$table->smallInteger('aktif')->default(1);
|
||||
});
|
||||
$schema->create('t_jabatanfungsional', function (Blueprint $table) {
|
||||
$table->integer('idjabatanfungsional')->primary();
|
||||
@@ -225,6 +246,29 @@ trait FakesLegacyDatabase
|
||||
$table->smallInteger('idjenisbagian')->nullable();
|
||||
$table->string('namabagian');
|
||||
});
|
||||
$schema->create('t_jenisprogram', function (Blueprint $table) {
|
||||
$table->integer('idprogram')->primary();
|
||||
$table->string('program');
|
||||
});
|
||||
$schema->create('t_jalurmasuk', function (Blueprint $table) {
|
||||
$table->integer('idjalur_siakad')->primary();
|
||||
$table->string('nama_jalur_masuk');
|
||||
});
|
||||
$schema->create('t_stat_akademik', function (Blueprint $table) {
|
||||
$table->integer('idstat_akd')->primary();
|
||||
$table->string('status_akademik');
|
||||
});
|
||||
$schema->create('t_jenjangprogdi', function (Blueprint $table) {
|
||||
$table->integer('idjenjang')->primary();
|
||||
$table->string('kdjenjang');
|
||||
$table->char('kode', 1);
|
||||
});
|
||||
// Data prodi PDDIKTI: jenjang per prodi (idbagianuntan); bisa ganda seperti di DB asli.
|
||||
$schema->create('pdpt_tmst_program_studi', function (Blueprint $table) {
|
||||
$table->string('kode_program_studi');
|
||||
$table->integer('idbagianuntan')->nullable();
|
||||
$table->char('kode_jenjang_pendidikan', 1)->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
private function seedLegacyData(): void
|
||||
@@ -282,7 +326,7 @@ trait FakesLegacyDatabase
|
||||
{
|
||||
$db = DB::connection('untan');
|
||||
|
||||
$db->table('t_periodekuliah')->insert([
|
||||
$db->table('t_periodekuliah')->insertOrIgnore([
|
||||
['idperiode' => 362, 'thakad' => '2019/2020', 'semester' => 1, 'perkuliahan' => 1],
|
||||
['idperiode' => 365, 'thakad' => '2019/2020', 'semester' => 2, 'perkuliahan' => 1],
|
||||
['idperiode' => 366, 'thakad' => '2019/2020', 'semester' => 2, 'perkuliahan' => 2],
|
||||
@@ -391,13 +435,46 @@ trait FakesLegacyDatabase
|
||||
* KRS: 3 dari 3 aktif sudah mengisi, 1 menunggu (500); masa pengisian hanya untuk prodi 21 (dibuka).
|
||||
* Kelas: 602 tanpa jadwal dan nilai belum terbit; 603 hanya peserta batal; 604 tugas akhir tanpa jadwal.
|
||||
*/
|
||||
/**
|
||||
* Pegawai untuk Portal > Pegawai (butuh seedLegacyOverview: akun 1 memegang prodi 21 dan 22, fakultas 5).
|
||||
* Dalam cakupan: 11 Siti (dosen prodi 21, PA mahasiswa 500), 20 Andi (dosen prodi 22, tidak aktif),
|
||||
* 21 Dewi (staf, jabatan aktif di fakultas 5), 24 Lina (dosen prodi 21). Di luar: 22 (prodi lain), 23 (jabatan lama).
|
||||
*/
|
||||
protected function seedLegacyEmployees(): void
|
||||
{
|
||||
$db = DB::connection('untan');
|
||||
|
||||
$db->table('t_statuspegawai')->insert([
|
||||
['idstatuspegawai' => 1, 'statuspegawai' => 'tanpa status'],
|
||||
['idstatuspegawai' => 2, 'statuspegawai' => 'Tetap'],
|
||||
['idstatuspegawai' => 3, 'statuspegawai' => 'Tidak Tetap'],
|
||||
]);
|
||||
$db->table('t_pegawai')->where('idpegawai', 11)->update(['kelamin' => 2, 'hp' => '081234567890', 'email' => 'siti@untan.ac.id', 'idstatuspegawai' => 2]);
|
||||
$db->table('t_pegawai')->insert([
|
||||
['idpegawai' => 20, 'nip' => '198502022010121001', 'nama' => 'Andi Wijaya', 'gelardepan' => '', 'gelarbelakang' => 'S.T., M.Eng.', 'nidn' => '0002028501', 'kelamin' => 1, 'hp' => '', 'telepon' => null, 'statusaktif' => 0, 'idstatuspegawai' => 3],
|
||||
['idpegawai' => 21, 'nip' => '199003032015032001', 'nama' => 'Dewi Kartika', 'gelardepan' => null, 'gelarbelakang' => null, 'nidn' => null, 'kelamin' => 2, 'hp' => ' ', 'telepon' => '0561-123456', 'statusaktif' => 1, 'idstatuspegawai' => null],
|
||||
['idpegawai' => 22, 'nip' => '197001012000011099', 'nama' => 'Joko Prodi Lain', 'gelardepan' => null, 'gelarbelakang' => null, 'nidn' => null, 'kelamin' => 1, 'hp' => null, 'telepon' => null, 'statusaktif' => 1, 'idstatuspegawai' => 2],
|
||||
['idpegawai' => 23, 'nip' => '196501011990011023', 'nama' => 'Rudi Mantan', 'gelardepan' => null, 'gelarbelakang' => null, 'nidn' => null, 'kelamin' => 1, 'hp' => null, 'telepon' => null, 'statusaktif' => 1, 'idstatuspegawai' => 2],
|
||||
['idpegawai' => 24, 'nip' => 'lina', 'nama' => 'Lina', 'gelardepan' => null, 'gelarbelakang' => null, 'nidn' => null, 'kelamin' => 0, 'hp' => null, 'telepon' => null, 'statusaktif' => 3, 'idstatuspegawai' => 1],
|
||||
]);
|
||||
$db->table('t_dosen')->where('idpegawai', 11)->update(['idprogdi' => 21]);
|
||||
$db->table('t_dosen')->insert([['idpegawai' => 20, 'idprogdi' => 22], ['idpegawai' => 22, 'idprogdi' => 99], ['idpegawai' => 24, 'idprogdi' => 21]]);
|
||||
$db->table('t_jabatanbagian')->insert([['idjabatanbagian' => 1, 'idbagian' => 5], ['idjabatanbagian' => 2, 'idbagian' => 5]]);
|
||||
$db->table('t_jabatanpegawai')->insert([
|
||||
['idpegawai' => 21, 'idjabatanbagian' => 1, 'aktif' => 1],
|
||||
['idpegawai' => 23, 'idjabatanbagian' => 2, 'aktif' => 0],
|
||||
]);
|
||||
$db->table('t_mahasiswa')->where('idmahasiswa', 500)->update(['idpa' => 11]);
|
||||
}
|
||||
|
||||
protected function seedLegacyOverview(): void
|
||||
{
|
||||
$db = DB::connection('untan');
|
||||
|
||||
$db->table('t_bagian')->insert(['idbagian' => 22, 'idbagian_induk' => 5, 'idjenisbagian' => 3, 'namabagian' => 'Teknik Sipil']);
|
||||
$db->table('t_unituser')->insert([['iduser' => 1, 'idfak' => 5, 'idprogdi' => 21], ['iduser' => 1, 'idfak' => 5, 'idprogdi' => 22]]);
|
||||
$db->table('t_periodekuliah')->insert([
|
||||
// insertOrIgnore: 365 dan 366 juga dibuat seedLegacyGrades().
|
||||
$db->table('t_periodekuliah')->insertOrIgnore([
|
||||
['idperiode' => 365, 'thakad' => '2019/2020', 'semester' => 2, 'perkuliahan' => 1],
|
||||
['idperiode' => 366, 'thakad' => '2019/2020', 'semester' => 2, 'perkuliahan' => 2],
|
||||
['idperiode' => 368, 'thakad' => '2020/2021', 'semester' => 1, 'perkuliahan' => 1],
|
||||
@@ -410,9 +487,29 @@ trait FakesLegacyDatabase
|
||||
]);
|
||||
$db->table('t_angkatanmhs')->insert([['idangkatan' => 160, 'tahun' => 2020, 'semester' => 1], ['idangkatan' => 170, 'tahun' => 2021, 'semester' => 1]]);
|
||||
|
||||
// idmahasiswa => [idprogdi, idangkatan, stataktif]
|
||||
foreach ([501 => [21, 150, 1], 502 => [21, 160, 1], 503 => [21, 150, 1], 504 => [21, 170, 1], 505 => [21, 150, 2], 510 => [22, 160, 1], 511 => [22, 160, 1]] as $id => [$prodi, $angkatan, $stat]) {
|
||||
$db->table('t_mahasiswa')->insert(['idmahasiswa' => $id, 'nim' => 'X'.$id, 'nama' => 'Mahasiswa '.$id, 'idprogdi' => $prodi, 'idangkatan' => $angkatan, 'stataktif' => $stat]);
|
||||
$db->table('t_jenisprogram')->insert([['idprogram' => 1, 'program' => 'Reguler A'], ['idprogram' => 2, 'program' => 'Reguler B']]);
|
||||
$db->table('t_jalurmasuk')->insert([['idjalur_siakad' => 1, 'nama_jalur_masuk' => 'SNMPTN'], ['idjalur_siakad' => 3, 'nama_jalur_masuk' => 'MANDIRI']]);
|
||||
$db->table('t_jenjangprogdi')->insert([['idjenjang' => 2, 'kdjenjang' => 'S1', 'kode' => 'C'], ['idjenjang' => 1, 'kdjenjang' => 'D3', 'kode' => 'E']]);
|
||||
$db->table('pdpt_tmst_program_studi')->insert([
|
||||
['kode_program_studi' => '55201', 'idbagianuntan' => 21, 'kode_jenjang_pendidikan' => 'C'],
|
||||
['kode_program_studi' => '55201L', 'idbagianuntan' => 21, 'kode_jenjang_pendidikan' => 'C'],
|
||||
]);
|
||||
$db->table('t_stat_akademik')->insert([
|
||||
['idstat_akd' => 0, 'status_akademik' => 'Alpa Kuliah'], ['idstat_akd' => 1, 'status_akademik' => 'Aktif'],
|
||||
['idstat_akd' => 2, 'status_akademik' => 'Cuti'], ['idstat_akd' => 3, 'status_akademik' => 'Lulus'],
|
||||
]);
|
||||
$db->table('t_mahasiswa')->where('idmahasiswa', 500)->update(['idprogram' => 1, 'jalur_masuk' => 1]);
|
||||
|
||||
// idmahasiswa => [idprogdi, idangkatan, stataktif, idprogram, jalur]; 506 mengundurkan diri (stataktif 3).
|
||||
$students = [
|
||||
501 => [21, 150, 1, 1, 1], 502 => [21, 160, 1, 1, 3], 503 => [21, 150, 1, 2, 3], 504 => [21, 170, 1, 1, 1],
|
||||
505 => [21, 150, 2, 1, 1], 506 => [21, 150, 3, 1, 1], 510 => [22, 160, 1, 1, 1], 511 => [22, 160, 1, 1, 1],
|
||||
];
|
||||
foreach ($students as $id => [$prodi, $angkatan, $stat, $program, $jalur]) {
|
||||
$db->table('t_mahasiswa')->insert([
|
||||
'idmahasiswa' => $id, 'nim' => 'X'.$id, 'nama' => 'Mahasiswa '.$id, 'idprogdi' => $prodi,
|
||||
'idangkatan' => $angkatan, 'stataktif' => $stat, 'idprogram' => $program, 'jalur_masuk' => $jalur,
|
||||
]);
|
||||
}
|
||||
|
||||
$histori = fn (int $mhs, int $periode, ?int $stat, ?float $ips = null): array => ['idmahasiswa' => $mhs, 'idperiode' => $periode, 'stat_akd_akhir' => $stat, 'ips' => $ips];
|
||||
|
||||
@@ -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