Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nk add items from list page #77

Closed
wants to merge 10 commits into from
31 changes: 12 additions & 19 deletions tests/List.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,49 +73,42 @@ describe('List Component', () => {
});
});

test('shows welcome message and AddItems component when no items are present', () => {
test('shows AddItems component with existing items', () => {
render(
<MemoryRouter>
<List data={[]} listPath={'/groceries'} />
<List data={mockShoppingListData} listPath={'/groceries'} />
</MemoryRouter>,
);

expect(screen.getByText('Welcome to groceries!')).toBeInTheDocument();
expect(screen.getByLabelText('Item Name:')).toBeInTheDocument();
expect(screen.getByLabelText('Soon')).toBeInTheDocument();
expect(screen.getByLabelText('Kind of soon')).toBeInTheDocument();
expect(screen.getByLabelText('Not soon')).toBeInTheDocument();
expect(screen.getByText('Submit')).toBeInTheDocument();
});

test('triggers alert and redirects when no list path is found in localStorage', () => {
window.localStorage.getItem.mockReturnValueOnce(null);

useEnsureListPath.mockImplementation(() => {
window.alert(
'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.',
);
return true;
});

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

expect(window.alert).toHaveBeenCalledWith(
'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.',
);
expect(screen.getByLabelText('Item Name:')).toBeInTheDocument();
expect(screen.getByLabelText('Soon')).toBeInTheDocument();
expect(screen.getByLabelText('Kind of soon')).toBeInTheDocument();
expect(screen.getByLabelText('Not soon')).toBeInTheDocument();
expect(screen.getByText('Submit')).toBeInTheDocument();
});

test('shows AddItems component with existing items', () => {
test('shows welcome message and AddItems component when no items are present', () => {
render(
<MemoryRouter>
<List data={mockShoppingListData} listPath={'/groceries'} />
<List data={[]} listPath={'/groceries'} />
</MemoryRouter>,
);

expect(screen.getByText('Welcome to groceries!')).toBeInTheDocument();
expect(screen.getByLabelText('Item Name:')).toBeInTheDocument();
expect(screen.getByLabelText('Soon')).toBeInTheDocument();
expect(screen.getByLabelText('Kind of soon')).toBeInTheDocument();
Expand Down