Files
portal/app/tests/Frontend/AdminSupplierIntegrationView.manual-queue.spec.ts
T

81 lines
3.4 KiB
TypeScript
Raw Normal View History

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 — manual queue section', () => {
beforeEach(() => {
vi.clearAllMocks();
(axios.get as ReturnType<typeof vi.fn>).mockImplementation((url: string) => {
if (url.endsWith('/manual-queue')) {
return Promise.resolve({
data: {
queue: [
{
id: 1,
project_id: 42,
platform: 'B1',
operation: 'create',
external_id: null,
payload_snapshot: { limit: 10, signal_type: 'site', unique_key: 'foo.com' },
failure_reason: 'contract_break',
created_at: '2026-05-19T10:00:00Z',
},
],
},
});
}
return Promise.resolve({ data: { health: null, history: [] } });
});
});
it('renders pending queue rows with payload + reason', async () => {
const wrapper = mount(AdminSupplierIntegrationView, { global: { plugins: [vuetify] } });
await new Promise((r) => setTimeout(r, 50));
const text = wrapper.text();
expect(text).toContain('foo.com');
expect(text).toContain('contract_break');
expect(text).toContain('B1');
});
it('clicking «Отметить выполнено» → подтверждение в диалоге → calls resolve endpoint', async () => {
(axios.post as ReturnType<typeof vi.fn>).mockResolvedValue({
data: { resolved: true, external_id: 700123 },
});
// window.confirm заменён на v-dialog (UI-аудит). Стабим VDialog passthrough,
// чтобы контент диалога рендерился инлайн и кнопка «Подтверждаю» была кликабельна.
const wrapper = mount(AdminSupplierIntegrationView, {
global: {
plugins: [vuetify],
stubs: {
VDialog: {
template: '<div class="dialog-stub" v-if="modelValue"><slot /></div>',
props: ['modelValue'],
},
},
},
});
await new Promise((r) => setTimeout(r, 50));
// Клик по «Отметить выполнено» открывает диалог подтверждения (askResolve).
const btn = wrapper.find('[data-testid="resolve-1"]');
expect(btn.exists()).toBe(true);
await btn.trigger('click');
await wrapper.vm.$nextTick();
// Подтверждаем в диалоге → doResolve → POST.
const confirmBtn = wrapper.findAll('button').find((b) => b.text().includes('Подтверждаю'));
expect(confirmBtn).toBeTruthy();
await confirmBtn!.trigger('click');
expect(axios.post).toHaveBeenCalledWith(expect.stringContaining('/manual-queue/1/resolve'));
});
});