Files
portal/app/tests/Frontend/AdminSupplierIntegrationView.export-mode.spec.ts
T
Дмитрий 01d292f5a9 feat(admin): supplier export-mode toggle (online|batch) endpoint + UI
План 4 Task 1 эпика project-migration-redesign.

- AdminSupplierIntegrationController +getExportMode/setExportMode
  (validation in:online,batch; system_settings upsert).
- Routes: GET/POST /api/admin/supplier-integration/export-mode
  в admin-группе рядом с manual-queue.
- AdminSupplierIntegrationView.vue +секция «Режим экспорта проектов»
  с v-btn-toggle (online|batch), подпись о ночном синке 18:00.
- Pest 3/3 + Vitest 2/2 (+ соседние 5 не сломаны).
- phpstan-baseline.neon +6 ignore (Pest TestCall::actingAs/getJson/postJson
  — типовой паттерн, как в SupplierManualQueueTest).
2026-05-20 14:34:22 +03:00

54 lines
2.3 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { mount } from '@vue/test-utils';
import { createVuetify } from 'vuetify';
import * as components from 'vuetify/components';
import * as directives from 'vuetify/directives';
import axios from 'axios';
import AdminSupplierIntegrationView from '../../resources/js/views/admin/AdminSupplierIntegrationView.vue';
vi.mock('axios');
const vuetify = createVuetify({ components, directives });
describe('AdminSupplierIntegrationView — export-mode toggle (Plan 4 Task 1)', () => {
beforeEach(() => {
vi.clearAllMocks();
(axios.get as ReturnType<typeof vi.fn>).mockImplementation((url: string) => {
if (url.endsWith('/export-mode')) {
return Promise.resolve({ data: { mode: 'batch' } });
}
if (url.endsWith('/manual-queue')) {
return Promise.resolve({ data: { queue: [] } });
}
return Promise.resolve({ data: { health: null, history: [] } });
});
(axios.post as ReturnType<typeof vi.fn>).mockResolvedValue({ data: { mode: 'online' } });
});
it('GETs current mode on mount and renders the toggle with current label', async () => {
const wrapper = mount(AdminSupplierIntegrationView, { global: { plugins: [vuetify] } });
await new Promise((r) => setTimeout(r, 50));
expect(axios.get).toHaveBeenCalledWith('/api/admin/supplier-integration/export-mode');
const toggle = wrapper.find('[data-testid="export-mode-toggle"]');
expect(toggle.exists()).toBe(true);
expect(wrapper.text()).toContain('Режим экспорта проектов');
expect(wrapper.text()).toContain('Пакетный');
});
it('switching to online POSTs the new value', async () => {
const wrapper = mount(AdminSupplierIntegrationView, { global: { plugins: [vuetify] } });
await new Promise((r) => setTimeout(r, 50));
const onlineBtn = wrapper.find('[data-testid="export-mode-online"]');
expect(onlineBtn.exists()).toBe(true);
await onlineBtn.trigger('click');
await new Promise((r) => setTimeout(r, 20));
expect(axios.post).toHaveBeenCalledWith(
'/api/admin/supplier-integration/export-mode',
{ mode: 'online' },
);
});
});