Files
portal/app/tests/Frontend/SystemSettingEditDialog.spec.ts
T
Дмитрий 768628d914 phase2(7-features): bulk-actions / new-deal / tenant-card / system-edit / webhook / smart-filters / impersonation-list
7-фичный auto-mode пакет согласно «карте что осталось» (после v1.54).

(1) Bulk-actions DealsView:
- dealsState reactive-копия MOCK_DEALS (deep-clone) для безопасного bulk-edit.
- Bulk-bar (sticky, теало-нуар, theme=dark) при selected.length > 0:
  count + Сменить статус (v-menu × 14 lead_statuses) + Экспорт (snackbar) +
  Удалить (v-dialog confirm) + ✕ clear.
- На production: smart status-transition с проверкой allowed-переходов;
  soft-delete (архив 30 дней); реальный CSV/XLSX export через xlsx-lib.

(2) NewDealDialog (used in DealsView+KanbanView):
- 6 полей: name/phone/project (MOCK_PROJECTS) / manager (MOCK_MANAGERS) /
  cost / status (default 'new' или presetStatus). Phone-валидация ≥10 цифр.
- emit('created', deal) → DealsView push в начало dealsState; KanbanView push
  в правильную колонку по statusSlug + totalDeals++.

(3) AdminTenantDetailView (/admin/tenants/:code):
- 4 KPI cards (Баланс/runway / Тариф+MRR/мес / Лиды сегодня+неделя+месяц /
  Средняя цена). 4 v-tabs: Финансы (balance-history) / Пользователи /
  Проекты / Активность с event-кодами.
- Кнопка «Войти как клиент» (использует ImpersonationDialog из v1.54).
  404-fallback. composables/mockTenantDetail.ts с expandTenantDetail.
- AdminTenantsView получил @click:row → router.push.

(4) Edit-flow AdminSystemView (audit-log + 2-step):
- Backend: SystemSetting + SaasAdminAuditLog Eloquent (append-only,
  payload_before/after JSONB casts).
- AdminSystemSettingsController с GET (list) + PUT (update в DB::transaction
  + INSERT в saas_admin_audit_log; hash-chain trigger BEFORE INSERT
  заполняет log_hash).
- Type-validation: int/decimal/bool/json. Reason ≥30 chars. No-op → 422.
- Frontend SystemSettingEditDialog — 3-step (edit → confirm с diff
  before/after → done).

(5) Webhook receive endpoint (POST /api/webhook/{token}):
- WebhookReceiveController::receive. Token = tenants.webhook_token.
- 404 unknown / 422 bad payload / 202 success + dispatch ProcessWebhookJob.
- Stub-INSERT в webhook_log через DB::table обёрнут в DB::transaction +
  SET LOCAL app.current_tenant_id для RLS.
