update api configuration for panel iot and adjust ai insight
This commit is contained in:
1 parent
a2b5b10977
commit
20d04acb3e
20 files changed
+814
-177
No files matched your search
@@ -2,10 +2,11 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import SettingsPage from '../SettingsPage.tsx';
|
||||
|
||||
const { createKandangMock, createFlockMock, createCycleMock, updateCycleMock, reloadMock, farmState } = vi.hoisted(
|
||||
const { createKandangMock, createFlockMock, updateFlockMock, createCycleMock, updateCycleMock, reloadMock, farmState } = vi.hoisted(
|
||||
() => ({
|
||||
createKandangMock: vi.fn(),
|
||||
createFlockMock: vi.fn(),
|
||||
updateFlockMock: vi.fn(),
|
||||
createCycleMock: vi.fn(),
|
||||
updateCycleMock: vi.fn(),
|
||||
reloadMock: vi.fn().mockResolvedValue(undefined),
|
||||
@@ -21,6 +22,7 @@ const { createKandangMock, createFlockMock, createCycleMock, updateCycleMock, re
|
||||
flocks: [] as Array<{
|
||||
id: number;
|
||||
flock_name: string;
|
||||
iot_api_url?: string;
|
||||
kandang: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
@@ -46,6 +48,7 @@ vi.mock('../../services/apiClient.ts', () => ({
|
||||
},
|
||||
flocks: {
|
||||
create: createFlockMock,
|
||||
update: updateFlockMock,
|
||||
remove: vi.fn(),
|
||||
},
|
||||
cycles: {
|
||||
@@ -91,6 +94,7 @@ describe('SettingsPage settings forms', () => {
|
||||
beforeEach(() => {
|
||||
createKandangMock.mockReset();
|
||||
createFlockMock.mockReset();
|
||||
updateFlockMock.mockReset();
|
||||
createCycleMock.mockReset();
|
||||
updateCycleMock.mockReset();
|
||||
reloadMock.mockClear();
|
||||
@@ -111,6 +115,15 @@ describe('SettingsPage settings forms', () => {
|
||||
createFlockMock.mockResolvedValue({
|
||||
id: 3,
|
||||
flock_name: 'Lantai 1',
|
||||
iot_api_url: '',
|
||||
kandang: 11,
|
||||
created_at: '',
|
||||
updated_at: '',
|
||||
});
|
||||
updateFlockMock.mockResolvedValue({
|
||||
id: 3,
|
||||
flock_name: 'Lantai 1',
|
||||
iot_api_url: 'https://example.test/iot/lantai-1',
|
||||
kandang: 11,
|
||||
created_at: '',
|
||||
updated_at: '',
|
||||
@@ -179,6 +192,35 @@ describe('SettingsPage settings forms', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('saves flock IoT API URL for a listed flock', async () => {
|
||||
farmState.kandangs = [
|
||||
{ id: 11, kandang_name: 'Kandang 1', site: 'site-a', created_at: '', updated_at: '' },
|
||||
];
|
||||
farmState.selectedKandangId = 11;
|
||||
farmState.flocks = [
|
||||
{
|
||||
id: 3,
|
||||
flock_name: 'Lantai 1',
|
||||
iot_api_url: '',
|
||||
kandang: 11,
|
||||
created_at: '',
|
||||
updated_at: '',
|
||||
},
|
||||
];
|
||||
|
||||
render(<SettingsPage />);
|
||||
|
||||
fireEvent.change(screen.getByPlaceholderText('https://…/api/iot/…'), {
|
||||
target: { value: 'https://example.test/iot/lantai-1' },
|
||||
});
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Simpan URL IoT' }));
|
||||
|
||||
await waitFor(() => expect(updateFlockMock).toHaveBeenCalledTimes(1));
|
||||
expect(updateFlockMock).toHaveBeenCalledWith(3, {
|
||||
iot_api_url: 'https://example.test/iot/lantai-1',
|
||||
});
|
||||
});
|
||||
|
||||
it('submits cycle fields without flock assignment', async () => {
|
||||
farmState.kandangs = [
|
||||
{ id: 11, kandang_name: 'Kandang 1', site: 'site-a', created_at: '', updated_at: '' },
|
||||
|
||||
Reference in new issue
Block a user