fix: Resolve intermittent test failures in Translation models (#413)
Commit: 7d5eebdc039674647bdc59da66df46bd493d3603
Date: 2025-10-20 17:53:45 +0000
Author: PascalHavelange
Commit Message
fix: Resolve intermittent test failures in Translation models (#413)
* feat: Add CollectionImage visibility and password reset functionality
## Features Added
### CollectionImage Visibility
- Created CollectionImageManager.vue component for managing collection images in SPA
- Integrated CollectionImageManager into CollectionDetail.vue view (visible in view mode)
- Added _images.blade.php partial for collections in web UI
- Updated collections/show.blade.php to include CollectionImages section
- Collections already present in AppHeader navigation (desktop/mobile) and Home dashboard
### Store Cache Management
- Updated clearCacheAndReload() in storeUtils.ts to clear all recent stores:
- collectionImage, itemImage, itemTranslation (with reset methods)
- collection, item, partner (cleared manually)
- availableImage, imageUpload (cleared manually)
- Ensures comprehensive cache clearing for all image and resource stores
### Password Reset
- Password reset already implemented in Laravel backend (using built-in functionality)
- Added "Forgot your password?" link to Login.vue (SPA)
- Web login (login.blade.php) already has password reset link
## Testing
- ✅ All frontend tests pass
- ✅ All backend tests pass (1757 passed)
- ✅ ESLint checks pass
- ✅ TypeScript type-check pass
- ✅ Build succeeds
- ✅ Pint checks pass (849 files)
## Files Changed
- resources/js/components/CollectionImageManager.vue (new)
- resources/js/views/CollectionDetail.vue (modified)
- resources/js/views/Login.vue (modified)
- resources/js/utils/storeUtils.ts (modified)
- resources/views/collections/_images.blade.php (new)
- resources/views/collections/show.blade.php (modified)
* 5.8.1
* chore: Update CHANGELOG and bump version to 5.8.1
* feat: add permissions:sync command for production-safe role and permission management
* fix: add missing PhotoIcon, ChevronUpIcon, and ChevronDownIcon mocks to CollectionDetail tests
* fix: improve cookie clearing to prevent 419 errors with saved credentials
- Remove speculative cookie name variations from cookies.ts (only target actual cookies)
- Use exact cookie names based on Laravel configuration:
- XSRF-TOKEN (Laravel default CSRF cookie)
- inventory_app_session (based on APP_NAME='Inventory-App')
- Import clearAuthCookies at module level in auth store (no dynamic import)
- Call clearAuthCookies synchronously before login attempt
- Set form autocomplete='off' and email autocomplete='username' to prevent browser from saving XSRF token
- Add detailed comments explaining cookie naming based on Laravel config
* feat: enhance item translations and images UI, add available images edit/delete
ItemTranslations improvements:
- Fix search to include parent item's internal_name and ID
- Add language filter dropdown to index page
- Pre-populate item when creating translation from item show page
- Fix Language ordering to use 'internal_name' (not 'language_name')
- Add Item Translations to navigation menu (desktop and mobile)
UI/UX improvements:
- Remove dark mode classes from item images and translations sections
- Standardize section headers with icons and consistent styling
- Fix ItemController sortBy error (use sortBy instead of sortKeys)
AvailableImages enhancements:
- Add edit functionality to update comment field
- Add delete functionality for permanent image removal
- Create UpdateAvailableImageRequest form request
- Add edit view and update routes
Cookie management:
- Clean up cookies.ts to only target actual cookies used
- Remove speculative cookie name variations
- Add detailed comments based on Laravel configuration
* refactor: use system-properties component consistently across all show views
- Move ID, backward_compatibility, created_at, and updated_at to bottom of pages
- Use x-system-properties component (similar to /cli SystemProperties.vue)
- Remove timestamps from main content area on all show views
- Apply to: items, collections, countries, languages, contexts, partners, projects, item-translations
- Apply to admin views: users, roles
- Ensure consistent format.uuid and format.date component usage
- Improve visual consistency between /web and /cli interfaces
* feat: complete Collection Translations web interface and improve Collection Images
Collection Images improvements:
- Remove dark mode classes from collections/_images.blade.php
- Add icon to Images section header (matches Item Images)
- Remove permanent Delete button, keep only Detach (matches Item Images)
- Change card backgrounds from dark to white with borders
Collection Translations implementation:
- Fix CollectionTranslationController search to use 'title' field
- Add Collection Translations to navigation menu (desktop and mobile)
- Create collections/_translations.blade.php partial (mirrors items)
- Update CollectionController to group translations by context
- Add translations section to collections/show.blade.php
- Fix collection-translations/show.blade.php to use correct fields (title, url)
- Remove item-specific fields that don't exist in CollectionTranslation model
Consistency improvements:
- Both Collection Images and Translations now match Item equivalents
- Consistent styling across all image and translation sections
- Proper use of system-properties component everywhere
* fix: critical Collection Translations fixes
- Add Collection Translations tile to home page (was missing)
- Fix table column header: 'Title' instead of 'Name'
- Fix table to display 'title' field instead of empty 'name'
- Show description preview in table instead of alternate_name
- Fix Livewire component search to use 'title' field
- Fix Livewire component sorting to use 'title' in validSortFields
- Create missing _form.blade.php for collection translations
- Form includes only relevant fields: title, description, url (not item-specific fields)
- Fix delete action to use correct title field for record name
All critical errors resolved:
✓ Home page now shows Collection Translations
✓ Table displays data correctly
✓ Edit page now works (form exists)
✓ All fields match CollectionTranslation model structure
* fix: correct Collection Translation tests validation assertions
- Remove 'description' from validation error assertions (field is nullable)
- Tests now match actual form request validation rules
- All 22 Collection Translation tests pass with 61 assertions
* feat: implement complete Collection Translations API
API Implementation:
- Create CollectionTranslationController with full CRUD operations (index, store, show, update, destroy)
- Add API request validation classes (Index, Show, Store, Update)
- Add collection-translation routes to api.php (GET, POST, PATCH, PUT, DELETE)
- Support filtering by collection_id, language_id, context_id, default_context
- Include proper uniqueness validation on (collection_id, language_id, context_id)
- Use CollectionTranslationResource for API responses
OpenAPI Documentation:
- Generate new OpenAPI spec with collection-translation endpoints
- Update API client with TypeScript definitions
- Add documentation for all new endpoints and request/response schemas
Compliance:
- CollectionTranslation now matches same API patterns as all other models
- Consistent with ItemTranslation, Collection, and other translation APIs
- Full CRUD operations available via REST API
* feat: create comprehensive API tests for Collection Translations
API Test Suite:
- Create tests/Feature/Api/CollectionTranslation/ directory with full test coverage
- IndexTest: List, filter by collection_id, language_id, context_id
- StoreTest: Create validation, unique constraints, nullable fields, URL validation
- ShowTest: Display with/without relations, not found handling
- UpdateTest: Full/partial updates, unique constraint validation, field validation
- DestroyTest: Delete operations, not found handling, isolation testing
- AnonymousTest: Unauthorized access protection
Test Structure:
- Follow same patterns as ItemTranslation tests for consistency
- Isolated tests that create their own test data
- Precise assertions on exact records created
- Proper authentication and permission testing
- Comprehensive validation testing
Note: Some tests currently fail due to schema differences (description NOT NULL)
and factory method naming differences - will be addressed in follow-up commit
* Adding API tests for CollectionTranslation
* fix: Resolve intermittent test failures in Translation model tests
## Problem
- CollectionTranslation and ItemTranslation tests were failing intermittently due to `extra` field validation
- Factories were generating arrays for `extra` field, but API expected JSON strings
- Race condition-like behavior caused random test failures during parallel execution
## Root Cause
The factories used randomElement/randomElements to generate arrays:
- CollectionTranslationFactory: `randomElement([null, ['notes' => ...], ['metadata' => ...]])`
- ItemTranslationFactory: `randomElements(['key1' => 'value1', 'key2' => 'value2'])`
But API validation expected JSON strings: `'extra' => ['nullable', 'json']`
## Solution
1. **Fixed factories to generate JSON strings directly**:
- CollectionTranslationFactory: Wrap arrays with `json_encode()`
- ItemTranslationFactory: Use `json_encode()` with `passthrough()`
2. **Removed conversion logic from tests** since factories now generate correct format
3. **Fixed manual test data** in UpdateTest that was still using arrays
## Impact
- Tests are now deterministic and consistently pass
- Eliminates random failures in CI/CD pipeline
- Better maintainability with consistent data generation
- Follows existing codebase patterns
Fixes intermittent CI failures in tests:
- Tests\Feature\Api\CollectionTranslation\StoreTest::test_can_store_collection_translation
- Tests\Feature\Api\CollectionTranslation\StoreTest::test_store_accepts_valid_url
- Tests\Feature\Api\ItemTranslation\UpdateTest::test_update_can_modify_all_optional_fields
---------
Signed-off-by: PascalHavelange <havelangep@gmail.com>
Co-authored-by: Pascal HAVELANGE <havelangep@hotmail.com>
Files Changed
- 📝 Modified:
database/factories/CollectionTranslationFactory.php
- 📝 Modified:
database/factories/ItemTranslationFactory.php
- 📝 Modified:
resources/js/views/Login.vue
- 📝 Modified:
tests/Feature/Api/CollectionTranslation/StoreTest.php
- 📝 Modified:
tests/Feature/Api/ItemTranslation/StoreTest.php
- 📝 Modified:
tests/Feature/Api/ItemTranslation/UpdateTest.php
Links
This documentation was automatically generated from Git commit data.