feat: add support for individual consumable items in service items

- Introduced `consumables` field in `ServiceItem` to allow multiple individual items alongside inventory packages.
- Created `ServiceItemConsumable` entity to manage individual consumable items linked to a service.
- Updated `ServiceItemController` to handle CRUD operations for consumables.
- Enhanced `ServiceDetailPage` and `ServiceItemFormModal` to display and manage consumables.
- Added tests to ensure functionality for adding, updating, and validating consumables.
- Updated API documentation to reflect changes in service item structure and consumables.
This commit is contained in:
hamed
2026-07-18 12:34:42 +03:30
parent c4a661b542
commit c13cc57c48
11 changed files with 530 additions and 40 deletions
+33 -2
View File
@@ -55,6 +55,9 @@ const mockApi = (item: unknown = ITEM, notFound = false) => {
if (url.includes('/tenant-insurances')) return Promise.resolve({ data: { data: [
{ uuid: 'ins1', insurance_name: 'بیمه ایران', insurance_kind: 'basic', coverage_percent: 70 },
] } });
if (url.includes('/inventory-items')) return Promise.resolve({ success: true, data: { items: [
{ uuid: 'inv1', name: 'گاز استریل', unit: 'عدد', price: 50_000, stock: 100 },
] } });
if (url.includes('/inventory-packages')) return Promise.resolve({ success: true, data: [
{
uuid: 'pkg1', title: 'پکیج سرم', total: 1_200_000, available: true,
@@ -145,14 +148,42 @@ describe('ServiceDetailPage (جزئیات سرویس)', () => {
expect(screen.getByText('۲ عدد')).toBeInTheDocument();
});
it('سرویس بدون پکیج، حالت خالی با لینک انبار می‌دهد', async () => {
it('سرویس بدون هیچ کالایی، حالت خالی با لینک انبار می‌دهد', async () => {
render();
fireEvent.click(await screen.findByText('کالاهای مرتبط'));
expect(await screen.findByText('پکیج کالایی به این سرویس متصل نیست')).toBeInTheDocument();
expect(await screen.findByText('کالایی به این سرویس متصل نیست')).toBeInTheDocument();
expect(screen.getByText('مدیریت انبار')).toBeInTheDocument();
});
it('پکیج و کالای تکی هم‌زمان در تب کالاها نمایش داده می‌شوند', async () => {
mockApi({
...ITEM,
inventory_package_uuid: 'pkg1',
inventory_package_title: 'پکیج سرم',
consumables: [{ item_uuid: 'inv1', name: 'گاز استریل', unit: 'عدد', price: 50_000, stock: 100, amount: 3 }],
});
render();
fireEvent.click(await screen.findByText('کالاهای مرتبط'));
expect(await screen.findByText('پکیج')).toBeInTheDocument();
expect(screen.getByText('پکیج سرم')).toBeInTheDocument();
expect(screen.getByText('کالاهای تکی')).toBeInTheDocument();
expect(screen.getByText('گاز استریل')).toBeInTheDocument();
expect(screen.getByText('۳ عدد')).toBeInTheDocument();
});
it('کالای تکی با موجودی ناکافی نشان‌دار می‌شود', async () => {
mockApi({
...ITEM,
consumables: [{ item_uuid: 'inv1', name: 'گاز استریل', unit: 'عدد', price: 50_000, stock: 1, amount: 5 }],
});
render();
fireEvent.click(await screen.findByText('کالاهای مرتبط'));
expect(await screen.findByText('موجودی ناکافی')).toBeInTheDocument();
});
it('تب لاگ تغییرات، مقدار قبل و بعد را خوانا نشان می‌دهد', async () => {
render();
fireEvent.click(await screen.findByText('لاگ تغییرات'));