159 lines
4.7 KiB
TypeScript
159 lines
4.7 KiB
TypeScript
import { App } from '@inertiajs/react';
|
|
import type { Page } from '@inertiajs/core';
|
|
import { renderToString } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import Bank from '@/pages/suppliers/bank';
|
|
import Payments from '@/pages/payments/index';
|
|
|
|
const key = 'c1111111-1111-4111-8111-111111111111';
|
|
const accounts = [
|
|
{
|
|
id: 1,
|
|
key: null,
|
|
revision: 1,
|
|
label: 'Banco anterior · MZN',
|
|
state: 'approved',
|
|
},
|
|
{
|
|
id: 2,
|
|
key,
|
|
revision: 2,
|
|
label: 'Banco independente · USD',
|
|
state: 'pending',
|
|
},
|
|
];
|
|
function render(
|
|
Component: typeof Bank | typeof Payments,
|
|
props: Record<string, unknown>,
|
|
) {
|
|
const page = {
|
|
component: 'test',
|
|
url: '/teste',
|
|
version: null,
|
|
props: { errors: {}, ...props },
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
} satisfies Page;
|
|
return renderToString(
|
|
<App initialPage={page} initialComponent={Component} />,
|
|
);
|
|
}
|
|
|
|
test('supplier bank account links preserve the selected logical account and the independent creation action', () => {
|
|
const html = render(Bank, {
|
|
supplier: { id: 8, name: 'Fornecedor sintético' },
|
|
current: null,
|
|
currentId: 0,
|
|
state: 'missing',
|
|
history: [],
|
|
reviews: [],
|
|
canPropose: true,
|
|
canReview: false,
|
|
accounts,
|
|
accountKey: null,
|
|
multiAccountsAvailable: true,
|
|
actorId: 12,
|
|
});
|
|
expect(html).toContain(`/fornecedores/8/dados-bancarios?account=${key}`);
|
|
expect(html).toContain('Adicionar conta independente');
|
|
expect(html).toContain('não substitui nem reactiva versões anteriores');
|
|
});
|
|
|
|
test('legacy schema does not offer independent accounts or infer additional authority', () => {
|
|
const html = render(Bank, {
|
|
supplier: { id: 8, name: 'Fornecedor sintético' },
|
|
current: null,
|
|
currentId: 0,
|
|
state: 'missing',
|
|
history: [],
|
|
reviews: [],
|
|
canPropose: false,
|
|
canReview: false,
|
|
multiAccountsAvailable: false,
|
|
actorId: 12,
|
|
});
|
|
expect(html).not.toContain('Adicionar conta independente');
|
|
expect(html).not.toContain('Conferência independente');
|
|
});
|
|
|
|
test('payment form leaves the deliberate choice empty when two approved same-currency accounts exist', () => {
|
|
const html = render(Payments, {
|
|
canManage: true,
|
|
focusInvoiceId: 42,
|
|
payments: {
|
|
data: [],
|
|
current_page: 1,
|
|
last_page: 1,
|
|
total: 0,
|
|
per_page: 15,
|
|
links: [],
|
|
},
|
|
invoices: [
|
|
{
|
|
id: 42,
|
|
number: 'FT-42',
|
|
currency: 'MZN',
|
|
supplier_id: 8,
|
|
supplier_name: 'Fornecedor sintético',
|
|
total_minor: 100,
|
|
outstanding_minor: 100,
|
|
bank_id: 0,
|
|
bank_revision: 0,
|
|
bank_state: 'approved',
|
|
banks: [
|
|
{
|
|
id: 1,
|
|
revision: 1,
|
|
currency: 'MZN',
|
|
label: 'Conta A',
|
|
state: 'approved',
|
|
},
|
|
{
|
|
id: 2,
|
|
revision: 2,
|
|
currency: 'MZN',
|
|
label: 'Conta B',
|
|
state: 'approved',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
expect(html).toContain('Conta bancária na moeda da factura');
|
|
expect(html).toContain('Conta A');
|
|
expect(html).toContain('Conta B');
|
|
expect(html).toContain('value="" selected=""');
|
|
expect(html).toContain('Por seleccionar');
|
|
});
|
|
|
|
test('bank identities and labels remain hidden when administration has no payment-management authority', () => {
|
|
const html = render(Payments, {
|
|
canManage: false,
|
|
payments: {
|
|
data: [],
|
|
current_page: 1,
|
|
last_page: 1,
|
|
total: 0,
|
|
per_page: 15,
|
|
links: [],
|
|
},
|
|
invoices: [
|
|
{
|
|
id: 42,
|
|
number: 'FT-42',
|
|
currency: 'MZN',
|
|
supplier_id: 8,
|
|
supplier_name: 'Fornecedor sintético',
|
|
total_minor: 100,
|
|
outstanding_minor: 100,
|
|
bank_id: 0,
|
|
bank_revision: 0,
|
|
bank_state: 'approved',
|
|
banks: [],
|
|
},
|
|
],
|
|
});
|
|
expect(html).not.toContain('Conta bancária na moeda da factura');
|
|
expect(html).not.toContain('Seleccione uma conta validada');
|
|
});
|