- CSRF-исключение для api/webhook/* в bootstrap/app.php.
- На prod: + HMAC X-Webhook-Signature + per-token rate-limit.

(6) Smart-filters:
- DealsView: multi-select v-select Проект+Менеджер с auto availableProjects/
  availableManagers computed.
- AdminTenantsView: filterStatuses (4 STATUS_OPTIONS) + filterTariffs
  (computed availableTariffs).
- Кнопка «Сбросить» появляется только когда фильтры активны.

(7) AdminImpersonationView (/admin/impersonation):
- Backend +2 GET endpoints: /active (used_at != null AND session_ended_at
  == null) + /recent (last 20 завершённых с duration_seconds через
  abs(diffInSeconds) — Carbon signed по умолчанию).
- ImpersonationToken получил belongsTo(Tenant).
- Frontend view: 2 секции (Активные с end-кнопкой / Недавно завершённые
  read-only) + refresh + onMounted load.
- Маршрут /admin/impersonation + 5-й nav-пункт «Impersonation» в AdminLayout.

Vitest +48 (всего 238/238 за 15.31 сек).
Pest +16 (всего 136/136 за 15.8 сек, 495 assertions).
PHPStan baseline регенерирован (0 errors после фикса nullsafe.neverNull).

Регресс: lint+type-check+format ; vite build 937 ms; Pint+PHPStan passed;
Pest 136/136. Реестр v1.54→v1.55, CLAUDE.md v1.45→v1.46.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 05:33:21 +03:00

160 lines
6.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { mount, flushPromises } from '@vue/test-utils';
import { createVuetify } from 'vuetify';
vi.mock('../../resources/js/api/admin', () => ({
updateSystemSetting: vi.fn(),
listSystemSettings: vi.fn(),
}));
vi.mock('../../resources/js/api/client', () => ({
extractValidationErrors: vi.fn(() => null),
extractErrorMessage: vi.fn((_e, fb?: string) => fb ?? 'err'),
apiClient: {},
ensureCsrfCookie: vi.fn(),
}));
import * as adminApi from '../../resources/js/api/admin';
import SystemSettingEditDialog from '../../resources/js/components/admin/SystemSettingEditDialog.vue';
const sampleSetting: adminApi.SystemSetting = {
key: 'login_max_attempts',
value: '5',
type: 'int',
description: 'Макс. неудачных попыток входа в окне 15 минут',
updated_at: '2026-05-09T10:00:00',
updated_by: null,
};
const factory = (
props: { modelValue: boolean; setting: adminApi.SystemSetting | null } = {
modelValue: true,
setting: sampleSetting,
},
) =>
mount(SystemSettingEditDialog, {
props: { ...props, requestedBy: 1 },
global: {
plugins: [createVuetify()],
stubs: {
VDialog: {
template: '<div class="dialog-stub" v-if="modelValue"><slot /></div>',
props: ['modelValue'],
},
},
},
});
describe('SystemSettingEditDialog.vue', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('не рендерит content при modelValue=false', () => {
const wrapper = factory({ modelValue: false, setting: sampleSetting });
expect(wrapper.find('.dialog-stub').exists()).toBe(false);
});
it('step 1 — показывает key + type-chip + текущее значение + 2 input', () => {
const wrapper = factory();
const text = wrapper.text();
expect(text).toContain('login_max_attempts');
expect(text).toContain('int');
expect(text).toContain('Макс. неудачных попыток');
expect(wrapper.find('[data-testid="value-input"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="reason-input"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="next-btn"]').exists()).toBe(true);
});
it('newValue по умолчанию = текущее значение setting', () => {
const wrapper = factory();
const vm = wrapper.vm as unknown as { newValue: string };
expect(vm.newValue).toBe('5');
});
it('Далее без изменения значения → ошибка «совпадает»', async () => {
const wrapper = factory();
const vm = wrapper.vm as unknown as { reason: string; valueError: string | null; step: string };
vm.reason = 'A'.repeat(35);
await wrapper.vm.$nextTick();
await wrapper.find('[data-testid="next-btn"]').trigger('click');
await flushPromises();
expect(vm.valueError).toContain('совпадает');
expect(vm.step).toBe('edit');
});
it('Далее с reason < 30 chars → ошибка', async () => {
const wrapper = factory();
const vm = wrapper.vm as unknown as {
newValue: string;
reason: string;
reasonError: string | null;
step: string;
};
vm.newValue = '7';
vm.reason = 'короткое';
await wrapper.vm.$nextTick();
await wrapper.find('[data-testid="next-btn"]').trigger('click');
await flushPromises();
expect(vm.reasonError).toBe('Минимум 30 символов.');
expect(vm.step).toBe('edit');
});
it('Далее с валидными данными → step confirm + diff before/after', async () => {
const wrapper = factory();
const vm = wrapper.vm as unknown as { newValue: string; reason: string; step: string };
vm.newValue = '7';
vm.reason = 'Решение CTO от 09.05.2026: ослабляем лимит для UX тестирования.';
await wrapper.vm.$nextTick();
await wrapper.find('[data-testid="next-btn"]').trigger('click');
await flushPromises();
expect(vm.step).toBe('confirm');
const text = wrapper.text();
expect(text).toContain('Было');
expect(text).toContain('Станет');
// Reason отображается на confirm-step
expect(text).toContain('CTO от 09.05');
});
it('Применить → API + emit updated + step done', async () => {
vi.mocked(adminApi.updateSystemSetting).mockResolvedValue({
key: 'login_max_attempts',
value: '7',
previous_value: '5',
updated_at: '2026-05-09T11:00:00',
message: 'OK',
});
const wrapper = factory();
const vm = wrapper.vm as unknown as { newValue: string; reason: string; step: string };
vm.newValue = '7';
vm.reason = 'Решение CTO от 09.05.2026: ослабляем лимит для UX тестирования.';
await wrapper.vm.$nextTick();
await wrapper.find('[data-testid="next-btn"]').trigger('click');
await flushPromises();
await wrapper.find('[data-testid="submit-btn"]').trigger('click');
await flushPromises();
expect(adminApi.updateSystemSetting).toHaveBeenCalledWith('login_max_attempts', {
value: '7',
reason: expect.stringContaining('CTO'),
admin_user_id: 1,
});
expect(wrapper.emitted('updated')).toBeDefined();
expect(vm.step).toBe('done');
});
it('Назад с confirm возвращает на edit с сохранёнными данными', async () => {
const wrapper = factory();
const vm = wrapper.vm as unknown as { newValue: string; reason: string; step: string };
vm.newValue = '7';
vm.reason = 'Решение CTO от 09.05.2026: ослабляем лимит для UX тестирования.';
await wrapper.vm.$nextTick();
await wrapper.find('[data-testid="next-btn"]').trigger('click');
await flushPromises();
expect(vm.step).toBe('confirm');
await wrapper.find('[data-testid="back-btn"]').trigger('click');
await flushPromises();
expect(vm.step).toBe('edit');
expect(vm.newValue).toBe('7'); // сохранилось
});
});