remove wagtail and admin website, remove edit option, from hitung ayam, add create flock to settings
This commit is contained in:
1 parent
74dd3faf60
commit
30a736641f
39 files changed
+634
-819
No files matched your search
@@ -2,25 +2,36 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import SettingsPage from '../SettingsPage.tsx';
|
||||
|
||||
const { createKandangMock, createCycleMock, reloadMock, farmState } = vi.hoisted(() => ({
|
||||
createKandangMock: vi.fn(),
|
||||
createCycleMock: vi.fn(),
|
||||
reloadMock: vi.fn().mockResolvedValue(undefined),
|
||||
farmState: {
|
||||
sites: [{ id: 7, site_name: 'Site A', user: 99, created_at: '', updated_at: '' }],
|
||||
kandangs: [] as Array<{
|
||||
id: number;
|
||||
kandang_name: string;
|
||||
site: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}>,
|
||||
cycles: [] as unknown[],
|
||||
selectedSiteId: 7,
|
||||
selectedKandangId: null as number | null,
|
||||
selectedCycle: null as unknown,
|
||||
},
|
||||
}));
|
||||
const { createKandangMock, createFlockMock, createCycleMock, reloadMock, farmState } = vi.hoisted(
|
||||
() => ({
|
||||
createKandangMock: vi.fn(),
|
||||
createFlockMock: vi.fn(),
|
||||
createCycleMock: vi.fn(),
|
||||
reloadMock: vi.fn().mockResolvedValue(undefined),
|
||||
farmState: {
|
||||
sites: [{ id: 7, site_name: 'Site A', user: 99, created_at: '', updated_at: '' }],
|
||||
kandangs: [] as Array<{
|
||||
id: number;
|
||||
kandang_name: string;
|
||||
site: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}>,
|
||||
flocks: [] as Array<{
|
||||
id: number;
|
||||
flock_name: string;
|
||||
kandang: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}>,
|
||||
cycles: [] as unknown[],
|
||||
selectedSiteId: 7,
|
||||
selectedKandangId: null as number | null,
|
||||
selectedCycleId: null as number | null,
|
||||
selectedCycle: null as unknown,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
vi.mock('../../services/apiClient.ts', () => ({
|
||||
api: {
|
||||
@@ -32,6 +43,10 @@ vi.mock('../../services/apiClient.ts', () => ({
|
||||
create: createKandangMock,
|
||||
remove: vi.fn(),
|
||||
},
|
||||
flocks: {
|
||||
create: createFlockMock,
|
||||
remove: vi.fn(),
|
||||
},
|
||||
cycles: {
|
||||
create: createCycleMock,
|
||||
remove: vi.fn(),
|
||||
@@ -56,9 +71,11 @@ vi.mock('../../context/FarmContext.tsx', () => ({
|
||||
useFarm: () => ({
|
||||
sites: farmState.sites,
|
||||
kandangs: farmState.kandangs,
|
||||
flocks: farmState.flocks,
|
||||
cycles: farmState.cycles,
|
||||
selectedSiteId: farmState.selectedSiteId,
|
||||
selectedKandangId: farmState.selectedKandangId,
|
||||
selectedCycleId: farmState.selectedCycleId,
|
||||
selectedCycle: farmState.selectedCycle,
|
||||
reload: reloadMock,
|
||||
setSelectedSiteId: vi.fn(),
|
||||
@@ -70,12 +87,15 @@ vi.mock('../../context/FarmContext.tsx', () => ({
|
||||
describe('SettingsPage settings forms', () => {
|
||||
beforeEach(() => {
|
||||
createKandangMock.mockReset();
|
||||
createFlockMock.mockReset();
|
||||
createCycleMock.mockReset();
|
||||
reloadMock.mockClear();
|
||||
farmState.kandangs = [];
|
||||
farmState.flocks = [];
|
||||
farmState.cycles = [];
|
||||
farmState.selectedSiteId = 7;
|
||||
farmState.selectedKandangId = null;
|
||||
farmState.selectedCycleId = null;
|
||||
farmState.selectedCycle = null;
|
||||
createKandangMock.mockResolvedValue({
|
||||
id: 11,
|
||||
@@ -84,15 +104,21 @@ describe('SettingsPage settings forms', () => {
|
||||
created_at: '',
|
||||
updated_at: '',
|
||||
});
|
||||
createFlockMock.mockResolvedValue({
|
||||
id: 3,
|
||||
flock_name: 'Lantai 1',
|
||||
kandang: 11,
|
||||
created_at: '',
|
||||
updated_at: '',
|
||||
});
|
||||
createCycleMock.mockResolvedValue({
|
||||
id: 21,
|
||||
kandang: 11,
|
||||
flock: 3,
|
||||
total_days: 35,
|
||||
current_day: 1,
|
||||
start_date: '2026-08-18',
|
||||
end_date: '2026-09-21',
|
||||
chick_in_weight: 45,
|
||||
chick_in_weight: 35,
|
||||
doc_in_count: 20000,
|
||||
status: 'active',
|
||||
created_at: '',
|
||||
@@ -116,7 +142,7 @@ describe('SettingsPage settings forms', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('submits cycle fields expected by the backend contract', async () => {
|
||||
it('submits flock fields for the selected kandang', async () => {
|
||||
farmState.kandangs = [
|
||||
{ id: 11, kandang_name: 'Kandang 1', site: 7, created_at: '', updated_at: '' },
|
||||
];
|
||||
@@ -124,6 +150,27 @@ describe('SettingsPage settings forms', () => {
|
||||
|
||||
render(<SettingsPage />);
|
||||
|
||||
fireEvent.change(screen.getByPlaceholderText('Nama flock'), {
|
||||
target: { value: 'Lantai 1' },
|
||||
});
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Tambah flock' }));
|
||||
|
||||
await waitFor(() => expect(createFlockMock).toHaveBeenCalledTimes(1));
|
||||
expect(createFlockMock).toHaveBeenCalledWith({
|
||||
flock_name: 'Lantai 1',
|
||||
kandang: 11,
|
||||
});
|
||||
});
|
||||
|
||||
it('submits cycle fields without flock assignment', async () => {
|
||||
farmState.kandangs = [
|
||||
{ id: 11, kandang_name: 'Kandang 1', site: 7, created_at: '', updated_at: '' },
|
||||
];
|
||||
farmState.selectedKandangId = 11;
|
||||
|
||||
render(<SettingsPage />);
|
||||
|
||||
expect(screen.queryByLabelText(/^Siklus$/i)).not.toBeInTheDocument();
|
||||
expect(screen.queryByLabelText(/Total hari/i)).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText(/Mulai/i), { target: { value: '2026-08-01' } });
|
||||
@@ -137,9 +184,8 @@ describe('SettingsPage settings forms', () => {
|
||||
current_day: 1,
|
||||
start_date: '2026-08-01',
|
||||
end_date: '2026-09-04',
|
||||
chick_in_weight: 45,
|
||||
chick_in_weight: 35,
|
||||
doc_in_count: 20000,
|
||||
status: 'active',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user