135 lines
7.7 KiB
PHP
135 lines
7.7 KiB
PHP
<?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\Support\Facades\Route;
|
|
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 dan riwayat percakapan (hanya lihat), serta pemulihan pesan yang pernah disembunyikan. */
|
|
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] */
|
|
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']]])->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)));
|
|
|
|
// Hanya lihat: tanpa kotak centang, tanpa kolom Status, tanpa tombol bilah, dan tanpa dialog hapus.
|
|
$this->assertSame(['NIM', 'Nama Mahasiswa', 'NIP', 'Nama Pembimbing', 'Topik', 'Post Terakhir', 'KRS Disetujui', 'Aksi'], $texts("{$panel}//thead/tr/th"));
|
|
$this->assertSame(['Periode Akademik'], $texts("//section[@aria-label='Filter data']//label"));
|
|
$this->assertSame([], $texts("{$panel}//div[contains(@class, 'satu-bar__tools')]//button"));
|
|
$this->assertSame([], $texts("{$panel}//tbody/template//button"), 'Baris hanya punya Lihat (tautan).');
|
|
// Semua periode reguler (juga yang tanpa pesan), terbaru dulu; periode aktif prodi (368) terpilih.
|
|
$this->assertSame(['2020/2021 Genap', '2020/2021 Ganjil', '2019/2020 Genap'], array_values(array_filter($texts("//select[@name='filter_periode']/option"))));
|
|
$this->assertSame(['2020/2021 Ganjil'], $texts("//select[@name='filter_periode']/option[@selected]"), 'Periode aktif menjadi bawaan.');
|
|
$this->assertSame(1, $xpath->query("{$panel}//tbody//a[@aria-label='Lihat']")->length, 'Aksi Lihat berupa tautan ke percakapan.');
|
|
$this->assertSame(0, $xpath->query("//dialog[contains(@class, 'dialog--danger')]")->length);
|
|
$response->assertDontSee('askRemove', false)->assertDontSee('remove()', false);
|
|
$this->assertFalse(Route::has('operator.konsultasi.destroy'), 'Hapus konsultasi sudah dihapus.');
|
|
}
|
|
|
|
public function test_data_groups_messages_per_pair_in_the_period(): void
|
|
{
|
|
// Periode bawaan = periode aktif prodi (2020/2021 Ganjil), bukan yang terbaru.
|
|
$this->assertSame(['502-11', '500-11'], array_keys($this->rows()));
|
|
$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' => 371]), 'Periode terbaru tetap bisa dipilih.');
|
|
$this->assertSame([], $this->rows(['periode' => 365]), 'Periode tanpa pesan tampil kosong, bukan hilang dari filter.');
|
|
$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_previously_hidden_messages_stay_hidden_and_can_be_restored(): void
|
|
{
|
|
// Pesan yang dulu disembunyikan (deleted_at) tidak tampil; tidak ada lagi cara menyembunyikan dari halaman ini.
|
|
DB::connection('untan')->table('x_message')->where('idmhs', 500)->update(['deleted_at' => now()]);
|
|
$this->assertSame(['502-11'], array_keys($this->rows(['periode' => 368])));
|
|
$this->get(route('operator.konsultasi.show', '500-11'))->assertNotFound();
|
|
|
|
$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])));
|
|
$this->get(route('operator.konsultasi.show', '500-11'))->assertOk();
|
|
$this->assertSame(5, DB::connection('untan')->table('x_message')->count());
|
|
}
|
|
|
|
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();
|
|
|
|
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();
|
|
}
|
|
}
|