import { describe, it, expect, vi, beforeEach } from 'vitest'; import { mount } from '@vue/test-utils'; import { createVuetify } from 'vuetify'; import axios from 'axios'; import AdminSupplierIntegrationView from '../../resources/js/views/admin/AdminSupplierIntegrationView.vue'; vi.mock('axios'); const vuetify = createVuetify(); describe('AdminSupplierIntegrationView — тумблер разблокировки смены источника', () => { beforeEach(() => { vi.clearAllMocks(); (axios.get as ReturnType).mockImplementation((url: string) => { if (url.endsWith('/source-edit-flag')) { return Promise.resolve({ data: { enabled: true } }); } 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).mockResolvedValue({ data: { enabled: false } }); }); it('GETs the flag on mount and renders the toggle card 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/source-edit-flag'); const card = wrapper.find('[data-testid="source-edit-flag-card"]'); expect(card.exists()).toBe(true); expect(wrapper.text()).toContain('Разблокировка смены источника'); // флаг enabled=true с бэка → подпись «Включена» expect(wrapper.text()).toContain('Включена'); }); });