2026-06-24 16:20:59 +03:00
|
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
2026-05-25 06:23:59 +03:00
|
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
|
|
import { createVuetify } from 'vuetify';
|
2026-06-24 16:20:59 +03:00
|
|
|
|
import { createRouter, createMemoryHistory } from 'vue-router';
|
2026-05-25 06:23:59 +03:00
|
|
|
|
import ProjectLimitOverloadDialog from '../../resources/js/components/projects/ProjectLimitOverloadDialog.vue';
|
|
|
|
|
|
|
|
|
|
|
|
// Billing v2 Spec C Task 1.10 — диалог перегрузки лимита (§6.2). Принимает
|
|
|
|
|
|
// 409-payload `balance_insufficient`, эмитит решение пользователя.
|
|
|
|
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
current_balance_rub: '1000.00',
|
|
|
|
|
|
current_capacity_leads: 30,
|
|
|
|
|
|
would_be_required_leads: 50,
|
|
|
|
|
|
deficit_leads: 20,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const mountDialog = () =>
|
|
|
|
|
|
mount(ProjectLimitOverloadDialog, {
|
|
|
|
|
|
props: { modelValue: true, payload },
|
|
|
|
|
|
global: {
|
|
|
|
|
|
plugins: [createVuetify()],
|
|
|
|
|
|
stubs: { VDialog: { template: '<div><slot /></div>' } },
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('ProjectLimitOverloadDialog', () => {
|
|
|
|
|
|
it('рендерит данные 409-payload', () => {
|
|
|
|
|
|
const w = mountDialog();
|
|
|
|
|
|
const text = w.text();
|
|
|
|
|
|
expect(text).toContain('1000.00');
|
|
|
|
|
|
expect(text).toContain('30');
|
|
|
|
|
|
expect(text).toContain('50');
|
|
|
|
|
|
expect(text).toContain('20');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('«Сохранить и приостановить» эмитит save-blocked', async () => {
|
|
|
|
|
|
const w = mountDialog();
|
|
|
|
|
|
await w.find('[data-testid="overload-save-blocked"]').trigger('click');
|
|
|
|
|
|
expect(w.emitted('save-blocked')).toBeTruthy();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('«Поставить лимит 0» эмитит set-zero', async () => {
|
|
|
|
|
|
const w = mountDialog();
|
|
|
|
|
|
await w.find('[data-testid="overload-set-zero"]').trigger('click');
|
|
|
|
|
|
expect(w.emitted('set-zero')).toBeTruthy();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('«Отмена» закрывает диалог (update:modelValue=false)', async () => {
|
|
|
|
|
|
const w = mountDialog();
|
|
|
|
|
|
await w.find('[data-testid="overload-cancel"]').trigger('click');
|
|
|
|
|
|
expect(w.emitted('update:modelValue')?.[0]).toEqual([false]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-06-24 16:20:59 +03:00
|
|
|
|
it('косяк 06: текст на «вы», без «ты»', () => {
|
|
|
|
|
|
const w = mountDialog();
|
|
|
|
|
|
const text = w.text();
|
|
|
|
|
|
expect(text).toContain('У вас');
|
|
|
|
|
|
expect(text).not.toContain('У тебя');
|
|
|
|
|
|
expect(text).not.toContain('пополни ');
|
|
|
|
|
|
expect(text).not.toContain('поставь ');
|
|
|
|
|
|
expect(text).not.toContain('уменьши ');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('косяк 06: «Пополнить баланс» закрывает окно и ведёт в /billing', async () => {
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
|
history: createMemoryHistory(),
|
|
|
|
|
|
routes: [{ path: '/billing', component: { template: '<div>billing</div>' } }],
|
|
|
|
|
|
});
|
|
|
|
|
|
const push = vi.spyOn(router, 'push');
|
|
|
|
|
|
const w = mount(ProjectLimitOverloadDialog, {
|
|
|
|
|
|
props: { modelValue: true, payload },
|
|
|
|
|
|
global: { plugins: [createVuetify(), router], stubs: { VDialog: { template: '<div><slot /></div>' } } },
|
|
|
|
|
|
});
|
|
|
|
|
|
await w.find('[data-testid="overload-topup"]').trigger('click');
|
|
|
|
|
|
expect(w.emitted('update:modelValue')?.[0]).toEqual([false]);
|
|
|
|
|
|
expect(push).toHaveBeenCalledWith('/billing');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-05-25 06:23:59 +03:00
|
|
|
|
it('payload=null — без падения, ничего не рендерит', () => {
|
|
|
|
|
|
const w = mount(ProjectLimitOverloadDialog, {
|
|
|
|
|
|
props: { modelValue: true, payload: null },
|
|
|
|
|
|
global: { plugins: [createVuetify()], stubs: { VDialog: { template: '<div><slot /></div>' } } },
|
|
|
|
|
|
});
|
|
|
|
|
|
expect(w.find('[data-testid="overload-save-blocked"]').exists()).toBe(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|