Skip to content

Commit

Permalink
Merge branch 'nk-add-items-from-list-page'
Browse files Browse the repository at this point in the history
  • Loading branch information
kweeuhree committed Oct 17, 2024
2 parents 6e10f2b + 73eedc4 commit 69c1c17
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/views/List.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { useEnsureListPath, useUrgency } from '../hooks';
import { getUrgency } from '../utils/urgencyUtils';
import { List as UnorderedList } from '@mui/material';
import { List as UnorderedList, Box, Grid } from '@mui/material';
import { ListItem, AddItems, TextInputElement } from '../components';

// React.memo is needed to prevent unnecessary re-renders of the List component
Expand Down Expand Up @@ -40,17 +40,31 @@ export const List = React.memo(function List({ data, listPath }) {
) : (
<>
<p>{listName}</p>
<Box sx={{ flexGrow: 1 }}>
<Grid
container
spacing={8}
columns={16}
justifyContent="space-between"
>
<Grid item size={{ xs: 2, sm: 4, md: 4 }}>
<AddItems items={data} />
</Grid>
<Grid item size={{ xs: 2, sm: 4, md: 4 }}>
<form onSubmit={(event) => event.preventDefault()}>
<TextInputElement
id="search-item"
type="search"
placeholder="Search Item..."
required={true}
onChange={handleTextChange}
label="Search Item:"
/>
</form>
</Grid>
</Grid>
</Box>

<form onSubmit={(event) => event.preventDefault()}>
<TextInputElement
id="search-item"
type="search"
placeholder="Search Item..."
required={true}
onChange={handleTextChange}
label="Search Item:"
/>
</form>
<UnorderedList>
{filteredItems.map((item) => {
const itemUrgencyStatus = getUrgency(item.name, urgencyObject);
Expand Down
14 changes: 14 additions & 0 deletions tests/List.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,18 @@ describe('List Component', () => {
'It seems like you landed here without first creating a list or selecting an existing one. Please select or create a new list first. Redirecting to Home.',
);
});

test('shows AddItems component with existing items', () => {
render(
<MemoryRouter>
<List data={mockShoppingListData} listPath={'/groceries'} />
</MemoryRouter>,
);

expect(screen.getByLabelText('Item Name:')).toBeInTheDocument();

Check failure on line 119 in tests/List.test.jsx

View workflow job for this annotation

GitHub Actions / Run Tests

tests/List.test.jsx > List Component > shows AddItems component with existing items

TestingLibraryElementError: Unable to find a label with the text of: Item Name: Ignored nodes: comments, script, style <body> <div /> </body> ❯ Object.getElementError node_modules/@testing-library/dom/dist/config.js:37:19 ❯ getAllByLabelText node_modules/@testing-library/dom/dist/queries/label-text.js:111:38 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:52:17 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:95:19 ❯ tests/List.test.jsx:119:17
expect(screen.getByLabelText('Soon')).toBeInTheDocument();
expect(screen.getByLabelText('Kind of soon')).toBeInTheDocument();
expect(screen.getByLabelText('Not soon')).toBeInTheDocument();
expect(screen.getByText('Submit')).toBeInTheDocument();
});
});

0 comments on commit 69c1c17

Please sign in to comment.