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

Remove manual chunks #83

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions tests/List.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { List } from '../src/views/List';
import { mockShoppingListData } from '../src/mocks/__fixtures__/shoppingListData';
import { useStateWithStorage, useEnsureListPath } from '../src/hooks';
import {
useStateWithStorage,
useEnsureListPath,
useUrgency,
} from '../src/hooks';
import {
getDateLastPurchasedOrDateCreated,
getDaysFromDate,
Expand All @@ -12,20 +16,7 @@ import {
vi.mock('../src/hooks', () => ({
useEnsureListPath: vi.fn(),
useStateWithStorage: vi.fn(),
useUrgency: vi.fn(() => ({
getUrgency: vi.fn((name) => {
if (name === 'nutella') return 'soon';
if (name === 'Cheese') return 'overdue';
return 'notSoon';
}),
urgencyObject: {
overdue: [{ name: 'nutella', id: '0T1ByXr8YJSOzujOlLMI' }],
soon: [{ name: 'Cheese', id: '1MFWOWMCzDtEHQboFZfR' }],
kindOfSoon: [],
notSoon: [{ name: 'Jam', id: 'MnUiYUmhg8iCzX1eMxW8' }],
inactive: [],
},
})),
useUrgency: vi.fn(),
}));

vi.mock('../src/utils', () => ({
Expand All @@ -36,6 +27,7 @@ vi.mock('../src/utils', () => ({
}));

beforeEach(() => {
vi.clearAllMocks();
Object.defineProperty(window, 'localStorage', {
value: {
getItem: vi.fn((key) => {
Expand All @@ -52,6 +44,21 @@ beforeEach(() => {

vi.spyOn(window, 'alert').mockImplementation(() => {});
useStateWithStorage.mockReturnValue(['/groceries']);
useEnsureListPath.mockReturnValue(false);
useUrgency.mockReturnValue({
getUrgency: vi.fn((name) => {
if (name === 'nutella') return 'soon';
if (name === 'Cheese') return 'overdue';
return 'notSoon';
}),
urgencyObject: {
overdue: [{ name: 'nutella', id: '0T1ByXr8YJSOzujOlLMI' }],
soon: [{ name: 'Cheese', id: '1MFWOWMCzDtEHQboFZfR' }],
kindOfSoon: [],
notSoon: [{ name: 'Jam', id: 'MnUiYUmhg8iCzX1eMxW8' }],
inactive: [],
},
});
getDateLastPurchasedOrDateCreated.mockReturnValue(new Date());
getDaysFromDate.mockReturnValue(10);
getDaysBetweenDates.mockReturnValue(5);
Expand Down Expand Up @@ -81,6 +88,9 @@ describe('List Component', () => {
);

expect(screen.getByText('Welcome to groceries!')).toBeInTheDocument();
expect(
screen.getByText('Ready to add your first item? Start adding below!'),
).toBeInTheDocument();
expect(screen.getByLabelText('Item Name:')).toBeInTheDocument();
expect(screen.getByLabelText('Soon')).toBeInTheDocument();
expect(screen.getByLabelText('Kind of soon')).toBeInTheDocument();
Expand All @@ -89,8 +99,6 @@ describe('List Component', () => {
});

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.',
Expand Down
16 changes: 1 addition & 15 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,7 @@ export default defineConfig(({ mode }) => ({
build: {
outDir: './build',
target: 'esnext',
rollupOptions: {
output: {
manualChunks: (id) => {
if (id.includes('node_modules')) {
if (id.includes('react')) {
return 'vendor__react';
}
if (id.includes('firebase')) {
return 'vendor__firebase';
}
return 'vendor';
}
},
},
},
rollupOptions: {},
},
plugins: [
mode === 'development' && eslint(),
Expand Down