mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-30 02:38:47 -04:00
* Implement AddSeedsPicker component and enhance planting selection UI; update styles and serializers for better seed management * Enhance PlantingPicker component: add hints and titles for harvest and seed actions; update test to reflect changes in seed saving behavior * Enhance harvest recording: allow harvesting from crops without plantings; update forms and modals for better user experience * Refactor code structure for improved readability and maintainability * Remove AddSeedsPicker component and its associated tests * Add planting picker functionality for harvesting and seed saving - Introduced PlantingPickersController to handle JSON responses for member's plantings. - Updated HomeHelper to include crop ID in planting picker properties. - Refactored PlantPicker and PlantSomethingModal components to support multiple gardens. - Created PlantingFlow component to manage planting actions (harvest and save seeds). - Implemented RecordDialog component to handle server-rendered links for harvesting and seed saving. - Updated various views to include data attributes for triggering the record dialog. - Added routes for planting picker and corresponding request specs for testing. - Adjusted styles in _plantings.scss for better layout and spacing. * Add job management features including job creation and wishlist functionality * Remove WishlistJobsController and associated views and tests * Add suggestion links rendering and fix routes formatting * Refactor AddJobModal and JobPicker components to simplify props and enhance user experience * Update seed addition test to check dialog presence and current path * Apply suggestion from @CloCkWeRX --------- Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
68 lines
2.5 KiB
React
68 lines
2.5 KiB
React
import {render, screen, waitFor} from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
|
|
|
import RecordDialog from './RecordDialog';
|
|
|
|
vi.mock('./CropPicker', () => ({default: () => null}));
|
|
vi.mock('./RecordHarvestModal', () => ({
|
|
default: ({crop}) => <div role="dialog" aria-label={`Harvest ${crop.name}`} />,
|
|
}));
|
|
vi.mock('./SaveSeedsModal', () => ({
|
|
default: ({crop, source}) => <div role="dialog" aria-label={`Seeds ${crop.name} ${source}`} />,
|
|
}));
|
|
|
|
const plantings = [{id: 1, crop: {id: 2, name: 'Tomato'}}];
|
|
|
|
function links() {
|
|
render(
|
|
<>
|
|
<RecordDialog plantings_url="/planting_picker.json" />
|
|
<a href="/seeds/new" data-record-dialog="seeds" data-crop-id="2" data-crop-name="Tomato">Add tomato seeds</a>
|
|
<a href="/seeds/new" data-record-dialog="seeds">Add seeds</a>
|
|
<a href="/harvests/new" data-record-dialog="harvest" data-crop-id="5" data-crop-name="Kale">Harvest kale</a>
|
|
</>,
|
|
);
|
|
}
|
|
|
|
describe('RecordDialog', () => {
|
|
beforeEach(() => {
|
|
vi.stubGlobal('fetch', vi.fn(async () => ({ok: true, json: async () => plantings})));
|
|
});
|
|
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
it('starts closed', () => {
|
|
links();
|
|
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('asks where the seeds came from', async () => {
|
|
links();
|
|
await userEvent.click(screen.getByRole('link', {name: 'Add seeds'}));
|
|
expect(await screen.findByRole('dialog', {name: 'Where did these seeds come from?'})).toBeInTheDocument();
|
|
});
|
|
|
|
it('skips asking for the crop when the link names one', async () => {
|
|
links();
|
|
await userEvent.click(screen.getByRole('link', {name: 'Add tomato seeds'}));
|
|
await userEvent.click(await screen.findByRole('button', {name: 'Seeds I bought'}));
|
|
expect(screen.getByRole('dialog', {name: 'Seeds Tomato bought'})).toBeInTheDocument();
|
|
});
|
|
|
|
it('goes straight to the harvest when the crop has no plantings', async () => {
|
|
links();
|
|
await userEvent.click(screen.getByRole('link', {name: 'Harvest kale'}));
|
|
expect(await screen.findByRole('dialog', {name: 'Harvest Kale'})).toBeInTheDocument();
|
|
});
|
|
|
|
it('follows the link when the plantings do not load', async () => {
|
|
fetch.mockResolvedValue({ok: false, json: async () => null});
|
|
const location = {href: ''};
|
|
vi.stubGlobal('location', location);
|
|
links();
|
|
await userEvent.click(screen.getByRole('link', {name: 'Add seeds'}));
|
|
await waitFor(() => expect(location.href).toBe('/seeds/new'));
|
|
});
|
|
});
|