|
@@ -16,7 +16,7 @@
|
|
|
* the user can zero an archived spool's tracking counter without having
|
|
* the user can zero an archived spool's tracking counter without having
|
|
|
* to un-archive it first.
|
|
* to un-archive it first.
|
|
|
*/
|
|
*/
|
|
|
-import { describe, it, expect, beforeEach } from 'vitest';
|
|
|
|
|
|
|
+import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
|
import { screen, waitFor, within } from '@testing-library/react';
|
|
import { screen, waitFor, within } from '@testing-library/react';
|
|
|
import userEvent from '@testing-library/user-event';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
import { render } from '../utils';
|
|
import { render } from '../utils';
|
|
@@ -244,3 +244,60 @@ describe('InventoryPage — resetting all counters says what failed', () => {
|
|
|
expect(await screen.findByText('Counter reset for 2 spool(s)')).toBeInTheDocument();
|
|
expect(await screen.findByText('Counter reset for 2 spool(s)')).toBeInTheDocument();
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+// SM-C8: a Spoolman spool priced only by its filament showed "-" in Cost/kg,
|
|
|
|
|
+// although every print off it was charged that price.
|
|
|
|
|
+describe('InventoryPage — Cost/kg shows what prints are charged', () => {
|
|
|
|
|
+ const show = async (spool: Record<string, unknown>) => {
|
|
|
|
|
+ vi.mocked(window.localStorage.getItem).mockImplementation((key: string) =>
|
|
|
|
|
+ key === 'bambuddy-inventory-columns'
|
|
|
|
|
+ ? JSON.stringify([
|
|
|
|
|
+ { id: 'brand', label: 'Brand', visible: true },
|
|
|
|
|
+ { id: 'cost_per_kg', label: 'Cost/kg', visible: true },
|
|
|
|
|
+ ])
|
|
|
|
|
+ : null,
|
|
|
|
|
+ );
|
|
|
|
|
+ server.use(
|
|
|
|
|
+ http.get('/api/v1/settings/', () => HttpResponse.json(baseSettings)),
|
|
|
|
|
+ http.get('/api/v1/inventory/spools', () => HttpResponse.json([{ ...mockSpools[0], ...spool }])),
|
|
|
|
|
+ http.get('/api/v1/inventory/assignments', () => HttpResponse.json([])),
|
|
|
|
|
+ http.get('/api/v1/spoolman/settings', () => HttpResponse.json({ spoolman_enabled: 'false' })),
|
|
|
|
|
+ );
|
|
|
|
|
+ render(<InventoryPageRouter />);
|
|
|
|
|
+ await screen.findAllByText('Polymaker');
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ it("falls back to the filament's price, marked as such", async () => {
|
|
|
|
|
+ await show({ cost_per_kg: null, effective_cost_per_kg: 24 });
|
|
|
|
|
+
|
|
|
|
|
+ expect(await screen.findByText('$24.00')).toBeInTheDocument();
|
|
|
|
|
+ expect(screen.getByText('(filament price)')).toBeInTheDocument();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('falls back past a spool price of 0, as the charge does', async () => {
|
|
|
|
|
+ // Spoolman imports often write 0 for "no price"; prints then pay the filament's.
|
|
|
|
|
+ await show({ cost_per_kg: 0, effective_cost_per_kg: 24 });
|
|
|
|
|
+
|
|
|
|
|
+ expect(await screen.findByText('$24.00')).toBeInTheDocument();
|
|
|
|
|
+ expect(screen.getByText('(filament price)')).toBeInTheDocument();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('keeps a built-in spool priced 0 at $0.00', async () => {
|
|
|
|
|
+ await show({ cost_per_kg: 0 });
|
|
|
|
|
+
|
|
|
|
|
+ expect(await screen.findByText('$0.00')).toBeInTheDocument();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it("shows the spool's own price unmarked", async () => {
|
|
|
|
|
+ await show({ cost_per_kg: 30, effective_cost_per_kg: 30 });
|
|
|
|
|
+
|
|
|
|
|
+ expect(await screen.findByText('$30.00')).toBeInTheDocument();
|
|
|
|
|
+ expect(screen.queryByText('(filament price)')).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('shows "-" for an unpriced spool', async () => {
|
|
|
|
|
+ await show({ cost_per_kg: null, effective_cost_per_kg: null });
|
|
|
|
|
+
|
|
|
|
|
+ await waitFor(() => expect(screen.queryByText(/^\$\d/)).toBeNull());
|
|
|
|
|
+ });
|
|
|
|
|
+});
|