Merge pull request #128 from beatz174-bit/codex/fix-packaging-type-filter-functionality-2fmtlc
Allow packaging filters when statuses are mixed
This commit is contained in:
@@ -500,7 +500,7 @@ describe('ActivePickListScreen product search', () => {
|
|||||||
expect(itemLabels).toEqual(['Apple Juice', 'Chips', 'Cola', 'Cola']);
|
expect(itemLabels).toEqual(['Apple Juice', 'Chips', 'Cola', 'Cola']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('disables packaging filters when only one packaging type is present', () => {
|
it('keeps packaging filters enabled when items share a single packaging type but mixed statuses', () => {
|
||||||
pickItemsMock.mockReturnValue([
|
pickItemsMock.mockReturnValue([
|
||||||
{
|
{
|
||||||
id: 'item-1',
|
id: 'item-1',
|
||||||
@@ -512,6 +512,16 @@ describe('ActivePickListScreen product search', () => {
|
|||||||
created_at: 0,
|
created_at: 0,
|
||||||
updated_at: 0,
|
updated_at: 0,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'item-2',
|
||||||
|
pick_list_id: 'list-1',
|
||||||
|
product_id: 'prod-2',
|
||||||
|
quantity: 1,
|
||||||
|
is_carton: false,
|
||||||
|
status: 'picked',
|
||||||
|
created_at: 0,
|
||||||
|
updated_at: 0,
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
render(
|
render(
|
||||||
@@ -522,9 +532,8 @@ describe('ActivePickListScreen product search', () => {
|
|||||||
</MemoryRouter>,
|
</MemoryRouter>,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByRole('radio', { name: /all/i })).toBeChecked();
|
expect(screen.getByRole('radio', { name: /cartons/i })).toBeEnabled();
|
||||||
expect(screen.getByRole('radio', { name: /cartons/i })).toBeDisabled();
|
expect(screen.getByRole('radio', { name: /units/i })).toBeEnabled();
|
||||||
expect(screen.getByRole('radio', { name: /units/i })).toBeDisabled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('enables and disables packaging filters based on the visible item statuses', async () => {
|
it('enables and disables packaging filters based on the visible item statuses', async () => {
|
||||||
@@ -647,7 +656,9 @@ describe('ActivePickListScreen product search', () => {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const { rerender } = render(
|
const user = userEvent.setup();
|
||||||
|
|
||||||
|
render(
|
||||||
<MemoryRouter initialEntries={['/pick-lists/1']} future={{ v7_startTransition: true, v7_relativeSplatPath: true }}>
|
<MemoryRouter initialEntries={['/pick-lists/1']} future={{ v7_startTransition: true, v7_relativeSplatPath: true }}>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/pick-lists/:id" element={<ActivePickListScreen />} />
|
<Route path="/pick-lists/:id" element={<ActivePickListScreen />} />
|
||||||
@@ -658,32 +669,14 @@ describe('ActivePickListScreen product search', () => {
|
|||||||
await user.click(screen.getByRole('radio', { name: /cartons/i }));
|
await user.click(screen.getByRole('radio', { name: /cartons/i }));
|
||||||
expect(screen.getByRole('radio', { name: /cartons/i })).toBeChecked();
|
expect(screen.getByRole('radio', { name: /cartons/i })).toBeChecked();
|
||||||
|
|
||||||
pickItemsMock.mockReturnValue([
|
await user.click(screen.getByLabelText(/show picked/i));
|
||||||
{
|
|
||||||
id: 'item-2',
|
|
||||||
pick_list_id: 'list-1',
|
|
||||||
product_id: 'prod-2',
|
|
||||||
quantity: 1,
|
|
||||||
is_carton: false,
|
|
||||||
status: 'pending',
|
|
||||||
created_at: 0,
|
|
||||||
updated_at: 0,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
rerender(
|
await waitFor(() => expect(screen.getByRole('radio', { name: /all/i })).toBeChecked());
|
||||||
<MemoryRouter initialEntries={['/pick-lists/1']} future={{ v7_startTransition: true, v7_relativeSplatPath: true }}>
|
expect(screen.getByRole('radio', { name: /cartons/i })).toBeDisabled();
|
||||||
<Routes>
|
|
||||||
<Route path="/pick-lists/:id" element={<ActivePickListScreen />} />
|
|
||||||
</Routes>
|
|
||||||
</MemoryRouter>,
|
|
||||||
);
|
|
||||||
|
|
||||||
await waitFor(() => expect(screen.getByRole('radio', { name: /cartons/i })).toBeDisabled());
|
|
||||||
expect(screen.getByRole('radio', { name: /all/i })).toBeChecked();
|
|
||||||
expect(screen.getByRole('radio', { name: /units/i })).toBeDisabled();
|
expect(screen.getByRole('radio', { name: /units/i })).toBeDisabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('hides picked items when show picked is unchecked', async () => {
|
it('hides picked items when show picked is unchecked', async () => {
|
||||||
pickItemsMock.mockReturnValue([
|
pickItemsMock.mockReturnValue([
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ export const ActivePickListScreen = () => {
|
|||||||
} else if (itemFilter === 'units' && !hasUnitItems) {
|
} else if (itemFilter === 'units' && !hasUnitItems) {
|
||||||
setItemFilter('cartons');
|
setItemFilter('cartons');
|
||||||
}
|
}
|
||||||
}, [itemFilter, hasCartonItems, hasUnitItems, packagingTypeCount]);
|
}, [itemFilter, packagingFiltersDisabled]);
|
||||||
|
|
||||||
const visibleItems = useMemo(() => {
|
const visibleItems = useMemo(() => {
|
||||||
let filteredItems = showPicked
|
let filteredItems = showPicked
|
||||||
@@ -456,13 +456,13 @@ export const ActivePickListScreen = () => {
|
|||||||
value="cartons"
|
value="cartons"
|
||||||
control={<Radio />}
|
control={<Radio />}
|
||||||
label="Cartons"
|
label="Cartons"
|
||||||
disabled={packagingFiltersDisabled || !hasCartonItems}
|
disabled={packagingFiltersDisabled}
|
||||||
/>
|
/>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
value="units"
|
value="units"
|
||||||
control={<Radio />}
|
control={<Radio />}
|
||||||
label="Units"
|
label="Units"
|
||||||
disabled={packagingFiltersDisabled || !hasUnitItems}
|
disabled={packagingFiltersDisabled}
|
||||||
/>
|
/>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
<Stack direction="row" spacing={1} alignItems="center" sx={{ ml: { xs: 0, sm: 2 } }}>
|
<Stack direction="row" spacing={1} alignItems="center" sx={{ ml: { xs: 0, sm: 2 } }}>
|
||||||
|
|||||||
Reference in New Issue
Block a user