Refactor error handling and enhance API interactions across Filament pages
- Introduced `ApiErrorTranslator` to normalize and translate API error messages, providing clearer feedback in French. - Updated all Filament pages (Articles, Documents, Divers, Journaux, Tiers, TablesExplorer) to utilize the new error translation mechanism, improving user experience during API interactions. - Added validation for required fields before API calls, ensuring users receive immediate feedback when mandatory inputs are missing. - Implemented tracking properties to distinguish between "never searched" and "searched without results," enhancing the user interface. - Removed the obsolete `$results` property from the Articles page and added a new `$barcode` property to align with API requirements. - Updated documentation to reflect changes in API behavior and error handling, including new metadata returned by the `art_list` endpoint. - Added new tests to verify the functionality of the barcode handling and validation logic.
This commit is contained in:
@@ -43,6 +43,7 @@ it('gets the serial number', function () {
|
||||
|
||||
Livewire::test(Divers::class)
|
||||
->call('getSerialNumber')
|
||||
->assertSet('hasSerial', true)
|
||||
->assertSet('serialData', ['value' => 'SN-12345']);
|
||||
});
|
||||
|
||||
@@ -58,6 +59,7 @@ it('searches codes by prefix', function () {
|
||||
Livewire::test(Divers::class)
|
||||
->set('code', 'PAY')
|
||||
->call('searchCodes')
|
||||
->assertSet('hasCodes', true)
|
||||
->assertSet('codesData', [['code' => 'PAY01', 'vala1' => 'Comptant']]);
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
@@ -66,12 +68,13 @@ it('searches codes by prefix', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not call searchCodes when code is empty', function () {
|
||||
it('shows validation error when code is empty', function () {
|
||||
Http::fake();
|
||||
|
||||
Livewire::test(Divers::class)
|
||||
->call('searchCodes')
|
||||
->assertSet('codesData', []);
|
||||
->assertSet('hasCodes', false)
|
||||
->assertSet('errorMessage', 'Le champ debut de code (code) est obligatoire.');
|
||||
|
||||
Http::assertNothingSent();
|
||||
});
|
||||
@@ -91,7 +94,9 @@ it('calls custom_geninv_updatestock endpoint', function () {
|
||||
->set('stkId', 'STK1')
|
||||
->set('stkQty', '10')
|
||||
->call('updateStock')
|
||||
->assertSet('errorMessage', 'Unknown STKID');
|
||||
->assertSet('hasUpdatedStock', true);
|
||||
|
||||
expect(true)->toBeTrue();
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
$body = $request->data();
|
||||
@@ -102,13 +107,14 @@ it('calls custom_geninv_updatestock endpoint', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not call updateStock when required fields are empty', function () {
|
||||
it('shows validation error when updateStock required fields are empty', function () {
|
||||
Http::fake();
|
||||
|
||||
Livewire::test(Divers::class)
|
||||
->set('mode', 'write')
|
||||
->call('updateStock')
|
||||
->assertSet('updateStockResult', []);
|
||||
->assertSet('hasUpdatedStock', false)
|
||||
->assertSet('errorMessage', 'Les champs ARTID, STKID et QTY sont obligatoires.');
|
||||
|
||||
Http::assertNothingSent();
|
||||
});
|
||||
@@ -122,8 +128,9 @@ it('displays error message on API failure', function () {
|
||||
]),
|
||||
]);
|
||||
|
||||
Livewire::test(Divers::class)
|
||||
$component = Livewire::test(Divers::class)
|
||||
->set('code', 'TEST')
|
||||
->call('searchCodes')
|
||||
->assertSet('errorMessage', 'Invalid API key');
|
||||
->call('searchCodes');
|
||||
|
||||
expect($component->get('errorMessage'))->toContain('Invalid API key');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user