Add tests for grouped stock list behavior and improve stock view mode UI and API enhancements
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -137,7 +137,7 @@ Project-specific operating conventions for future contributors and coding agents
|
|||||||
- Active kitchen selection and switching
|
- Active kitchen selection and switching
|
||||||
- Dashboard with quick actions
|
- Dashboard with quick actions
|
||||||
- Label creation flow with item lookup, location loading, preview, and stock entry creation
|
- Label creation flow with item lookup, location loading, preview, and stock entry creation
|
||||||
- Stock list with search and filters
|
- Grouped-first stock review with search and overview filters
|
||||||
- Stock detail page with stock adjustment workflow
|
- Stock detail page with stock adjustment workflow
|
||||||
- PWA manifest, icons, service worker, and offline fallback
|
- PWA manifest, icons, service worker, and offline fallback
|
||||||
|
|
||||||
@@ -165,6 +165,8 @@ Expected shapes today:
|
|||||||
Returns item definitions for autocomplete.
|
Returns item definitions for autocomplete.
|
||||||
- `GET /{database}/kitchen/items`
|
- `GET /{database}/kitchen/items`
|
||||||
Returns the current stock review list.
|
Returns the current stock review list.
|
||||||
|
- `GET /{database}/kitchen/items/grouped?expanded=0|1`
|
||||||
|
Returns grouped stock data; grouped review uses summary-first loading and hydrates item children in background.
|
||||||
- `GET /{database}/kitchen/items/{uuid_b64}`
|
- `GET /{database}/kitchen/items/{uuid_b64}`
|
||||||
Returns one item detail payload.
|
Returns one item detail payload.
|
||||||
- `GET /{database}/kitchen/changes`
|
- `GET /{database}/kitchen/changes`
|
||||||
|
|||||||
+37
-3
@@ -21,7 +21,24 @@ export async function searchItemDefinitions(store, query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function listStockEntries(store, filters = {}) {
|
export async function listStockEntries(store, filters = {}) {
|
||||||
const payload = await apiRequest(store, getPath('items'));
|
const query = {};
|
||||||
|
const searchName = filters.searchName || filters.search_name;
|
||||||
|
if (searchName) {
|
||||||
|
query.search_name = searchName;
|
||||||
|
}
|
||||||
|
if (filters.limit !== undefined && filters.limit !== null) {
|
||||||
|
query.limit = filters.limit;
|
||||||
|
}
|
||||||
|
if (filters.offset !== undefined && filters.offset !== null) {
|
||||||
|
query.offset = filters.offset;
|
||||||
|
}
|
||||||
|
if (filters.cursor) {
|
||||||
|
query.cursor = filters.cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = await apiRequest(store, getPath('items'), {
|
||||||
|
query,
|
||||||
|
});
|
||||||
|
|
||||||
if (Array.isArray(payload)) {
|
if (Array.isArray(payload)) {
|
||||||
return payload;
|
return payload;
|
||||||
@@ -30,9 +47,26 @@ export async function listStockEntries(store, filters = {}) {
|
|||||||
return payload?.data || payload?.entries || payload?.items || [];
|
return payload?.data || payload?.entries || payload?.items || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listGroupedStockEntries(store) {
|
export async function listGroupedStockEntries(store, options = {}) {
|
||||||
|
const query = {};
|
||||||
|
const expanded = options.expanded ?? 1;
|
||||||
|
query.expanded = expanded;
|
||||||
|
const searchName = options.searchName || options.search_name;
|
||||||
|
if (searchName) {
|
||||||
|
query.search_name = searchName;
|
||||||
|
}
|
||||||
|
if (options.limit !== undefined && options.limit !== null) {
|
||||||
|
query.limit = options.limit;
|
||||||
|
}
|
||||||
|
if (options.offset !== undefined && options.offset !== null) {
|
||||||
|
query.offset = options.offset;
|
||||||
|
}
|
||||||
|
if (options.cursor) {
|
||||||
|
query.cursor = options.cursor;
|
||||||
|
}
|
||||||
|
|
||||||
const payload = await apiRequest(store, `${getPath('items')}/grouped`, {
|
const payload = await apiRequest(store, `${getPath('items')}/grouped`, {
|
||||||
query: { expanded: 1 },
|
query,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Array.isArray(payload)) {
|
if (Array.isArray(payload)) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+79
-3
@@ -315,9 +315,63 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.stock-view-switch {
|
.stock-view-switch {
|
||||||
display: inline-flex;
|
display: grid;
|
||||||
flex-wrap: wrap;
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
gap: 0.5rem;
|
gap: 0.65rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stock-view-switch-wrap {
|
||||||
|
min-width: min(100%, 38rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stock-view-tab {
|
||||||
|
display: grid;
|
||||||
|
align-content: start;
|
||||||
|
gap: 0.2rem;
|
||||||
|
text-align: left;
|
||||||
|
border: 1px solid var(--lonc-border);
|
||||||
|
border-radius: 0.9rem;
|
||||||
|
background: rgba(255, 255, 255, 0.66);
|
||||||
|
color: inherit;
|
||||||
|
padding: 0.65rem 0.85rem;
|
||||||
|
transition:
|
||||||
|
border-color 160ms ease,
|
||||||
|
box-shadow 160ms ease,
|
||||||
|
background-color 160ms ease,
|
||||||
|
transform 160ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stock-view-tab:hover {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
border-color: rgba(31, 75, 153, 0.24);
|
||||||
|
box-shadow: 0 8px 16px rgba(24, 42, 79, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stock-view-tab:focus-visible {
|
||||||
|
outline: 2px solid rgba(31, 75, 153, 0.4);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stock-view-tab-active {
|
||||||
|
border-color: rgba(31, 75, 153, 0.42);
|
||||||
|
background: rgba(31, 75, 153, 0.1);
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(31, 75, 153, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stock-view-tab-title {
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stock-view-tab-subtitle {
|
||||||
|
font-size: 0.78rem;
|
||||||
|
color: var(--lonc-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 767.98px) {
|
||||||
|
.stock-view-switch {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.overview-row-single-open > [class*='col-'] {
|
.overview-row-single-open > [class*='col-'] {
|
||||||
@@ -598,6 +652,28 @@ button.legend-card:focus-visible {
|
|||||||
|
|
||||||
.grouped-stock-summary-meta {
|
.grouped-stock-summary-meta {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
row-gap: 0.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grouped-stock-secondary-details {
|
||||||
|
border-top: 1px dashed rgba(31, 39, 64, 0.14);
|
||||||
|
padding-top: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grouped-stock-secondary-toggle {
|
||||||
|
border-radius: 0.85rem;
|
||||||
|
border: 1px solid var(--lonc-border);
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
background: rgba(255, 255, 255, 0.66);
|
||||||
|
}
|
||||||
|
|
||||||
|
.grouped-stock-secondary-toggle > summary {
|
||||||
|
list-style: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grouped-stock-secondary-toggle > summary::-webkit-details-marker {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grouped-stock-toggle-label {
|
.grouped-stock-toggle-label {
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ vi.mock('../../src/api/client.js', () => ({
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
applyItemUpsert,
|
applyItemUpsert,
|
||||||
|
listGroupedStockEntries,
|
||||||
|
listStockEntries,
|
||||||
lookupItemByIdentifier,
|
lookupItemByIdentifier,
|
||||||
lookupItemDetails,
|
lookupItemDetails,
|
||||||
listKitchenChanges,
|
listKitchenChanges,
|
||||||
@@ -28,6 +30,51 @@ describe('api/stock', () => {
|
|||||||
apiRequestMock.mockReset();
|
apiRequestMock.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('listStockEntries forwards optional query filters', async () => {
|
||||||
|
apiRequestMock.mockResolvedValueOnce([]);
|
||||||
|
|
||||||
|
await listStockEntries(
|
||||||
|
{ config: { database: 'db' } },
|
||||||
|
{ searchName: 'Milk', limit: 20, offset: 40, cursor: 'cursor-1' },
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||||
|
{ config: { database: 'db' } },
|
||||||
|
'kitchen/items',
|
||||||
|
{
|
||||||
|
query: {
|
||||||
|
search_name: 'Milk',
|
||||||
|
limit: 20,
|
||||||
|
offset: 40,
|
||||||
|
cursor: 'cursor-1',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('listGroupedStockEntries defaults to expanded=1 and forwards options', async () => {
|
||||||
|
apiRequestMock.mockResolvedValueOnce([]);
|
||||||
|
|
||||||
|
await listGroupedStockEntries(
|
||||||
|
{ config: { database: 'db' } },
|
||||||
|
{ expanded: 0, searchName: 'Rice', limit: 10, offset: 0, cursor: 'cursor-2' },
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||||
|
{ config: { database: 'db' } },
|
||||||
|
'kitchen/items/grouped',
|
||||||
|
{
|
||||||
|
query: {
|
||||||
|
expanded: 0,
|
||||||
|
search_name: 'Rice',
|
||||||
|
limit: 10,
|
||||||
|
offset: 0,
|
||||||
|
cursor: 'cursor-2',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('listKitchenChanges returns normalized changes payload', async () => {
|
it('listKitchenChanges returns normalized changes payload', async () => {
|
||||||
apiRequestMock.mockResolvedValueOnce({
|
apiRequestMock.mockResolvedValueOnce({
|
||||||
since: 'cursor-1',
|
since: 'cursor-1',
|
||||||
|
|||||||
@@ -70,4 +70,59 @@ describe('stock mark-gone behavior', () => {
|
|||||||
message: 'Flour was marked gone and removed from the list.',
|
message: 'Flour was marked gone and removed from the list.',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('stock list grouped markGone removes item from grouped and flat collections', async () => {
|
||||||
|
useStockItemMock.mockResolvedValueOnce({ status: 'used' });
|
||||||
|
const addAlert = vi.fn();
|
||||||
|
const data = stockListPageData({ addAlert, isConnected: false });
|
||||||
|
|
||||||
|
data.groupedEntries = [
|
||||||
|
{
|
||||||
|
id: 10,
|
||||||
|
uuid_b64: 'group-10',
|
||||||
|
name: 'Beans',
|
||||||
|
stock_type: 'measured',
|
||||||
|
location_initial_uuid_b64: null,
|
||||||
|
date: '2026-04-12',
|
||||||
|
expire_date: '2026-04-20',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
id: 11,
|
||||||
|
uuid_b64: 'item-11',
|
||||||
|
name: 'Beans',
|
||||||
|
stock_type: 'measured',
|
||||||
|
quantity: 1,
|
||||||
|
location_initial_uuid_b64: null,
|
||||||
|
date: '2026-04-12',
|
||||||
|
expire_date: '2026-04-20',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
].map((group) => data.indexGroup(group));
|
||||||
|
data.entries = [
|
||||||
|
data.indexEntry({
|
||||||
|
id: 11,
|
||||||
|
uuid_b64: 'item-11',
|
||||||
|
name: 'Beans',
|
||||||
|
stock_type: 'measured',
|
||||||
|
quantity: 1,
|
||||||
|
location_initial_uuid_b64: null,
|
||||||
|
date: '2026-04-12',
|
||||||
|
expire_date: '2026-04-20',
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
data.entriesVersion = 1;
|
||||||
|
data.groupedVersion = 1;
|
||||||
|
data.editForms = { 11: { level: 'plenty', quantity: 1 } };
|
||||||
|
data.editErrors = {};
|
||||||
|
|
||||||
|
await data.markGoneFromGroup(data.groupedEntries[0].items[0], data.groupedEntries[0]);
|
||||||
|
|
||||||
|
expect(data.entries).toEqual([]);
|
||||||
|
expect(data.groupedEntries).toEqual([]);
|
||||||
|
expect(addAlert).toHaveBeenCalledWith({
|
||||||
|
type: 'success',
|
||||||
|
message: 'Beans was marked gone and removed from the group.',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,257 @@
|
|||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
|
||||||
|
const listStockEntriesMock = vi.fn();
|
||||||
|
const listGroupedStockEntriesMock = vi.fn();
|
||||||
|
const listKitchenChangesMock = vi.fn();
|
||||||
|
const updateStockItemMock = vi.fn();
|
||||||
|
const useStockItemMock = vi.fn();
|
||||||
|
const fetchLocationsMock = vi.fn();
|
||||||
|
|
||||||
|
vi.mock('../../../src/api/stock.js', () => ({
|
||||||
|
listStockEntries: (...args) => listStockEntriesMock(...args),
|
||||||
|
listGroupedStockEntries: (...args) => listGroupedStockEntriesMock(...args),
|
||||||
|
listKitchenChanges: (...args) => listKitchenChangesMock(...args),
|
||||||
|
updateStockItem: (...args) => updateStockItemMock(...args),
|
||||||
|
useStockItem: (...args) => useStockItemMock(...args),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock('../../../src/api/locations.js', () => ({
|
||||||
|
fetchLocations: (...args) => fetchLocationsMock(...args),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { stockListPageData } = await import('../../../src/features/stock/stock-list-page.js');
|
||||||
|
|
||||||
|
function createGroupedSummary() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 10,
|
||||||
|
uuid_b64: 'group-10',
|
||||||
|
name: 'Rice',
|
||||||
|
description: 'Basmati',
|
||||||
|
stock_type: 'measured',
|
||||||
|
level: 'good',
|
||||||
|
quantity: 1,
|
||||||
|
uom_symbol: 'kg',
|
||||||
|
location_initial_uuid_b64: 'loc-root',
|
||||||
|
date: '2026-04-10',
|
||||||
|
expire_date: '2026-04-25',
|
||||||
|
first_expire_date: '2026-04-25',
|
||||||
|
first_production_date: '2026-04-10',
|
||||||
|
items_count: 1,
|
||||||
|
items: [],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createGroupedExpanded() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
...createGroupedSummary()[0],
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
id: 100,
|
||||||
|
uuid_b64: 'item-100',
|
||||||
|
name: 'Rice',
|
||||||
|
description: 'Open bag',
|
||||||
|
stock_type: 'measured',
|
||||||
|
level: 'good',
|
||||||
|
quantity: 1,
|
||||||
|
uom_symbol: 'kg',
|
||||||
|
location_initial_uuid_b64: 'loc-root',
|
||||||
|
date: '2026-04-10',
|
||||||
|
expire_date: '2026-04-25',
|
||||||
|
expire_in: 13,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createWindowMock() {
|
||||||
|
const intervals = new Map();
|
||||||
|
let nextId = 1;
|
||||||
|
|
||||||
|
return {
|
||||||
|
location: { hash: '#/stock' },
|
||||||
|
setInterval: vi.fn((fn) => {
|
||||||
|
const id = nextId;
|
||||||
|
nextId += 1;
|
||||||
|
intervals.set(id, fn);
|
||||||
|
return id;
|
||||||
|
}),
|
||||||
|
clearInterval: vi.fn((id) => {
|
||||||
|
intervals.delete(id);
|
||||||
|
}),
|
||||||
|
addEventListener: vi.fn(),
|
||||||
|
removeEventListener: vi.fn(),
|
||||||
|
matchMedia: vi.fn(() => ({ matches: false })),
|
||||||
|
__intervals: intervals,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('stock list grouped-first behavior', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
listStockEntriesMock.mockReset();
|
||||||
|
listGroupedStockEntriesMock.mockReset();
|
||||||
|
listKitchenChangesMock.mockReset();
|
||||||
|
updateStockItemMock.mockReset();
|
||||||
|
useStockItemMock.mockReset();
|
||||||
|
fetchLocationsMock.mockReset();
|
||||||
|
|
||||||
|
globalThis.window = createWindowMock();
|
||||||
|
globalThis.requestAnimationFrame = (callback) => callback();
|
||||||
|
globalThis.HTMLDetailsElement = class MockDetailsElement {};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
delete globalThis.window;
|
||||||
|
delete globalThis.requestAnimationFrame;
|
||||||
|
delete globalThis.HTMLDetailsElement;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('defaults to grouped mode and loads grouped summary before lazy item list', async () => {
|
||||||
|
listGroupedStockEntriesMock
|
||||||
|
.mockResolvedValueOnce(createGroupedSummary())
|
||||||
|
.mockResolvedValueOnce(createGroupedExpanded());
|
||||||
|
listStockEntriesMock.mockResolvedValueOnce([]);
|
||||||
|
listKitchenChangesMock.mockResolvedValue({ since: null, nextCursor: null, changes: [] });
|
||||||
|
fetchLocationsMock.mockResolvedValue({ flat: [], tree: [] });
|
||||||
|
|
||||||
|
const store = { isConnected: true, addAlert: vi.fn() };
|
||||||
|
const data = stockListPageData(store);
|
||||||
|
data.$nextTick = vi.fn(async () => {});
|
||||||
|
|
||||||
|
await data.init();
|
||||||
|
|
||||||
|
expect(data.viewMode).toBe('grouped');
|
||||||
|
expect(listGroupedStockEntriesMock).toHaveBeenNthCalledWith(1, store, { expanded: 0 });
|
||||||
|
expect(listStockEntriesMock).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
await Promise.resolve();
|
||||||
|
|
||||||
|
expect(listGroupedStockEntriesMock).toHaveBeenNthCalledWith(2, store, { expanded: 1 });
|
||||||
|
|
||||||
|
await data.switchView('items');
|
||||||
|
expect(listStockEntriesMock).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
await data.switchView('grouped');
|
||||||
|
await data.switchView('items');
|
||||||
|
expect(listStockEntriesMock).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hydrates grouped children in background and merges into existing groups', async () => {
|
||||||
|
listGroupedStockEntriesMock
|
||||||
|
.mockResolvedValueOnce(createGroupedSummary())
|
||||||
|
.mockResolvedValueOnce(createGroupedExpanded());
|
||||||
|
|
||||||
|
const data = stockListPageData({ isConnected: true, addAlert: vi.fn() });
|
||||||
|
await data.loadGroupedEntries({ expanded: 0, resetVisible: true });
|
||||||
|
|
||||||
|
expect(data.groupedEntries[0].items).toEqual([]);
|
||||||
|
|
||||||
|
await data.hydrateGroupedEntriesInBackground();
|
||||||
|
|
||||||
|
expect(data.groupedHydrated).toBe(true);
|
||||||
|
expect(data.groupedEntries[0].items).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('memoizes filtered results and invalidates when filters change', () => {
|
||||||
|
const data = stockListPageData({ isConnected: true, addAlert: vi.fn() });
|
||||||
|
data.entries = [
|
||||||
|
data.indexEntry({
|
||||||
|
id: 1,
|
||||||
|
uuid_b64: 'item-1',
|
||||||
|
name: 'Milk',
|
||||||
|
description: 'Fresh',
|
||||||
|
location_initial_uuid_b64: null,
|
||||||
|
stock_type: 'binary',
|
||||||
|
level: 'good',
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
data.entriesVersion = 1;
|
||||||
|
|
||||||
|
const first = data.filteredEntries;
|
||||||
|
const second = data.filteredEntries;
|
||||||
|
|
||||||
|
expect(second).toBe(first);
|
||||||
|
|
||||||
|
data.filters.search = 'milk';
|
||||||
|
|
||||||
|
const third = data.filteredEntries;
|
||||||
|
expect(third).not.toBe(first);
|
||||||
|
expect(third).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps grouped data visible while background summary refresh is in progress', async () => {
|
||||||
|
let resolveRefresh;
|
||||||
|
const refreshPromise = new Promise((resolve) => {
|
||||||
|
resolveRefresh = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
|
listGroupedStockEntriesMock.mockImplementationOnce(() => refreshPromise);
|
||||||
|
|
||||||
|
const data = stockListPageData({ isConnected: true, addAlert: vi.fn() });
|
||||||
|
data.groupedLoaded = true;
|
||||||
|
data.groupedEntries = createGroupedSummary().map((group) => data.indexGroup(group));
|
||||||
|
|
||||||
|
const pending = data.loadGroupedEntries({ expanded: 0, background: true });
|
||||||
|
|
||||||
|
expect(data.state.isRefreshing).toBe(true);
|
||||||
|
expect(data.groupedEntries).toHaveLength(1);
|
||||||
|
|
||||||
|
resolveRefresh(createGroupedSummary());
|
||||||
|
await pending;
|
||||||
|
|
||||||
|
expect(data.state.isRefreshing).toBe(false);
|
||||||
|
expect(data.groupedEntries).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('poll refreshes view only when new changes exist', async () => {
|
||||||
|
listKitchenChangesMock
|
||||||
|
.mockResolvedValueOnce({ since: 'a', nextCursor: 'b', changes: [] })
|
||||||
|
.mockResolvedValueOnce({
|
||||||
|
since: 'b',
|
||||||
|
nextCursor: 'c',
|
||||||
|
changes: [{ type: 'stock', action: 'use', timestamp: '2026-04-12T08:00:00Z' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = stockListPageData({ isConnected: true, addAlert: vi.fn() });
|
||||||
|
const refreshSpy = vi.fn(async () => {});
|
||||||
|
data.refreshCurrentView = refreshSpy;
|
||||||
|
|
||||||
|
await data.pollKitchenChanges();
|
||||||
|
expect(refreshSpy).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
await data.pollKitchenChanges();
|
||||||
|
expect(refreshSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(refreshSpy).toHaveBeenCalledWith({ background: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tracks grouped card open state from details toggle events', () => {
|
||||||
|
const data = stockListPageData({ isConnected: true, addAlert: vi.fn() });
|
||||||
|
|
||||||
|
class MockDetails extends HTMLDetailsElement {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.open = true;
|
||||||
|
this.dataset = { groupId: '10' };
|
||||||
|
}
|
||||||
|
|
||||||
|
querySelector() {
|
||||||
|
return {
|
||||||
|
scrollIntoView: vi.fn(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const details = new MockDetails();
|
||||||
|
|
||||||
|
data.handleGroupedToggle({ target: details });
|
||||||
|
expect(data.isGroupedCardOpen(10)).toBe(true);
|
||||||
|
|
||||||
|
details.open = false;
|
||||||
|
data.handleGroupedToggle({ target: details });
|
||||||
|
expect(data.isGroupedCardOpen(10)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user