Conversation
|
🔄 AI PR Review sedang antri di server...
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
issue #1278
🎯 Deskripsi
Pull request ini memperbaiki penanganan pesan kesalahan (error handling) pada formulir Tambah Bantuan (
/master/bantuan/create) dan Ubah Bantuan (/master/bantuan/{id}/edit).Sebelum perbaikan ini, ketika pengiriman form gagal divalidasi oleh API upstream (
API-Database-Gabungan) dengan status HTTP 422 dan respons JSON:{ "success": false, "message": "Validation failed", "errors": { "nama": [ "Format isian nama tidak valid." ] } }SweetAlert hanya menampilkan teks generik
"Validation failed"dariresponse.messageatauxhr.responseJSON.message. Pengguna tidak mendapatkan informasi spesifik mengenai field mana yang salah atau apa aturan validasi yang dilanggar (misalnya aturan regex pada nama bantuan). Selain itu, pemanggilan langsungxhr.responseJSON.messageberisiko memicuTypeErrordi JavaScript apabilaxhr.responseJSONtidak terdefinisi (misal akibat kegagalan jaringan atau server mengembalikan respons HTML).Perbaikan ini menambahkan fungsi
showErrorAlert(response, fallbackMessage)pada viewcreate.blade.phpdanedit.blade.phpyang secara cerdas:errors.data.messageatau pesan default bilaerrorstidak tersedia, serta mencegah terjadinyaTypeErrorpada JavaScript.🛠️ Perubahan yang Dilakukan
1.
resources/views/master/bantuan/create.blade.phpFix — Penanganan error validasi dan ekstraksi pesan
errorspada form create:showErrorAlert(response, fallbackMessage).success(kondisiresponse.success != true) danerroruntuk memanggilshowErrorAlert().2.
resources/views/master/bantuan/edit.blade.phpFix — Penanganan error validasi dan ekstraksi pesan
errorspada form edit:showErrorAlert(response, fallbackMessage)yang sama.success(saatresponse.success != true) danerrorpada request AJAX update data bantuan.3.
tests/Feature/MasterBantuanKabupatenTest.phpTest — Penambahan automated feature test untuk view create dan edit bantuan:
master/bantuan/create(bantuan.create) danmaster/bantuan/{id}/edit(bantuan.edit) dapat diakses oleh user yang terotentikasi.showErrorAlertdan logika penanganandata.errors.✅ Test Cases yang Diimplementasikan
"Validation failed"), SweetAlert menampilkan teks pesan error dari propertierrors(contoh:"Format isian nama tidak valid."), bukan hanya teks umum"Validation failed".errors, SweetAlert menampilkan daftar terstruktur (bulleted list) dari seluruh pesan error yang ada.textContent) sebelum dirender ke dalam HTML SweetAlert untuk mencegah kerentanan XSS.errors, SweetAlert dengan aman beralih menampilkandata.messageataufallbackMessagetanpa terjadiTypeError: Cannot read properties of undefined (reading 'message').tests/Feature/MasterBantuanKabupatenTest.phpdieksekusi dengan sukses (2 passed, 9 assertions).📸 Cara Menjalankan Uji Coba Manual
/master/bantuan)./master/bantuan/create).Bantuan 123atau karakter simbol yang tidak diizinkan)."Format isian nama tidak valid."(bukan hanya"Validation failed")./master/bantuan/{id}/edit).errors.🤖 Cara Menjalankan Uji Coba Otomatis (Automated Test)
Jalankan perintah berikut di terminal untuk mengeksekusi automated test yang dibuat:
php artisan test tests/Feature/MasterBantuanKabupatenTest.phpHasil yang diharapkan:
📸 Screenshot atau Video