Updated CI

This commit is contained in:
maziggy
2026-02-20 18:28:34 +01:00
parent 1404242e0c
commit 6ab48fa338
8 changed files with 303 additions and 37 deletions
@@ -93,6 +93,7 @@ describe('SpoolFormModal weightTouched', () => {
isOpen={true}
onClose={vi.fn()}
spool={existingSpool}
currencySymbol="$"
/>
);
@@ -124,6 +125,7 @@ describe('SpoolFormModal weightTouched', () => {
isOpen={true}
onClose={vi.fn()}
spool={existingSpool}
currencySymbol="$"
/>
);
@@ -158,6 +160,7 @@ describe('SpoolFormModal weightTouched', () => {
<SpoolFormModal
isOpen={true}
onClose={vi.fn()}
currencySymbol="$"
/>
);
@@ -196,6 +199,7 @@ describe('SpoolFormModal weightTouched', () => {
isOpen={true}
onClose={vi.fn()}
spool={spoolWithCatalogId}
currencySymbol="$"
/>
);
@@ -237,6 +241,7 @@ describe('SpoolFormModal weightTouched', () => {
<SpoolFormModal
isOpen={true}
onClose={vi.fn()}
currencySymbol="$"
/>
);
@@ -277,6 +282,70 @@ describe('SpoolFormModal weightTouched', () => {
expect(payload).toHaveProperty('core_weight_catalog_id', 2); // ID of "Bambu Lab 250g"
});
it('preserves cost_per_kg when editing spool', async () => {
const spoolWithCost: InventorySpool = {
...existingSpool,
cost_per_kg: 25.50,
};
render(
<SpoolFormModal
isOpen={true}
onClose={vi.fn()}
spool={spoolWithCost}
currencySymbol="$"
/>
);
await waitFor(() => {
expect(screen.getByText('Edit Spool')).toBeInTheDocument();
});
// Click Save without changing cost
const saveButton = screen.getByRole('button', { name: /save/i });
fireEvent.click(saveButton);
await waitFor(() => {
expect(api.updateSpool).toHaveBeenCalledTimes(1);
});
const [spoolId, payload] = vi.mocked(api.updateSpool).mock.calls[0];
expect(spoolId).toBe(1);
// cost_per_kg should be preserved in the update payload
expect(payload).toHaveProperty('cost_per_kg', 25.50);
});
it('sends null cost_per_kg when spool has no cost', async () => {
const spoolWithoutCost: InventorySpool = {
...existingSpool,
cost_per_kg: null,
};
render(
<SpoolFormModal
isOpen={true}
onClose={vi.fn()}
spool={spoolWithoutCost}
currencySymbol="$"
/>
);
await waitFor(() => {
expect(screen.getByText('Edit Spool')).toBeInTheDocument();
});
const saveButton = screen.getByRole('button', { name: /save/i });
fireEvent.click(saveButton);
await waitFor(() => {
expect(api.updateSpool).toHaveBeenCalledTimes(1);
});
const [, payload] = vi.mocked(api.updateSpool).mock.calls[0];
// cost_per_kg should be null when not set
expect(payload).toHaveProperty('cost_per_kg', null);
});
it('displays correct catalog name when duplicates exist', async () => {
const spoolWithCatalogId: InventorySpool = {
...existingSpool,
@@ -297,6 +366,7 @@ describe('SpoolFormModal weightTouched', () => {
isOpen={true}
onClose={vi.fn()}
spool={spoolWithCatalogId}
currencySymbol="$"
/>
);