Penambahan menu Perkuliahan

This commit is contained in:
Ariyutta
2026-11-06 02:23:37 +07:00
parent ddd02d7df9
commit efb3a1d41d
57 changed files with 7427 additions and 88 deletions
@@ -0,0 +1,132 @@
<?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 > Konsultasi (list_konsultasi) dari x_message: daftar per periode, percakapan, hapus lunak dan pemulihan. */
class LegacyKonsultasiTest extends TestCase
{
use FakesLegacyDatabase;
use InspectsHtml;
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->useLegacyDatabase();
$this->seedLegacyOverview();
$this->seedLegacyEmployees();
$this->seedLegacyPortal();
$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.konsultasi.data', $query))->assertOk();
}
/** @return array<string, list<mixed>> id => [nim, nama, nip, pembimbing, topik, terakhir, krs, status] */
private function rows(array $query = []): array
{
return collect($this->data($query)->json('rows'))
->mapWithKeys(fn (array $r): array => [$r['id'] => [$r['nim'], $r['nama'], $r['nip'], $r['pembimbing'], $r['topik'], $r['terakhir'], $r['krs'], $r['status']]])->all();
}
public function test_page_matches_the_prototype_layout(): void
{
$response = $this->get(route('operator.halaman', 'list_konsultasi'))->assertOk()
->assertSee('satuRemoteTable', false)
->assertSee('Konsultasi pembimbing asli dari SIAKAD');
$xpath = $this->dom($response);
$panel = "//*[@aria-label='Daftar Konsultasi Pembimbing']";
$texts = fn (string $query): array => array_map(fn ($node): string => $this->textOf($node), iterator_to_array($xpath->query($query)));
$this->assertSame(['', 'NIM', 'Nama Mahasiswa', 'NIP', 'Nama Pembimbing', 'Topik', 'Post Terakhir', 'KRS Disetujui', 'Status', 'Aksi'], $texts("{$panel}//thead/tr/th"));
$this->assertSame(['Periode Akademik'], $texts("//section[@aria-label='Filter data']//label"));
$this->assertSame(['Hapus'], $texts("{$panel}//div[contains(@class, 'satu-bar__tools')]//button"));
$this->assertSame(['2020/2021 Genap', '2020/2021 Ganjil'], array_values(array_filter($texts("//select[@name='filter_periode']/option"))), 'Hanya periode yang punya pesan, terbaru dulu.');
$this->assertSame(1, $xpath->query("{$panel}//tbody//a[@aria-label='Lihat']")->length, 'Aksi Lihat berupa tautan ke percakapan.');
$this->assertSame(1, $xpath->query("//dialog[contains(@class, 'dialog--danger')]")->length);
}
public function test_data_groups_messages_per_pair_in_the_period(): void
{
$this->assertSame(['510-20' => ['X510', 'Mahasiswa 510', '198502022010121001', 'Andi Wijaya, S.T., M.Eng.', 'Pesan semester genap', '1 Mar 2021, 10:00', 'Tidak', '–']], $this->rows(), 'Periode bawaan = terbaru (2020/2021 Genap).');
$this->assertSame([
'502-11' => ['X502', 'Mahasiswa 502', '197501012000031002', 'Siti Aminah, M.Pd.', 'Perbaiki IPK semester depan', '1 Okt 2020, 10:00', 'Ya', '–'],
'500-11' => ['D1041191001', 'Rina Lestari', '197501012000031002', 'Siti Aminah, M.Pd.', 'Segera isi KRS semester ini jangan terlambat', '12 Sep 2020, 09:30', 'Tidak', '–'],
], $this->rows(['periode' => 368]), 'Topik = pesan pertama; KRS disetujui dari t_kst; mahasiswa prodi lain tidak ikut.');
$this->data(['periode' => 368])->assertJson(['total' => 2])->assertJsonPath('rows.0.tone', 'success');
$this->assertSame(['500-11'], array_keys($this->rows(['periode' => 368, 'q' => 'rina'])));
$this->assertSame(['502-11', '500-11'], array_keys($this->rows(['periode' => 368, 'q' => 'aminah'])));
$this->assertSame([], $this->rows(['periode' => 368, 'q' => 'tidak-ada']));
}
public function test_show_thread(): void
{
$this->get(route('operator.konsultasi.show', '500-11'))->assertOk()
->assertSee('Rina Lestari')->assertSee('D1041191001')->assertSee('Siti Aminah, M.Pd.')
->assertSeeInOrder(['Segera isi KRS semester ini', 'jangan terlambat', 'KRS sudah saya periksa'])
->assertSee(route('operator.halaman', 'list_konsultasi'));
$this->get(route('operator.konsultasi.show', '600-11'))->assertNotFound();
$this->get(route('operator.konsultasi.show', '500-99'))->assertNotFound();
}
public function test_soft_delete_and_restore(): void
{
$this->postJson(route('operator.konsultasi.destroy'), ['ids' => ['500-11', '600-11', '999-1']])
->assertOk()->assertJson(['message' => '2 pesan konsultasi dihapus.', 'count' => 2]);
$this->assertSame(['502-11'], array_keys($this->rows(['periode' => 368])));
$this->get(route('operator.konsultasi.show', '500-11'))->assertNotFound();
$this->assertSame(1, DB::connection('untan')->table('x_message')->where('idmhs', 600)->whereNull('deleted_at')->count(), 'Mahasiswa di luar cakupan tidak tersentuh.');
$this->assertSame(5, DB::connection('untan')->table('x_message')->count(), 'Baris tidak dihapus fisik.');
$this->postJson(route('operator.konsultasi.destroy'), ['ids' => ['abc']])->assertStatus(422);
$this->postJson(route('operator.konsultasi.destroy'), ['ids' => ['500-11']])->assertOk()->assertJson(['count' => 0]);
$this->artisan('siakad:pulihkan-konsultasi')->assertFailed();
$this->artisan('siakad:pulihkan-konsultasi', ['--nim' => 'D1041191001'])->expectsOutput('2 pesan dipulihkan.')->assertSuccessful();
$this->assertSame(['502-11', '500-11'], array_keys($this->rows(['periode' => 368])));
DB::connection('untan')->getSchemaBuilder()->dropColumns('x_message', ['deleted_at']);
$this->postJson(route('operator.konsultasi.destroy'), ['ids' => ['500-11']])->assertStatus(422)->assertSee('siakad:siapkan-portal');
}
public function test_access(): void
{
Auth::logout();
$this->get(route('operator.konsultasi.data'))->assertRedirect(route('login'));
$this->post(route('login.store'), ['username' => 'D1041191001', 'password' => 'rahasia-mhs']);
$this->getJson(route('operator.konsultasi.data'))->assertForbidden();
$this->postJson(route('operator.konsultasi.destroy'), ['ids' => ['500-11']])->assertForbidden();
Auth::logout();
config(['auth.guards.web.provider' => 'users']);
Auth::forgetGuards();
$demo = User::factory()->operator()->create();
$this->actingAs($demo)->getJson(route('operator.konsultasi.data'))->assertNotFound();
$this->actingAs($demo)->get(route('operator.konsultasi.show', '500-11'))->assertNotFound();
$this->actingAs($demo)->get(route('operator.halaman', 'list_konsultasi'))->assertOk()->assertDontSee('dialog--danger');
}
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_konsultasi'))->assertOk()->assertSee('Akun belum terhubung ke program studi');
$this->getJson(route('operator.konsultasi.data'))->assertNotFound();
}
}